# HG changeset patch # User jjg # Date 1340223806 25200 # Node ID 5c0b3faeb0b08c1a609d6148f5152cebafc7f2fd # Parent 34e254ffd0e7b1df8e642dfab020a0a0b435cae7 7174143: encapsulate doc comment table Reviewed-by: ksrini, mcimadamore diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/api/JavacTrees.java --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Wed Jun 20 13:23:26 2012 -0700 @@ -60,7 +60,7 @@ import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.comp.Resolve; import com.sun.tools.javac.model.JavacElements; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; @@ -240,10 +240,11 @@ public String getDocComment(TreePath path) { CompilationUnitTree t = path.getCompilationUnit(); - if (t instanceof JCTree.JCCompilationUnit) { + Tree leaf = path.getLeaf(); + if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { JCCompilationUnit cu = (JCCompilationUnit) t; if (cu.docComments != null) { - return cu.docComments.get(path.getLeaf()); + return cu.docComments.getCommentText((JCTree) leaf); } } return null; diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/comp/Enter.java --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -312,7 +312,7 @@ tree.packge); if (addEnv || (tree0.packageAnnotations.isEmpty() && tree.docComments != null && - tree.docComments.get(tree) != null)) { + tree.docComments.hasComment(tree))) { typeEnvs.put(tree.packge, topEnv); } } diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/comp/Lower.java --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,7 @@ import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Target; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.BLOCK; diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/jvm/CRTable.java --- a/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,7 @@ import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.List; import com.sun.tools.javac.tree.JCTree.*; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; /** This class contains the CharacterRangeTable for some method * and the hashtable for mapping trees or lists of trees to their diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/jvm/Gen.java --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Code.*; import com.sun.tools.javac.jvm.Items.*; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/model/JavacElements.java --- a/src/share/classes/com/sun/tools/javac/model/JavacElements.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/model/JavacElements.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,11 +28,14 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; import java.util.Map; + import javax.lang.model.SourceVersion; import javax.lang.model.element.*; import javax.lang.model.type.DeclaredType; import javax.lang.model.util.Elements; import javax.tools.JavaFileObject; +import static javax.lang.model.util.ElementFilter.methodsIn; + import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.TypeTags; @@ -47,9 +50,7 @@ import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.Name; - import static com.sun.tools.javac.tree.JCTree.Tag.*; -import static javax.lang.model.util.ElementFilter.methodsIn; /** * Utility methods for operating on program elements. @@ -361,7 +362,7 @@ JCCompilationUnit toplevel = treeTop.snd; if (toplevel.docComments == null) return null; - return toplevel.docComments.get(tree); + return toplevel.docComments.getCommentText(tree); } public PackageElement getPackageOf(Element e) { diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/parser/EndPosTable.java --- a/src/share/classes/com/sun/tools/javac/parser/EndPosTable.java Tue Jun 19 13:25:58 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.tools.javac.parser; - -import com.sun.tools.javac.tree.JCTree; - -/** - * Specifies the methods to access a mappings of syntax trees to end positions. - *
This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own - * risk. This code and its internal interfaces are subject to change - * or deletion without notice.
- */ -public interface EndPosTable { - - /** - * This method will return the end position of a given tree, otherwise a - * Positions.NOPOS will be returned. - * @param tree JCTree - * @return position of the source tree or Positions.NOPOS for non-existent mapping - */ - public int getEndPos(JCTree tree); - - /** - * Give an old tree and a new tree, the old tree will be replaced with - * the new tree, the position of the new tree will be that of the old - * tree. - * not exist. - * @param oldtree a JCTree to be replaced - * @param newtree a JCTree to be replaced with - * @return position of the old tree or Positions.NOPOS for non-existent mapping - */ - public int replaceTree(JCTree oldtree, JCTree newtree); -} diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Tue Jun 19 13:25:58 2012 +0100 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Wed Jun 20 13:23:26 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -571,7 +571,7 @@ reader.scanCommentChar(); } while (reader.ch != CR && reader.ch != LF && reader.bp < reader.buflen); if (reader.bp < reader.buflen) { - comments = addDocReader(comments, processComment(pos, reader.bp, CommentStyle.LINE)); + comments = addComment(comments, processComment(pos, reader.bp, CommentStyle.LINE)); } break; } else if (reader.ch == '*') { @@ -597,7 +597,7 @@ } if (reader.ch == '/') { reader.scanChar(); - comments = addDocReader(comments, processComment(pos, reader.bp, style)); + comments = addComment(comments, processComment(pos, reader.bp, style)); break; } else { lexError(pos, "unclosed.comment"); @@ -693,10 +693,10 @@ } } //where - ListThis is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.
+ */
+public class SimpleDocCommentTable implements DocCommentTable {
+ Map This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own
+ * risk. This code and its internal interfaces are subject to change
+ * or deletion without notice.
+ */
+public interface DocCommentTable {
+ /**
+ * Check if a tree node has a corresponding doc comment.
+ */
+ public boolean hasComment(JCTree tree);
+
+ /**
+ * Get the Comment token containing the doc comment, if any, for a tree node.
+ */
+ public Comment getComment(JCTree tree);
+
+ /**
+ * Get the plain text of the doc comment, if any, for a tree node.
+ */
+ public String getCommentText(JCTree tree);
+
+ /**
+ * Set the Comment to be associated with a tree node.
+ */
+ public void putComment(JCTree tree, Comment c);
+}
diff -r 34e254ffd0e7 -r 5c0b3faeb0b0 src/share/classes/com/sun/tools/javac/tree/EndPosTable.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/javac/tree/EndPosTable.java Wed Jun 20 13:23:26 2012 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.javac.tree;
+
+/**
+ * Specifies the methods to access a mappings of syntax trees to end positions.
+ * This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own
+ * risk. This code and its internal interfaces are subject to change
+ * or deletion without notice.