private static TypeRef getKeyForValue(Map<TypeRef, TypeParamDef> map, TypeRef value) { for (Map.Entry<TypeRef, TypeParamDef> entry : map.entrySet()) { if (value instanceof TypeParamRef && ((TypeParamRef) value).getName().equals(entry.getValue().getName())) { return entry.getKey(); } } return null; //throw new IllegalStateException("Key not found for value:[" + value +"]."); }
private static boolean containsValue(Map<TypeRef, TypeParamDef> map, TypeRef value) { for (Map.Entry<TypeRef, TypeParamDef> entry : map.entrySet()) { if (value instanceof TypeParamRef && ((TypeParamRef) value).getName().equals(entry.getValue().getName())) { return true; } } return false; }
public static Set<String> allGenericsOf(TypeDef clazz) { Set<String> result = new HashSet<String>(); for (TypeParamDef paramDef : clazz.getParameters()) { result.add(paramDef.getName()); } for (Property property : clazz.getProperties()) { result.addAll(allGenericsOf(property)); } for (Method method : clazz.getMethods()) { result.addAll(allGenericsOf(method)); } return result; }
public static TypeParamDef getNextGeneric(TypeDef type, Collection<TypeParamDef> excluded) { Set<String> skip = new HashSet<String>(); for (String s : allGenericsOf(type)) { skip.add(s); } for (TypeParamDef e : excluded) { skip.add(e.getName()); } for (int i = 0; i < 10; i++) { for (int j = 0; j < GENERIC_NAMES.length; j++) { String name = GENERIC_NAMES[j] + ((i > 0) ? String.valueOf(i) : ""); if (!skip.contains(name)) { return new TypeParamDefBuilder().withName(name).build(); } } } throw new IllegalStateException("Could not allocate generic parameter letter for: " + type.getFullyQualifiedName()); }
public static TypeParamDef getParameterDefinition(TypeRef typeRef, Collection<TypeParamDef> parameters) { String name; if (typeRef instanceof ClassRef) { name = ((ClassRef)typeRef).getName(); } else if (typeRef instanceof TypeParamRef) { name = ((TypeParamRef)typeRef).getName(); } else if (typeRef instanceof PrimitiveRef) { name = ((PrimitiveRef)typeRef).getName(); } else { name = typeRef.toString(); } for (TypeParamDef parameter : parameters) { if (parameter.getName().equals(name)) { return parameter; } } return null; }
public TypeParamDefFluentImpl(TypeParamDef instance){ this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }
public TypeParamDefBuilder(TypeParamDefFluent<?> fluent, TypeParamDef instance) { this.fluent = fluent; fluent.withName(instance.getName()); fluent.withBounds(instance.getBounds()); fluent.withAttributes(instance.getAttributes()); }
public TypeParamDefBuilder(TypeParamDef instance) { this.fluent = this; this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }