equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 import java.util.*; |
29 import java.util.*; |
30 |
30 |
31 import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
31 import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
32 |
32 import com.sun.tools.javac.code.*; |
|
33 import com.sun.tools.javac.code.Symbol.*; |
|
34 import com.sun.tools.javac.parser.Tokens.Comment; |
|
35 import com.sun.tools.javac.tree.JCTree.*; |
33 import com.sun.tools.javac.util.*; |
36 import com.sun.tools.javac.util.*; |
34 import com.sun.tools.javac.util.List; |
37 import com.sun.tools.javac.util.List; |
35 import com.sun.tools.javac.code.*; |
|
36 |
|
37 import com.sun.tools.javac.code.Symbol.*; |
|
38 import com.sun.tools.javac.tree.JCTree.*; |
|
39 |
|
40 import static com.sun.tools.javac.code.Flags.*; |
38 import static com.sun.tools.javac.code.Flags.*; |
41 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
39 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
42 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
40 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
43 |
41 |
44 /** Prints out a tree as an indented Java source program. |
42 /** Prints out a tree as an indented Java source program. |
76 |
74 |
77 /** The enclosing class name. |
75 /** The enclosing class name. |
78 */ |
76 */ |
79 Name enclClassName; |
77 Name enclClassName; |
80 |
78 |
81 /** A hashtable mapping trees to their documentation comments |
79 /** A table mapping trees to their documentation comments |
82 * (can be null) |
80 * (can be null) |
83 */ |
81 */ |
84 Map<JCTree, String> docComments = null; |
82 DocCommentTable docComments = null; |
85 |
83 |
86 /** Align code to be indented to left margin. |
84 /** Align code to be indented to left margin. |
87 */ |
85 */ |
88 void align() throws IOException { |
86 void align() throws IOException { |
89 for (int i = 0; i < lmargin; i++) out.write(" "); |
87 for (int i = 0; i < lmargin; i++) out.write(" "); |
231 /** Print documentation comment, if it exists |
229 /** Print documentation comment, if it exists |
232 * @param tree The tree for which a documentation comment should be printed. |
230 * @param tree The tree for which a documentation comment should be printed. |
233 */ |
231 */ |
234 public void printDocComment(JCTree tree) throws IOException { |
232 public void printDocComment(JCTree tree) throws IOException { |
235 if (docComments != null) { |
233 if (docComments != null) { |
236 String dc = docComments.get(tree); |
234 String dc = docComments.getCommentText(tree); |
237 if (dc != null) { |
235 if (dc != null) { |
238 print("/**"); println(); |
236 print("/**"); println(); |
239 int pos = 0; |
237 int pos = 0; |
240 int endpos = lineEndPos(dc, pos); |
238 int endpos = lineEndPos(dc, pos); |
241 while (pos < dc.length()) { |
239 while (pos < dc.length()) { |
478 } |
476 } |
479 } |
477 } |
480 |
478 |
481 public void visitVarDef(JCVariableDecl tree) { |
479 public void visitVarDef(JCVariableDecl tree) { |
482 try { |
480 try { |
483 if (docComments != null && docComments.get(tree) != null) { |
481 if (docComments != null && docComments.hasComment(tree)) { |
484 println(); align(); |
482 println(); align(); |
485 } |
483 } |
486 printDocComment(tree); |
484 printDocComment(tree); |
487 if ((tree.mods.flags & ENUM) != 0) { |
485 if ((tree.mods.flags & ENUM) != 0) { |
488 print("/*public static final*/ "); |
486 print("/*public static final*/ "); |