src/share/classes/com/sun/tools/javac/tree/Pretty.java

Print this page

        

*** 308,318 **** print("}"); } /** Is the given tree an enumerator definition? */ boolean isEnumerator(JCTree t) { ! return t.getTag() == JCTree.VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 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. --- 308,318 ---- print("}"); } /** Is the given tree an enumerator definition? */ boolean isEnumerator(JCTree t) { ! return t.getTag() == JCTree.Tag.VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 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.
*** 329,341 **** 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.names.asterisk || cdef == null || isUsed(TreeInfo.symbol(imp.qualid), cdef)) { --- 329,341 ---- print(";"); println(); } boolean firstImport = true; for (List<JCTree> l = tree.defs; ! l.nonEmpty() && (cdef == null || l.head.getTag() == JCTree.Tag.IMPORT); l = l.tail) { ! if (l.head.getTag() == JCTree.Tag.IMPORT) { JCImport imp = (JCImport)l.head; Name name = TreeInfo.name(imp.qualid); if (name == name.table.names.asterisk || cdef == null || isUsed(TreeInfo.symbol(imp.qualid), cdef)) {
*** 482,492 **** printDocComment(tree); if ((tree.mods.flags & ENUM) != 0) { print("/*public static final*/ "); print(tree.name); if (tree.init != null) { ! if (sourceOutput && tree.init.getTag() == JCTree.NEWCLASS) { print(" /*enum*/ "); JCNewClass init = (JCNewClass) tree.init; if (init.args != null && init.args.nonEmpty()) { print("("); print(init.args); --- 482,492 ---- printDocComment(tree); if ((tree.mods.flags & ENUM) != 0) { print("/*public static final*/ "); print(tree.name); if (tree.init != null) { ! if (sourceOutput && tree.init.getTag() == JCTree.Tag.NEWCLASS) { print(" /*enum*/ "); JCNewClass init = (JCNewClass) tree.init; if (init.args != null && init.args.nonEmpty()) { print("("); print(init.args);
*** 543,553 **** try { print("do "); printStat(tree.body); align(); print(" while "); ! if (tree.cond.getTag() == JCTree.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")"); --- 543,553 ---- try { print("do "); printStat(tree.body); align(); print(" while "); ! if (tree.cond.getTag() == JCTree.Tag.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")");
*** 559,569 **** } public void visitWhileLoop(JCWhileLoop tree) { try { print("while "); ! if (tree.cond.getTag() == JCTree.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")"); --- 559,569 ---- } public void visitWhileLoop(JCWhileLoop tree) { try { print("while "); ! if (tree.cond.getTag() == JCTree.Tag.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")");
*** 577,587 **** public void visitForLoop(JCForLoop tree) { try { print("for ("); if (tree.init.nonEmpty()) { ! if (tree.init.head.getTag() == JCTree.VARDEF) { printExpr(tree.init.head); for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { JCVariableDecl vdef = (JCVariableDecl)l.head; print(", " + vdef.name + " = "); printExpr(vdef.init); --- 577,587 ---- public void visitForLoop(JCForLoop tree) { try { print("for ("); if (tree.init.nonEmpty()) { ! if (tree.init.head.getTag() == JCTree.Tag.VARDEF) { printExpr(tree.init.head); for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { JCVariableDecl vdef = (JCVariableDecl)l.head; print(", " + vdef.name + " = "); printExpr(vdef.init);
*** 624,634 **** } public void visitSwitch(JCSwitch tree) { try { print("switch "); ! if (tree.selector.getTag() == JCTree.PARENS) { printExpr(tree.selector); } else { print("("); printExpr(tree.selector); print(")"); --- 624,634 ---- } public void visitSwitch(JCSwitch tree) { try { print("switch "); ! if (tree.selector.getTag() == JCTree.Tag.PARENS) { printExpr(tree.selector); } else { print("("); printExpr(tree.selector); print(")");
*** 663,673 **** } public void visitSynchronized(JCSynchronized tree) { try { print("synchronized "); ! if (tree.lock.getTag() == JCTree.PARENS) { printExpr(tree.lock); } else { print("("); printExpr(tree.lock); print(")"); --- 663,673 ---- } public void visitSynchronized(JCSynchronized tree) { try { print("synchronized "); ! if (tree.lock.getTag() == JCTree.Tag.PARENS) { printExpr(tree.lock); } else { print("("); printExpr(tree.lock); print(")");
*** 734,744 **** } public void visitIf(JCIf tree) { try { print("if "); ! if (tree.cond.getTag() == JCTree.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")"); --- 734,744 ---- } public void visitIf(JCIf tree) { try { print("if "); ! if (tree.cond.getTag() == JCTree.Tag.PARENS) { printExpr(tree.cond); } else { print("("); printExpr(tree.cond); print(")");
*** 821,831 **** } public void visitApply(JCMethodInvocation tree) { try { if (!tree.typeargs.isEmpty()) { ! if (tree.meth.getTag() == JCTree.SELECT) { JCFieldAccess left = (JCFieldAccess)tree.meth; printExpr(left.selected); print(".<"); printExprs(tree.typeargs); print(">" + left.name); --- 821,831 ---- } public void visitApply(JCMethodInvocation tree) { try { if (!tree.typeargs.isEmpty()) { ! if (tree.meth.getTag() == JCTree.Tag.SELECT) { JCFieldAccess left = (JCFieldAccess)tree.meth; printExpr(left.selected); print(".<"); printExprs(tree.typeargs); print(">" + left.name);
*** 880,890 **** public void visitNewArray(JCNewArray tree) { try { if (tree.elemtype != null) { print("new "); JCTree elem = tree.elemtype; ! if (elem.getTag() == JCTree.TYPEARRAY) printBaseElementType((JCArrayTypeTree) elem); else printExpr(elem); for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { print("["); --- 880,890 ---- public void visitNewArray(JCNewArray tree) { try { if (tree.elemtype != null) { print("new "); JCTree elem = tree.elemtype; ! if (elem.getTag() == JCTree.Tag.TYPEARRAY) printBaseElementType((JCArrayTypeTree) elem); else printExpr(elem); for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { print("[");
*** 925,973 **** } catch (IOException e) { throw new UncheckedIOException(e); } } ! public String operatorName(int tag) { switch(tag) { ! case JCTree.POS: return "+"; ! case JCTree.NEG: return "-"; ! case JCTree.NOT: return "!"; ! case JCTree.COMPL: return "~"; ! case JCTree.PREINC: return "++"; ! case JCTree.PREDEC: return "--"; ! case JCTree.POSTINC: return "++"; ! case JCTree.POSTDEC: return "--"; ! case JCTree.NULLCHK: return "<*nullchk*>"; ! case JCTree.OR: return "||"; ! case JCTree.AND: return "&&"; ! case JCTree.EQ: return "=="; ! case JCTree.NE: return "!="; ! case JCTree.LT: return "<"; ! case JCTree.GT: return ">"; ! case JCTree.LE: return "<="; ! case JCTree.GE: return ">="; ! case JCTree.BITOR: return "|"; ! case JCTree.BITXOR: return "^"; ! case JCTree.BITAND: return "&"; ! case JCTree.SL: return "<<"; ! case JCTree.SR: return ">>"; ! case JCTree.USR: return ">>>"; ! case JCTree.PLUS: return "+"; ! case JCTree.MINUS: return "-"; ! case JCTree.MUL: return "*"; ! case JCTree.DIV: return "/"; ! case JCTree.MOD: return "%"; default: throw new Error(); } } public void visitAssignop(JCAssignOp tree) { try { open(prec, TreeInfo.assignopPrec); printExpr(tree.lhs, TreeInfo.assignopPrec + 1); ! print(" " + operatorName(tree.getTag() - JCTree.ASGOffset) + "= "); printExpr(tree.rhs, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec); } catch (IOException e) { throw new UncheckedIOException(e); } --- 925,973 ---- } catch (IOException e) { throw new UncheckedIOException(e); } } ! public String operatorName(JCTree.Tag tag) { switch(tag) { ! case POS: return "+"; ! case NEG: return "-"; ! case NOT: return "!"; ! case COMPL: return "~"; ! case PREINC: return "++"; ! case PREDEC: return "--"; ! case POSTINC: return "++"; ! case POSTDEC: return "--"; ! case NULLCHK: return "<*nullchk*>"; ! case OR: return "||"; ! case AND: return "&&"; ! case EQ: return "=="; ! case NE: return "!="; ! case LT: return "<"; ! case GT: return ">"; ! case LE: return "<="; ! case GE: return ">="; ! case BITOR: return "|"; ! case BITXOR: return "^"; ! case BITAND: return "&"; ! case SL: return "<<"; ! case SR: return ">>"; ! case USR: return ">>>"; ! case PLUS: return "+"; ! case MINUS: return "-"; ! case MUL: return "*"; ! case DIV: return "/"; ! case MOD: return "%"; default: throw new Error(); } } public void visitAssignop(JCAssignOp tree) { try { open(prec, TreeInfo.assignopPrec); printExpr(tree.lhs, TreeInfo.assignopPrec + 1); ! print(" " + operatorName(tree.getTag().noAssignOp()) + "= "); printExpr(tree.rhs, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec); } catch (IOException e) { throw new UncheckedIOException(e); }
*** 976,986 **** 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); --- 976,986 ---- public void visitUnary(JCUnary tree) { try { int ownprec = TreeInfo.opPrec(tree.getTag()); String opname = operatorName(tree.getTag()); open(prec, ownprec); ! if (tree.getTag().ordinal() <= JCTree.Tag.PREDEC.ordinal()) { print(opname); printExpr(tree.arg, ownprec); } else { printExpr(tree.arg, ownprec); print(opname);
*** 1151,1161 **** private void printBrackets(JCArrayTypeTree tree) throws IOException { JCTree elem; while (true) { elem = tree.elemtype; print("[]"); ! if (elem.getTag() != JCTree.TYPEARRAY) break; tree = (JCArrayTypeTree) elem; } } public void visitTypeApply(JCTypeApply tree) { --- 1151,1161 ---- private void printBrackets(JCArrayTypeTree tree) throws IOException { JCTree elem; while (true) { elem = tree.elemtype; print("[]"); ! if (elem.getTag() != JCTree.Tag.TYPEARRAY) break; tree = (JCArrayTypeTree) elem; } } public void visitTypeApply(JCTypeApply tree) {