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 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(); }
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 edit() { return new TypeParamDefBuilder(this); }
public TypeDef apply(TypeDef item) { BuilderContext ctx = BuilderContextManager.getContext(); TypeDef fluent = SHALLOW_FLUENT.apply(item); List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(item.getParameters()); List<TypeRef> superClassParameters = new ArrayList<TypeRef>(); TypeParamDef nextParameter = getNextGeneric(item, parameters); ClassRef builableSuperClassRef = findBuildableSuperClassRef(item); TypeDef buildableSuperClass = findBuildableSuperClass(item); if (builableSuperClassRef != null) { superClassParameters.addAll(builableSuperClassRef.getArguments()); } TypeParamDef parameterFluent = new TypeParamDefBuilder(nextParameter).addToBounds(fluent.toInternalReference()).build(); parameters.add(parameterFluent); superClassParameters.add(parameterFluent.toReference()); TypeDef superClass = buildableSuperClass != null ? SHALLOW_FLUENT.apply(buildableSuperClass) : ctx.getFluentInterface(); return new TypeDefBuilder(item) .withKind(Kind.INTERFACE) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(item.getName() + "Fluent") .withPackageName(item.getPackageName()) .withParameters(parameters) .withExtendsList(superClass.toReference(superClassParameters)) .withImplementsList() .withInnerTypes() .build(); } };
public TypeParamDefBuilder(TypeParamDef instance) { this.fluent = this; this.withName(instance.getName()); this.withBounds(instance.getBounds()); this.withAttributes(instance.getAttributes()); }
public TypeDef apply(ClassOrInterfaceType item) { List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(); for (Type type : item.getTypeArgs()) { new TypeParamDefBuilder() .build(); } return new TypeDefBuilder() .withName(item.getName()) .withParameters(parameters) .build(); } }
public TypeParamDef buildParameter(int index){ return this.parameters.get(index).build(); }
public EditableTypeParamDef build() { EditableTypeParamDef buildable = new EditableTypeParamDef(fluent.getName(), fluent.getBounds(), fluent.getAttributes()); validate(buildable); return buildable; }
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; }
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 A addToParameters(int index,TypeParamDef item){ TypeParamDefBuilder builder = new TypeParamDefBuilder(item);_visitables.add(builder);this.parameters.add(builder); return (A)this; }
public TypeDef apply(TypeDef item) { BuilderContext ctx = BuilderContextManager.getContext(); TypeDef fluent = SHALLOW_FLUENT.apply(item); List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(item.getParameters()); List<TypeRef> superClassParameters = new ArrayList<TypeRef>(); TypeParamDef nextParameter = getNextGeneric(item, parameters); ClassRef builableSuperClassRef = findBuildableSuperClassRef(item); if (builableSuperClassRef != null) { superClassParameters.addAll(builableSuperClassRef.getArguments()); } TypeParamDef parameterFluent = new TypeParamDefBuilder(nextParameter).addToBounds(fluent.toInternalReference()).build(); parameters.add(parameterFluent); superClassParameters.add(parameterFluent.toReference()); TypeDef buildableSuperClass = findBuildableSuperClass(item); TypeDef superClass = buildableSuperClass != null ? FLUENT_IMPL.apply(buildableSuperClass) : ctx.getBaseFluentClass(); return new TypeDefBuilder(item) .withKind(Kind.CLASS) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(item.getName() + "FluentImpl") .withPackageName(item.getPackageName()) .withParameters(parameters) .withExtendsList(superClass.toReference(superClassParameters)) .withImplementsList(SHALLOW_FLUENT.apply(item).toInternalReference()) .withInnerTypes() .build(); }
public TypeParamDef buildFirstParameter(){ return this.parameters.get(0).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 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 A addToParameters(TypeParamDef... items){ for (TypeParamDef item : items) {TypeParamDefBuilder builder = new TypeParamDefBuilder(item);_visitables.add(builder);this.parameters.add(builder);} return (A)this; }
public TypeParamDef buildLastParameter(){ return this.parameters.get(parameters.size() - 1).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(); } };