public TypeRef apply(TypeRef type) { if (type instanceof ClassRef) { ClassRef classRef = (ClassRef) type; if (Collections.IS_COLLECTION.apply(classRef)) { return classRef.getArguments().get(0); } } return type; } };
public static Set<String> allGenericsOf(TypeRef type) { Set<String> result = new HashSet<String>(); if (type instanceof ClassRef) { for (TypeRef ref : ((ClassRef)type).getArguments()) { if (ref instanceof TypeParamRef) { result.add(((TypeParamRef)ref).getName()); } } } return result; }
private static Set<TypeRef> findTypeArguments(Set<ClassRef> interfaces) { if (interfaces.size() < 2) { return Collections.<TypeRef>emptySet(); } //1st pass find all generics Set<TypeRef> allGenerics = new LinkedHashSet<TypeRef>(); for (ClassRef clazz : interfaces) { allGenerics.addAll(clazz.getArguments()); } //2nd pass collect common generics Set<TypeRef> common = new LinkedHashSet<TypeRef>(allGenerics); for (ClassRef clazz : interfaces) { Set<TypeRef> ownGenerics = new LinkedHashSet<TypeRef>(); ownGenerics.addAll(clazz.getArguments()); common.remove(clazz); common.retainAll(ownGenerics); } Set<TypeRef> result = new LinkedHashSet<TypeRef>(); for (TypeRef type : common) { Boolean isGeneric = type.getAttributes().containsKey(IS_GENERIC) ? (Boolean) type.getAttributes().get(IS_GENERIC) : false; if (!isGeneric) { result.add(type); } } return result; }
public ClassRefBuilder(ClassRef instance, Boolean validationEnabled) { this.fluent = this; this.withDefinition(instance.getDefinition()); this.withFullyQualifiedName(instance.getFullyQualifiedName()); this.withDimensions(instance.getDimensions()); this.withArguments(instance.getArguments()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
@Override public Method apply(Property property) { Method method = WITH_NEW_LIKE_NESTED.apply(property); if (!(property.getTypeRef() instanceof ClassRef)) { throw new IllegalStateException("Expected Nestable / Buildable type and found:" + property.getTypeRef()); } ClassRef baseType = (ClassRef) TypeAs.UNWRAP_COLLECTION_OF.apply(property.getTypeRef()); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef ignore : baseType.getArguments()) { typeArguments.add(Q); } typeArguments.add(returnType); ClassRef rewrapedImpl = nestedTypeImpl.toReference(typeArguments); return new MethodBuilder(method) .addToArguments(0, INDEX) .withName(method.getName().replaceFirst("add", "set")) .editBlock() .withStatements(new StringStatement("return new " + rewrapedImpl.getName() + "(index, item);")) .endBlock() .build(); } };
public ClassRefBuilder(ClassRefFluent<?> fluent, ClassRef instance, Boolean validationEnabled) { this.fluent = fluent; fluent.withDefinition(instance.getDefinition()); fluent.withFullyQualifiedName(instance.getFullyQualifiedName()); fluent.withDimensions(instance.getDimensions()); fluent.withArguments(instance.getArguments()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public ClassRefFluentImpl(ClassRef instance){ this.withDefinition(instance.getDefinition()); this.withFullyQualifiedName(instance.getFullyQualifiedName()); this.withDimensions(instance.getDimensions()); this.withArguments(instance.getArguments()); this.withAttributes(instance.getAttributes()); }
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; if (!(property.getTypeRef() instanceof ClassRef)) { throw new IllegalStateException("Expected Map type and found:" + property.getTypeRef()); } ClassRef mapType = (ClassRef) property.getTypeRef(); TypeRef keyType = mapType.getArguments().get(0); TypeRef valueType = mapType.getArguments().get(1); Property keyProperty = new PropertyBuilder().withName("key").withTypeRef(keyType).build(); Property valueProperty = new PropertyBuilder().withName("value").withTypeRef(valueType).build(); String methodName = "addTo" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(new Property[]{keyProperty, valueProperty}) .withNewBlock() .addNewStringStatementStatement("if(this."+property.getName()+" == null && key != null && value != null) { this." + property.getName() + " = " + property.getAttribute(INIT_FUNCTION).apply(Collections.emptyList()) + "; }") .addNewStringStatementStatement("if(key != null && value != null) {this." + property.getName() + ".put(key, value);} return (" + returnType + ")this;") .endBlock() .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); 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) { 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(); }
List<TypeRef> arguments = ((ClassRef) typeRef).getArguments();
public TypeRef apply(TypeRef type) { if (type instanceof ClassRef) { ClassRef classRef = (ClassRef) type; if (TypeUtils.isOptional(classRef)) { return classRef.getArguments().get(0); } if (TypeUtils.isOptionalInt(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Integer").build().toReference(); } if (TypeUtils.isOptionalLong(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Long").build().toReference(); } if (TypeUtils.isOptionalDouble(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Double").build().toReference(); } } return type; } };
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; ClassRef mapType = (ClassRef) property.getTypeRef(); TypeRef keyType = mapType.getArguments().get(0); Property keyProperty = new PropertyBuilder().withName("key").withTypeRef(keyType).build(); String methodName = "removeFrom" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(keyProperty) .withNewBlock() .addNewStringStatementStatement("if(this." + property.getName() + " == null) { return (" + returnType + ") this; }") .addNewStringStatementStatement("if(key != null && this."+property.getName()+" != null) {this." + property.getName() + ".remove(key);} return (" + returnType + ")this;") .endBlock() .build(); } });
for (TypeRef ignore : baseType.getArguments()) { typeArguments.add(Q);
for (TypeRef ignore : baseType.getArguments()) { typeArguments.add(Q);
for (TypeRef ignore : baseType.getArguments()) { typeArguments.add(Q);
for (TypeRef arg : baseType.getArguments()) { typeArguments.add(arg);
for (TypeRef ignore : unwrapped.getArguments()) { typeArguments.add(Q);