예제 #1
0
 /**
  * Print unit consisting of package clause and import statements in toplevel, followed by class
  * definition. if class definition == null, print all definitions in toplevel.
  *
  * @param tree The toplevel tree
  * @param cdef The class definition, which is assumed to be part of the toplevel tree.
  */
 public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException {
   docComments = tree.docComments;
   printDocComment(tree);
   if (tree.pid != null) {
     print("package ");
     printExpr(tree.pid);
     print(";");
     println();
   }
   boolean firstImport = true;
   for (List<JCTree> l = tree.defs;
       l.nonEmpty() && (cdef == null || l.head.getTag() == JCTree.IMPORT);
       l = l.tail) {
     if (l.head.getTag() == JCTree.IMPORT) {
       JCImport imp = (JCImport) l.head;
       Name name = TreeInfo.name(imp.qualid);
       if (name == name.table.asterisk
           || cdef == null
           || isUsed(TreeInfo.symbol(imp.qualid), cdef)) {
         if (firstImport) {
           firstImport = false;
           println();
         }
         printStat(imp);
       }
     } else {
       printStat(l.head);
     }
   }
   if (cdef != null) {
     printStat(cdef);
     println();
   }
 }
예제 #2
0
 public void visitBinary(JCBinary tree) {
   try {
     int ownprec = TreeInfo.opPrec(tree.getTag());
     String opname = operatorName(tree.getTag());
     open(prec, ownprec);
     printExpr(tree.lhs, ownprec);
     print(" " + opname + " ");
     printExpr(tree.rhs, ownprec + 1);
     close(prec, ownprec);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
예제 #3
0
 public void visitUnary(JCUnary tree) {
   try {
     int ownprec = TreeInfo.opPrec(tree.getTag());
     String opname = operatorName(tree.getTag());
     open(prec, ownprec);
     if (tree.getTag() <= JCTree.PREDEC) {
       print(opname);
       printExpr(tree.arg, ownprec);
     } else {
       printExpr(tree.arg, ownprec);
       print(opname);
     }
     close(prec, ownprec);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
예제 #4
0
 /** Print a set of modifiers. */
 public void printFlags(long flags) throws IOException {
   if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
   print(TreeInfo.flagNames(flags));
   if ((flags & StandardFlags) != 0) print(" ");
   if ((flags & ANNOTATION) != 0) print("@");
 }
예제 #5
0
 // Prints the inner element type of a nested array
 private void printBaseElementType(JCTree tree) throws IOException {
   printExpr(TreeInfo.innermostType(tree));
 }