コード例 #1
0
  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);
  }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
           */
 }
コード例 #4
0
 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));
 }
コード例 #5
0
 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();
 }
コード例 #6
0
 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);
 }