예제 #1
0
 public void visitVarDef(JCVariableDecl tree) {
   try {
     if (docComments != null && docComments.hasComment(tree)) {
       println();
       align();
     }
     printDocComment(tree);
     if ((tree.mods.flags & ENUM) != 0) {
       print("/*public static final*/ ");
       print(tree.name);
       if (tree.init != null) {
         if (sourceOutput && tree.init.hasTag(NEWCLASS)) {
           print(" /*enum*/ ");
           JCNewClass init = (JCNewClass) tree.init;
           if (init.args != null && init.args.nonEmpty()) {
             print("(");
             print(init.args);
             print(")");
           }
           if (init.def != null && init.def.defs != null) {
             print(" ");
             printBlock(init.def.defs);
           }
           return;
         }
         print(" /* = ");
         printExpr(tree.init);
         print(" */");
       }
     } else {
       printExpr(tree.mods);
       if ((tree.mods.flags & VARARGS) != 0) {
         JCTree vartype = tree.vartype;
         List<JCAnnotation> tas = null;
         if (vartype instanceof JCAnnotatedType) {
           tas = ((JCAnnotatedType) vartype).annotations;
           vartype = ((JCAnnotatedType) vartype).underlyingType;
         }
         printExpr(((JCArrayTypeTree) vartype).elemtype);
         if (tas != null) {
           print(' ');
           printTypeAnnotations(tas);
         }
         print("... " + tree.name);
       } else {
         printExpr(tree.vartype);
         print(" " + tree.name);
       }
       if (tree.init != null) {
         print(" = ");
         printExpr(tree.init);
       }
       if (prec == TreeInfo.notExpression) print(";");
     }
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
예제 #2
0
 /**
  * Print documentation comment, if it exists
  *
  * @param tree The tree for which a documentation comment should be printed.
  */
 public void printDocComment(JCTree tree) throws IOException {
   if (docComments != null) {
     String dc = docComments.getCommentText(tree);
     if (dc != null) {
       print("/**");
       println();
       int pos = 0;
       int endpos = lineEndPos(dc, pos);
       while (pos < dc.length()) {
         align();
         print(" *");
         if (pos < dc.length() && dc.charAt(pos) > ' ') print(" ");
         print(dc.substring(pos, endpos));
         println();
         pos = endpos + 1;
         endpos = lineEndPos(dc, pos);
       }
       align();
       print(" */");
       println();
       align();
     }
   }
 }