public static void clear() { counter = 0; GENERIC_MAPPINGS.clear(); GENERIC_MAPPINGS.put(VOID_REF, new TypeParamDefBuilder().withName("V").addToAttributes(IS_GENERIC, true).build()); GENERIC_MAPPINGS.put(TRANSPARENT_REF, TRANSPARENT); }
/** * Creates a new TypeParamDef. * @param letter The letter of the type. * @return The param definition. */ public static TypeParamDef newTypeParamDef(String letter) { return new TypeParamDefBuilder().withName(letter).build(); }
public TypeParamDef apply(Type item) { if (item instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) item; String name = typeVariable.getName(); List<ClassRef> bounds = new ArrayList<ClassRef>(); for (Type b : typeVariable.getBounds()) { if (b instanceof Class) { Class c = (Class) b; bounds.add((ClassRef) TYPEREF.apply(c)); } } return new TypeParamDefBuilder().withName(name).withBounds(bounds).build(); } return null; } });
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 TypeParamDef apply(TypeRef item) { if (!GENERIC_MAPPINGS.containsKey(item)) { int iteration = counter / GENERIC_NAMES.length; String name = GENERIC_NAMES[counter % GENERIC_NAMES.length]; if (iteration > 0) { name += iteration; } counter++; GENERIC_MAPPINGS.put(item, new TypeParamDefBuilder().withName(name) .addToAttributes(IS_GENERIC, true) .addToAttributes(ORIGINAL_REF, item) .build()); } return GENERIC_MAPPINGS.get(item); } };
public TypeParamDef apply(TypeParameterElement item) { List<ClassRef> typeRefs = new ArrayList(); for (TypeMirror typeMirror : item.getBounds()) { //TODO: Fix this //typeRefs.add(toTypeRef.apply(typeMirror)); } return new TypeParamDefBuilder() .withName(item.getSimpleName().toString()) .withBounds(typeRefs) .build(); }
public TypeParamDef apply(TypeParameter typeParameter) { List<ClassRef> bounds = new ArrayList<ClassRef>(); for (ClassOrInterfaceType classOrInterfaceType : typeParameter.getTypeBound()) { bounds.add((ClassRef) CLASS_OR_TYPEPARAM_REF.apply(classOrInterfaceType)); } return new TypeParamDefBuilder() .withName(typeParameter.getName()) .withBounds(bounds) .build(); } };
.withName(typeVariable.getName()) .withBounds(bounds) .build());
private static final Set<TypeParamDef> extractParameters(TypeDef typeDef) { final Set<TypeParamDef> result = new LinkedHashSet<TypeParamDef>(); final Set<TypeParamRef> refs = new LinkedHashSet<TypeParamRef>(); TypeDef ignored = new TypeDefBuilder(typeDef).accept(new TypeParamDefColletor(result)).accept(new TypeParamRefColletor(refs)).build(); for (TypeParamRef typeParamRef : refs) { result.add(new TypeParamDefBuilder().withName(typeParamRef.getName()).withAttributes(typeParamRef.getAttributes()).build()); } return result; }
public TypeParamDefBuilder(TypeParamDef instance) { this.fluent = this; this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }
private static final Set<TypeParamDef> extractParameters(ClassRef classRef) { final Set<TypeParamDef> result = new LinkedHashSet<TypeParamDef>(); final Set<TypeParamRef> refs = new LinkedHashSet<TypeParamRef>(); ClassRef ignored = new ClassRefBuilder(classRef).accept(new TypeParamDefColletor(result)).accept(new TypeParamRefColletor(refs)).build(); for (TypeParamRef typeParamRef : refs) { result.add(new TypeParamDefBuilder().withName(typeParamRef.getName()).withAttributes(typeParamRef.getAttributes()).build()); } return result; }
TypeParamDef genericType = new TypeParamDefBuilder().withName(typeParameter.getSimpleName().toString()) .withBounds(genericBounds) .build();