Ejemplo n.º 1
0
  @Override
  public void visitTypeIdent(JCPrimitiveTypeTree tree) {
    TypeTag typeTag = typeTag(tree);

    if (CTC_BYTE.equals(typeTag)) print("byte");
    else if (CTC_CHAR.equals(typeTag)) print("char");
    else if (CTC_SHORT.equals(typeTag)) print("short");
    else if (CTC_INT.equals(typeTag)) print("int");
    else if (CTC_LONG.equals(typeTag)) print("long");
    else if (CTC_FLOAT.equals(typeTag)) print("float");
    else if (CTC_DOUBLE.equals(typeTag)) print("double");
    else if (CTC_BOOLEAN.equals(typeTag)) print("boolean");
    else if (CTC_VOID.equals(typeTag)) print("void");
    else print("error");
  }
Ejemplo n.º 2
0
  public JCMethodDecl generateBuildMethod(
      String name,
      Name staticName,
      JCExpression returnType,
      java.util.List<Name> fieldNames,
      JavacNode type,
      List<JCExpression> thrownExceptions) {
    JavacTreeMaker maker = type.getTreeMaker();

    JCExpression call;
    JCStatement statement;

    ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
    for (Name n : fieldNames) {
      args.append(maker.Ident(n));
    }

    if (staticName == null) {
      call = maker.NewClass(null, List.<JCExpression>nil(), returnType, args.toList(), null);
      statement = maker.Return(call);
    } else {
      ListBuffer<JCExpression> typeParams = new ListBuffer<JCExpression>();
      for (JCTypeParameter tp : ((JCClassDecl) type.get()).typarams) {
        typeParams.append(maker.Ident(tp.name));
      }

      JCExpression fn = maker.Select(maker.Ident(((JCClassDecl) type.up().get()).name), staticName);
      call = maker.Apply(typeParams.toList(), fn, args.toList());
      if (returnType instanceof JCPrimitiveTypeTree && CTC_VOID.equals(typeTag(returnType))) {
        statement = maker.Exec(call);
      } else {
        statement = maker.Return(call);
      }
    }

    JCBlock body = maker.Block(0, List.<JCStatement>of(statement));

    return maker.MethodDef(
        maker.Modifiers(Flags.PUBLIC),
        type.toName(name),
        returnType,
        List.<JCTypeParameter>nil(),
        List.<JCVariableDecl>nil(),
        thrownExceptions,
        body,
        null);
  }