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(Class item) { if (Object.class.equals(item)) { return TypeDef.OBJECT; } Kind kind = KIND.apply(item); return new TypeDefBuilder() .withKind(kind) .withName(item.getSimpleName()) .withPackageName(item.getPackage() != null ? item.getPackage().getName() : null) .withModifiers(item.getModifiers()) .withParameters() .build(); } };
public TypeDef register(TypeDef definition, AttributeKey<Boolean>... flags) { TypeDefBuilder builder = new TypeDefBuilder(definition); for (AttributeKey<Boolean> flag : flags) { builder.addToAttributes(flag, true); } return register(builder.build()); }
/** * Removes parameters from a TypeDef. * @param base The base type. * @return The unwraped TypeDef. */ public static TypeDef unwrapGeneric(TypeDef base) { return new TypeDefBuilder(base).withParameters().build(); }
/** * Sets one {@link io.sundr.codegen.model.TypeDef} as a super class of an other. * * @param base The base type. * @param superClass The super type. * @return The updated type definition. */ public static TypeDef typeExtends(TypeDef base, ClassRef superClass) { return new TypeDefBuilder(base) .withExtendsList(superClass) .build(); }
public TypeDef apply(Model model) { return new TypeDefBuilder() .withKind(Kind.CLASS) .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(); } };
String packageName = CLASSREFS_TO_PACKAGE.apply(interfaces); TypeDef combination = new TypeDefBuilder() .withKind(Kind.INTERFACE) .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(className) .withPackageName(packageName) .withExtendsList(interfaces) .withParameters(parameters.toArray(new TypeParamDef[parameters.size()])) .addToAttributes(ORIGINAL_RETURN_TYPE, TRANSPARENT_REF) .addToAttributes(TERMINATING_TYPES, terminatingTypes) .addToAttributes(IS_TERMINAL, false) .addToAttributes(IS_COMPOSITE, false) .build();
TypeDef baseType = new TypeDefBuilder() .withKind(kind) .withModifiers(TypeUtils.modifiersToInt(classElement.getModifiers())) .withPackageName(getPackageName(classElement)) .withName(getClassName(classElement)) .withParameters(genericTypes) .withExtendsList(superClassType instanceof ClassRef ? (ClassRef) superClassType : null) .withImplementsList(interfaces) .withOuterType(classElement.getEnclosingElement() instanceof TypeElement ? TYPEDEF.apply((TypeElement) classElement.getEnclosingElement()) : null) .build(); innerType = new TypeDefBuilder(innerType).withOuterType(baseType).build(); DefinitionRepository.getRepository().register(innerType); innerTypes.add(innerType); TypeDefBuilder builder = new TypeDefBuilder(baseType) .withInnerTypes(innerTypes); builder.addToConstructors(METHOD.apply(constructor)); builder.addToProperties(PROPERTY.apply(variableElement)); builder.addToMethods(METHOD.apply(method)); builder.addToAnnotations(ANNOTATION_REF.apply(annotationMirror)); return DefinitionRepository.getRepository().register(builder.build());
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; }
superClass = new TypeDefBuilder(ElementTo.TYPEDEF.apply(BuilderContextManager.getContext().getElements().getTypeElement(superClassName))) .build(); : POJO.apply(new TypeDefBuilder(ref.getDefinition()) .withAnnotations(annotationRefs) .addToAnnotations(inheritedPojoRef) .withAttributes(item.getAttributes()) .build()); TypeDef generatedPojo = new TypeDefBuilder() .withPackageName(relativePackage(item.getPackageName(), relativePath)) .withModifiers(modifiersToInt(Modifier.PUBLIC)) .withName(pojoName) .withAnnotations(annotationRefs) .withProperties(fields) .withConstructors(constructors) .withMethods(getters) .withImplementsList(implementsList) .withExtendsList(extendsList) .addToAttributes(item.getAttributes()) .build(); TypeDef mapper = new TypeDefBuilder() .withModifiers(modifiersToInt(Modifier.PUBLIC)) .withPackageName(adapterPackage) .withName(!StringUtils.isNullOrEmpty(name) ? name : StringUtils.toPojoName(generatedPojo.getName(), prefix, suffix)) .withMethods(adapterMethods) .addToAttributes(ALSO_IMPORT, adapterImports) .build();
public TypeDef apply(Property item) { TypeDef nested = new TypeDefBuilder(SHALLOW_NESTED_TYPE.apply(item)).withOuterType(item.getAttribute(OUTER_INTERFACE)).build(); TypeDef outerInterface = item.getAttribute(OUTER_INTERFACE); .build(); return new TypeDefBuilder(nested) .withKind(Kind.INTERFACE) .withPackageName(outerInterface.getPackageName()) .withParameters(parameters) .withOuterType(outerInterface) .withImplementsList() .withExtendsList(BuilderContextManager.getContext().getNestedInterface().toReference(N.toReference()), superClassFluent) .build();
.build()); return new TypeDefBuilder(nestedType) .withAnnotations() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withProperties(properties) .withMethods(nestedMethods) .withConstructors(constructors) .build();
return new TypeDefBuilder() .withKind(Kind.CLASS) .withPackageName(packageName) .withName(className) .withImplementsList(interfaces) .withExtendsList(superClass) .withProperties(fields) .withMethods(methods) .build();
final TypeDef shallowInlineType = new TypeDefBuilder(builderType) .withName(inlineableName) .withImplementsList(inlineTypeRef) .withProperties() .withMethods() .withConstructors().build(); return new TypeDefBuilder(shallowInlineType) .withAnnotations() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withConstructors(constructors) .addToProperties(builderProperty, functionProperty) .addToMethods(inlineMethod) .accept(new TypedVisitor<ClassRefBuilder>() { public void visit(ClassRefBuilder builder) { List<TypeRef> updatedArguments = new ArrayList<TypeRef>(); }).build();
current = new TypeDefBuilder(clazz) .addToAttributes(CARDINALITY_MULTIPLE, false) .build(); result.add(new TypeDefBuilder(clazz) .withKind(Kind.INTERFACE) .withPackageName(scopeInterface.getDefinition().getPackageName()) .withName(scopeInterface.getDefinition().getName() + SCOPE_SUFFIX) .withExtendsList(scopeInterface) .withMethods() .addToAttributes(CARDINALITY_MULTIPLE, multiple) .addToAttributes(KEYWORDS, scopeKeywords(scopeClasses)) .accept(new TypedVisitor<TypeDefBuilder>() { public void visit(TypeDefBuilder builder) { builder.getAttributes().remove(BEGIN_SCOPE); .build());
public TypeDef apply(TypeElement classElement) { List<ClassRef> extendsList = new ArrayList<ClassRef>(); //Check SuperClass Kind kind = Kind.CLASS; if (classElement.getKind() == ElementKind.INTERFACE) { kind = Kind.INTERFACE; } else if (classElement.getKind() == ElementKind.CLASS) { kind = Kind.CLASS; extendsList.add(TypeDef.OBJECT_REF); } else if (classElement.getKind() == ElementKind.ANNOTATION_TYPE) { kind = Kind.ANNOTATION; } Set<Method> allMethods = new LinkedHashSet<Method>(); for (ExecutableElement method : ElementFilter.methodsIn(classElement.getEnclosedElements())) { } return new TypeDefBuilder() .withKind(kind) .withModifiers(TypeUtils.modifiersToInt(classElement.getModifiers())) .withPackageName(getPackageName(classElement)) .withName(getClassName(classElement)) .withExtendsList(extendsList) .addAllToMethods(allMethods) .withOuterType(classElement.getEnclosingElement() instanceof TypeElement ? SHALLOW_TYPEDEF.apply((TypeElement) classElement.getEnclosingElement()) : null) .build(); } };
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 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 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(); }