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); } };
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; } }
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 TypeDef apply(TypeDef... items) { if (items == null || items.length == 0) { throw new IllegalArgumentException("Items cannot be empty."); } else if (items.length == 1) { return items[0]; } else if (items.length == 2) { TypeDefBuilder builder = new TypeDefBuilder(items[0]); for (ClassRef classRef : items[1].getExtendsList()) { builder = builder.addToExtendsList(classRef); } for (TypeParamDef type : items[1].getParameters()) { if (!items[0].getParameters().contains(type)) { builder = builder.addToParameters(type); } } return builder.build(); } else { TypeDef[] rest = new TypeDef[items.length - 1]; System.arraycopy(items, 1, rest, 0, rest.length); return TYPES.apply(new TypeDef[]{items[0], TYPES.apply(rest)}); } } };
public TypeDef apply(TypeDef item) { List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(item.getParameters()); parameters.add(getNextGeneric(item)); return new TypeDefBuilder(item) .withKind(Kind.INTERFACE) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(item.getName() + "Fluent") .withParameters(parameters) .withInnerTypes() .build(); } };
public TypeDef apply(TypeDef item) { TypeDef builder = SHALLOW_BUILDER.apply(item); TypeDef fluent = FLUENT_IMPL.apply(item); List<TypeRef> parameters = new ArrayList<TypeRef>(); for (TypeParamDef param : item.getParameters()) { parameters.add(param.toReference()); } parameters.add(builder.toInternalReference()); return new TypeDefBuilder(item) .withKind(Kind.CLASS) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(item.getName() + "Builder") .withParameters(item.getParameters()) .withInnerTypes() .withExtendsList(fluent.toReference(parameters)) .withImplementsList(BuilderContextManager.getContext().getVisitableBuilderInterface().toReference(item.toInternalReference(), builder.toInternalReference())) .build(); } };
public TypeDef apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); TypeRef typeRef = TypeAs.combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF, UNWRAP_OPTIONAL_OF).apply(property.getTypeRef()); TypeDef typeDef = BuilderContextManager.getContext().getDefinitionRepository().getDefinition(typeRef); if (typeDef == null) { if (typeRef instanceof ClassRef) { typeDef = ((ClassRef)typeRef).getDefinition(); } else { throw new IllegalStateException("Could not find definition from property: ["+property+"] neither in the repo nor via the object tree."); } } TypeDef outerInterface = property.getAttribute(OUTER_INTERFACE); List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(); for (TypeParamDef generic : typeDef.getParameters()) { parameters.add(generic); } parameters.add(N); return new TypeDefBuilder(typeDef) .withPackageName(outerInterface.getPackageName()) .withName(BuilderUtils.fullyQualifiedNameDiff(property.getTypeRef(), originTypeDef) + property.getNameCapitalized() + "Nested") .withParameters(parameters) .build(); } };
public TypeDef getInlineableInterface(Inline inline) { return new TypeDefBuilder(inlineableBase) .withKind(Kind.INTERFACE) .withPackageName(builderPackage) .withName(inline.prefix() + (!inline.name().isEmpty() ? inline.name() : INLINEABLE.getName()) + inline.suffix()) .withParameters(INLINEABLE.getParameters()) .addNewMethod() .withReturnType(TypeUtils.newTypeParamRef("T")) .withName(inline.value()) .and() .build(); }
List<TypeRef> superClassParameters = new ArrayList<TypeRef>(); for (TypeParamDef parameter : typeDef.getParameters()) { parameters.add(parameter); superClassParameters.add(parameter.toReference());
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 TypeDef apply(TypeDef item) { List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(); for (TypeParamDef generic : item.getParameters()) { parameters.add(generic); } return new TypeDefBuilder(item) .withKind(Kind.CLASS) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName("Editable" + item.getName()) .withParameters(parameters) .withExtendsList(item.toInternalReference()) .withImplementsList(BuilderContextManager.getContext().getEditableInterface().toReference(SHALLOW_BUILDER.apply(item).toInternalReference())) .withInnerTypes() .withProperties() .withMethods() .withConstructors() .build(); } };
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(); }
TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property); List<TypeParamDef> parameters = baseType.getDefinition().getParameters(); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef ignore : baseType.getArguments()) {
TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property); List<TypeParamDef> parameters = baseType.getDefinition().getParameters(); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef ignore : baseType.getArguments()) {
TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property); List<TypeParamDef> parameters = baseType.getDefinition().getParameters(); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef ignore : baseType.getArguments()) {
TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property); List<TypeParamDef> parameters = baseType.getDefinition().getParameters(); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef arg : baseType.getArguments()) {
.withArguments(constructor.getArguments()) .withName(ownName) .withParameters(baseType.getParameters()) .withNewBlock() .addNewStringStatementStatement("return (" + returnType + ")" + delegateName + "(new " + baseType.getName() + "(" + args + "));")
public TypeDefFluentImpl(TypeDef instance){ this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); }
public TypeDefBuilder(TypeDef instance,Boolean validationEnabled){ this.fluent = this; this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public TypeDefBuilder(TypeDefFluent<?> fluent,TypeDef instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withKind(instance.getKind()); fluent.withPackageName(instance.getPackageName()); fluent.withName(instance.getName()); fluent.withComments(instance.getComments()); fluent.withAnnotations(instance.getAnnotations()); fluent.withExtendsList(instance.getExtendsList()); fluent.withImplementsList(instance.getImplementsList()); fluent.withParameters(instance.getParameters()); fluent.withProperties(instance.getProperties()); fluent.withConstructors(instance.getConstructors()); fluent.withMethods(instance.getMethods()); fluent.withOuterType(instance.getOuterType()); fluent.withInnerTypes(instance.getInnerTypes()); fluent.withModifiers(instance.getModifiers()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; } public TypeDefBuilder(TypeDef instance){