public TypeParamDefFluentImpl(TypeParamDef instance){ this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }
private TypeRef checkAgainstTypeParamRef(TypeRef typeRef, Collection<TypeParamDef> parameters) { TypeParamDef parameterDef = TypeUtils.getParameterDefinition(typeRef, parameters); if (parameterDef != null) { return parameterDef.toReference(); } return typeRef; } };
public void visit(TypeDefBuilder builder) { List<TypeParamDef> updated = new ArrayList<TypeParamDef>(); for (TypeParamDef parameter : builder.getParameters()) { if (parameter.equals(target)) { updated.add(replacement); } else { updated.add(parameter); } } } }
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 Set<TypeParamDef> findParameters(Set<TypeDef> interfaces) { if (interfaces.size() < 2) { return Collections.<TypeParamDef>emptySet(); } //1st pass find all generics Set<TypeParamDef> allGenerics = new LinkedHashSet<TypeParamDef>(); for (TypeDef clazz : interfaces) { allGenerics.addAll(clazz.getParameters()); } //2nd pass collect common generics Set<TypeParamDef> common = new LinkedHashSet<TypeParamDef>(allGenerics); for (TypeDef clazz : interfaces) { Set<TypeParamDef> ownGenerics = new LinkedHashSet<TypeParamDef>(); ownGenerics.addAll(clazz.getParameters()); common.remove(clazz); common.retainAll(ownGenerics); } Set<TypeParamDef> result = new LinkedHashSet<TypeParamDef>(); for (TypeParamDef type : common) { Boolean isGeneric = type.getAttributes().containsKey(IS_GENERIC) ? (Boolean) type.getAttributes().get(IS_GENERIC) : false; if (!isGeneric) { result.add(type); } } return result; } }
for (ClassRef bound : typeParamDef.getBounds()) { refs.addAll(bound.getReferences());
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 TypeParamRef toReference() { return new TypeParamRefBuilder() .withName(name) .withAttributes(getAttributes()) .build(); }
for (ClassRef bound : typeParamDef.getBounds()) { refs.addAll(bound.getReferences());
public ClassRef apply(TypeDef item) { List<TypeRef> parameters = new ArrayList<TypeRef>(); for (TypeParamDef param : item.getParameters()) { parameters.add(param.toReference()); } parameters.add(Q); return SHALLOW_FLUENT.apply(item).toReference(parameters); } };
public TypeParamDefBuilder(TypeParamDefFluent<?> fluent, TypeParamDef instance) { this.fluent = fluent; fluent.withName(instance.getName()); fluent.withBounds(instance.getBounds()); fluent.withAttributes(instance.getAttributes()); }
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 Set<ClassRef> apply(Set<ClassRef> source) { Set<ClassRef> result = new LinkedHashSet<ClassRef>(source); Set<TypeRef> typeArguments = findTypeArguments(source); for (TypeRef type : typeArguments) { Set<ClassRef> intermediate = new LinkedHashSet<ClassRef>(); for (ClassRef clazz : result) { intermediate.add(new ClassRefBuilder(clazz).accept(new TypeArgumentReplace(type, Generics.MAP.apply(type).toReference())).build()); } result = new LinkedHashSet<ClassRef>(intermediate); } return result; } };
public TypeParamDefBuilder(TypeParamDef instance) { this.fluent = this; this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }
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 Set<TypeDef> apply(Set<TypeDef> source) { Set<TypeDef> result = new LinkedHashSet<TypeDef>(source); Set<TypeParamDef> typeParameters = findParameters(source); for (TypeParamDef type : typeParameters) { Set<TypeDef> intermediate = new LinkedHashSet<TypeDef>(); for (TypeDef clazz : result) { intermediate.add(new TypeDefBuilder(clazz).accept(new TypeParamDefReplace(type, Generics.MAP.apply(type.toReference()))).build()); } result = new LinkedHashSet<TypeDef>(intermediate); } return result; } };
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; }
/** * Creates a {@link ClassRef} for internal use inside the scope of the type (methods, properties * etc). It uses as arguments the same 'letters' as the parameters definition. */ public ClassRef toInternalReference() { List<TypeRef> arguments = new ArrayList<TypeRef>(); for (TypeParamDef parameter : parameters) { arguments.add(parameter.toReference()); } return new ClassRefBuilder() .withDefinition(this) .withArguments(arguments) .withAttributes(getAttributes()) .build(); }