public MethodBuilder edit(){ return new MethodBuilder(this); }
public A removeAllFromMethods(Collection<Method> items){ for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.remove(builder);if (this.methods != null) {this.methods.remove(builder);}} return (A)this; }
public A removeFromConstructors(Method... items){ for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.remove(builder);if (this.constructors != null) {this.constructors.remove(builder);}} return (A)this; }
public A removeFromMethods(Method... items){ for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.remove(builder);if (this.methods != null) {this.methods.remove(builder);}} return (A)this; }
public A addToConstructors(Method... items){ if (this.constructors == null) {this.constructors = new ArrayList<MethodBuilder>();} for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.add(builder);this.constructors.add(builder);} return (A)this; }
public A addToMethods(Method... items){ if (this.methods == null) {this.methods = new ArrayList<MethodBuilder>();} for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.add(builder);this.methods.add(builder);} return (A)this; }
public A removeAllFromConstructors(Collection<Method> items){ for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.remove(builder);if (this.constructors != null) {this.constructors.remove(builder);}} return (A)this; }
public A addAllToMethods(Collection<Method> items){ if (this.methods == null) {this.methods = new ArrayList<MethodBuilder>();} for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.add(builder);this.methods.add(builder);} return (A)this; }
public A addAllToConstructors(Collection<Method> items){ if (this.constructors == null) {this.constructors = new ArrayList<MethodBuilder>();} for (Method item : items) {MethodBuilder builder = new MethodBuilder(item);_visitables.add(builder);this.constructors.add(builder);} return (A)this; }
public A addToConstructors(int index,Method item){ if (this.constructors == null) {this.constructors = new ArrayList<MethodBuilder>();} MethodBuilder builder = new MethodBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.constructors.add(index >= 0 ? index : constructors.size(), builder); return (A)this; }
public A setToMethods(int index,Method item){ if (this.methods == null) {this.methods = new ArrayList<MethodBuilder>();} MethodBuilder builder = new MethodBuilder(item); if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);} if (index < 0 || index >= methods.size()) { methods.add(builder); } else { methods.set(index, builder);} return (A)this; }
public A setToConstructors(int index,Method item){ if (this.constructors == null) {this.constructors = new ArrayList<MethodBuilder>();} MethodBuilder builder = new MethodBuilder(item); if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);} if (index < 0 || index >= constructors.size()) { constructors.add(builder); } else { constructors.set(index, builder);} return (A)this; }
public A addToMethods(int index,Method item){ if (this.methods == null) {this.methods = new ArrayList<MethodBuilder>();} MethodBuilder builder = new MethodBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.methods.add(index >= 0 ? index : methods.size(), builder); return (A)this; }
/** * The method adapts constructor method to the current class. It unsets any name that may be * presetn in the method. It also sets as a return type a reference to the current type. */ private static List<Method> adaptConstructors(List<Method> methods, TypeDef target) { List<Method> adapted = new ArrayList<Method>(); for (Method m : methods) { adapted.add(new MethodBuilder(m) .withName(null) .withReturnType(target.toUnboundedReference()) .build()); } return adapted; }
public static final Method forProperty(Property property) { return new MethodBuilder() .withName(name(property)) .withReturnType(property.getTypeRef()) .withNewBlock() .addNewStringStatementStatement("return this." + property + ";") .endBlock() .build(); }
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; String methodName = "with" + property.getNameCapitalized(); List<ClassRef> alsoImport = new ArrayList<ClassRef>(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(property) .withVarArgPreferred(true) .withNewBlock() .withStatements(getStatements(property, alsoImport)) .endBlock() .addToAttributes(Attributeable.ALSO_IMPORT, alsoImport) .build(); }
public Method apply(Property property) { String methodName = "set" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(VOID) .withArguments() .withNewBlock() .addNewStringStatementStatement("this." + property.getName() + "=" + property.getName() + ";") .endBlock() .build(); } });
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeRef mapType = property.getTypeRef(); Property mapProperty = new PropertyBuilder().withName("map").withTypeRef(mapType).build(); String methodName = "addTo" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(mapProperty) .withNewBlock() .addNewStringStatementStatement("if(this."+property.getName()+" == null && map != null) { this." + property.getName() + " = " + property.getAttribute(INIT_FUNCTION).apply(Collections.emptyList()) + "; }") .addNewStringStatementStatement("if(map != null) { this." + property.getName() + ".putAll(map);} return (" + returnType + ")this;") .endBlock() .build(); } });
public Method apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); String methodName = "end" + BuilderUtils.fullyQualifiedNameDiff(property.getTypeRef(), originTypeDef) + capitalizeFirst(IS_COLLECTION.apply(property.getTypeRef()) ? Singularize.FUNCTION.apply(property.getNameCapitalized()) : property.getNameCapitalized()); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withReturnType(N_REF) .withName(methodName) .withNewBlock() .addNewStringStatementStatement("return and();") .endBlock() .build(); } });
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeRef mapType = property.getTypeRef(); Property mapProperty = new PropertyBuilder().withName("map").withTypeRef(mapType).build(); String methodName = "removeFrom" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(mapProperty) .withNewBlock() .addNewStringStatementStatement("if(this." + property.getName() + " == null) { return (" + returnType + ") this; }") .addNewStringStatementStatement("if(map != null) { for(Object key : map.keySet()) {if (this."+property.getName()+" != null){this." + property.getName() + ".remove(key);}}} return (" + returnType + ")this;") .endBlock() .build(); } });