public JCTree.JCMethodDecl build() { if (built) { throw new IllegalStateException(); } built = true; ListBuffer<JCVariableDecl> params = ListBuffer.lb(); for (ParameterDefinitionBuilder pdb : this.params) { if (noAnnotations || ignoreAnnotations) { pdb.noAnnotations(); } params.append(pdb.build()); } return gen.make() .MethodDef( gen.make().Modifiers(modifiers, getAnnotations().toList()), makeName(name), resultTypeExpr, typeParams.toList(), params.toList(), List.<JCExpression>nil(), makeBody(body), null); }
public static MethodDefinitionBuilder main(AbstractTransformer gen) { MethodDefinitionBuilder mdb = new MethodDefinitionBuilder(gen, false, "main").modifiers(PUBLIC | STATIC); ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.instance(mdb.gen, "args"); pdb.type( gen.make().TypeArray(gen.make().Type(gen.syms().stringType)), List.<JCAnnotation>nil()); return mdb.parameter(pdb); }
private ParameterDefinitionBuilder makeCallableCallParam(long flags, int ii) { JCExpression type = gen.makeIdent(gen.syms().objectType); if ((flags & Flags.VARARGS) != 0) { type = gen.make().TypeArray(type); } ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.instance(gen, getParamName(ii)); pdb.modifiers(Flags.FINAL | flags); pdb.type(type, null); return pdb; /* return gen.make().VarDef(gen.make().Modifiers(Flags.FINAL | Flags.PARAMETER | flags), makeParamName(gen, ii), type, null); */ }
private void generateValueConstructor(MethodDefinitionBuilder methodDefinitionBuilder) { ParameterDefinitionBuilder paramBuilder = ParameterDefinitionBuilder.instance(owner, fieldName).type(attrType, null); JCTree.JCAssign init = owner .make() .Assign( owner.makeQualIdent(owner.makeUnquotedIdent("this"), fieldName), owner.makeUnquotedIdent(fieldName)); methodDefinitionBuilder.parameter(paramBuilder).body(owner.make().Exec(init)); }
private JCTree makeCallTypedMethod( List<JCStatement> body, java.util.List<ProducedType> parameterTypes) { // make the method MethodDefinitionBuilder methodBuilder = MethodDefinitionBuilder.method(gen, false, Naming.getCallableTypedMethodName()); methodBuilder.modifiers(Flags.PRIVATE); ProducedType returnType = gen.getReturnTypeOfCallable(typeModel); methodBuilder.resultType(gen.makeJavaType(returnType, JT_NO_PRIMITIVES), null); // add all parameters int i = 0; for (Parameter param : paramLists.getParameters()) { ParameterDefinitionBuilder parameterBuilder = ParameterDefinitionBuilder.instance(gen, param.getName()); JCExpression paramType = gen.makeJavaType(parameterTypes.get(i)); parameterBuilder.type(paramType, null); methodBuilder.parameter(parameterBuilder); i++; } // Return the call result, or null if a void method methodBuilder.body(body); return methodBuilder.build(); }
private MethodDefinitionBuilder parameter( long modifiers, String name, String aliasedName, TypedDeclaration decl, TypedDeclaration nonWideningDecl, ProducedType nonWideningType, int flags) { ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.instance(gen, name); pdb.modifiers(modifiers); pdb.aliasName(aliasedName); pdb.sequenced(decl instanceof Parameter && ((Parameter) decl).isSequenced()); pdb.defaulted(decl instanceof Parameter && ((Parameter) decl).isDefaulted()); pdb.type(paramType(nonWideningDecl, nonWideningType, flags), gen.makeJavaTypeAnnotations(decl)); return parameter(pdb); }