8004828: refactor init of *DocImpl classes
authorjjg
Tue, 11 Dec 2012 15:05:55 -0800
changeset 14802 969e90f68ac5
parent 14801 d66cab4ef397
child 14803 88347e495d34
8004828: refactor init of *DocImpl classes Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ConstructorDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java
langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java
langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java
langtools/src/share/classes/com/sun/tools/javadoc/MemberDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java
--- a/langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -27,13 +27,13 @@
 
 import com.sun.javadoc.*;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Kinds;
 import com.sun.tools.javac.code.Scope;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.Names;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Represents an annotation type.
@@ -51,12 +51,11 @@
         extends ClassDocImpl implements AnnotationTypeDoc {
 
     public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
-        this(env, sym, null, null, null);
+        this(env, sym, null);
     }
 
-    public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym,
-                          String doc, JCClassDecl tree, Position.LineMap lineMap) {
-        super(env, sym, doc, tree, lineMap);
+    public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -27,9 +27,9 @@
 
 import com.sun.javadoc.*;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Represents an element of an annotation type.
@@ -50,9 +50,8 @@
         super(env, sym);
     }
 
-    public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym,
-                                 String doc, JCMethodDecl tree, Position.LineMap lineMap) {
-        super(env, sym, doc, tree, lineMap);
+    public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -31,13 +31,14 @@
 import java.net.URI;
 import java.util.HashSet;
 import java.util.Set;
+
 import javax.tools.FileObject;
 import javax.tools.JavaFileManager.Location;
 import javax.tools.StandardJavaFileManager;
 import javax.tools.StandardLocation;
 
 import com.sun.javadoc.*;
-
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.Kinds;
 import com.sun.tools.javac.code.Scope;
@@ -45,22 +46,17 @@
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type;
 import com.sun.tools.javac.code.Type.ClassType;
-
 import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Env;
-
 import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
 import com.sun.tools.javac.tree.JCTree.JCImport;
 import com.sun.tools.javac.tree.TreeInfo;
-
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Name;
 import com.sun.tools.javac.util.Names;
 import com.sun.tools.javac.util.Position;
-
 import static com.sun.tools.javac.code.Kinds.*;
 import static com.sun.tools.javac.code.TypeTag.CLASS;
 import static com.sun.tools.javac.tree.JCTree.Tag.*;
@@ -100,15 +96,14 @@
      * Constructor
      */
     public ClassDocImpl(DocEnv env, ClassSymbol sym) {
-        this(env, sym, null, null, null);
+        this(env, sym, null);
     }
 
     /**
      * Constructor
      */
-    public ClassDocImpl(DocEnv env, ClassSymbol sym, String documentation,
-                        JCClassDecl tree, Position.LineMap lineMap) {
-        super(env, sym, documentation, tree, lineMap);
+    public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
         this.type = (ClassType)sym.type;
         this.tsym = sym;
     }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ConstructorDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ConstructorDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -27,10 +27,9 @@
 
 import com.sun.javadoc.*;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import com.sun.tools.javac.code.Symbol.MethodSymbol;
-import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Represents a constructor of a java class.
@@ -58,9 +57,8 @@
     /**
      * constructor.
      */
-    public ConstructorDocImpl(DocEnv env, MethodSymbol sym,
-                              String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
-        super(env, sym, docComment, tree, lineMap);
+    public ConstructorDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Tue Dec 11 15:05:55 2012 -0800
@@ -27,18 +27,20 @@
 
 import java.lang.reflect.Modifier;
 import java.util.*;
+
 import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
-
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.api.JavacTrees;
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type.ClassType;
 import com.sun.tools.javac.comp.Check;
+import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.Names;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Holds the environment for a run of javadoc.
@@ -104,6 +106,8 @@
     JavaFileManager fileManager;
     Context context;
 
+    WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
+
     /** Allow documenting from class files? */
     boolean docClasses = false;
 
@@ -540,13 +544,12 @@
     /**
      * Create the PackageDoc (or a subtype) for a package symbol.
      */
-    void makePackageDoc(PackageSymbol pack, String docComment, JCCompilationUnit tree) {
+    void makePackageDoc(PackageSymbol pack, TreePath treePath) {
         PackageDocImpl result = packageMap.get(pack);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
         } else {
-            result = new PackageDocImpl(this, pack, docComment, tree);
+            result = new PackageDocImpl(this, pack, treePath);
             packageMap.put(pack, result);
         }
     }
@@ -572,17 +575,16 @@
     /**
      * Create the ClassDoc (or a subtype) for a class symbol.
      */
-    protected void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) {
+    protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
         ClassDocImpl result = classMap.get(clazz);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
             return;
         }
-        if (isAnnotationType(tree)) {   // flags of clazz may not yet be set
-            result = new AnnotationTypeDocImpl(this, clazz, docComment, tree, lineMap);
+        if (isAnnotationType((JCClassDecl) treePath.getLeaf())) {   // flags of clazz may not yet be set
+            result = new AnnotationTypeDocImpl(this, clazz, treePath);
         } else {
-            result = new ClassDocImpl(this, clazz, docComment, tree, lineMap);
+            result = new ClassDocImpl(this, clazz, treePath);
         }
         classMap.put(clazz, result);
     }
@@ -610,13 +612,12 @@
     /**
      * Create a FieldDoc for a var symbol.
      */
-    protected void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) {
+    protected void makeFieldDoc(VarSymbol var, TreePath treePath) {
         FieldDocImpl result = fieldMap.get(var);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
         } else {
-            result = new FieldDocImpl(this, var, docComment, tree, lineMap);
+            result = new FieldDocImpl(this, var, treePath);
             fieldMap.put(var, result);
         }
     }
@@ -627,14 +628,12 @@
      * Create a MethodDoc for this MethodSymbol.
      * Should be called only on symbols representing methods.
      */
-    protected void makeMethodDoc(MethodSymbol meth, String docComment,
-                       JCMethodDecl tree, Position.LineMap lineMap) {
+    protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
         MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
         } else {
-            result = new MethodDocImpl(this, meth, docComment, tree, lineMap);
+            result = new MethodDocImpl(this, meth, treePath);
             methodMap.put(meth, result);
         }
     }
@@ -656,14 +655,12 @@
      * Create the ConstructorDoc for a MethodSymbol.
      * Should be called only on symbols representing constructors.
      */
-    protected void makeConstructorDoc(MethodSymbol meth, String docComment,
-                            JCMethodDecl tree, Position.LineMap lineMap) {
+    protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
         ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
         } else {
-            result = new ConstructorDocImpl(this, meth, docComment, tree, lineMap);
+            result = new ConstructorDocImpl(this, meth, treePath);
             methodMap.put(meth, result);
         }
     }
@@ -685,16 +682,14 @@
      * Create the AnnotationTypeElementDoc for a MethodSymbol.
      * Should be called only on symbols representing annotation type elements.
      */
-    protected void makeAnnotationTypeElementDoc(MethodSymbol meth,
-                                      String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
+    protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
         AnnotationTypeElementDocImpl result =
             (AnnotationTypeElementDocImpl)methodMap.get(meth);
         if (result != null) {
-            if (docComment != null) result.setRawCommentText(docComment);
-            if (tree != null) result.setTree(tree);
+            if (treePath != null) result.setTreePath(treePath);
         } else {
             result =
-                new AnnotationTypeElementDocImpl(this, meth, docComment, tree, lineMap);
+                new AnnotationTypeElementDocImpl(this, meth, treePath);
             methodMap.put(meth, result);
         }
     }
@@ -730,6 +725,18 @@
 //      return result;
     }
 
+    TreePath getTreePath(JCCompilationUnit tree) {
+        TreePath p = treePaths.get(tree);
+        if (p == null)
+            treePaths.put(tree, p = new TreePath(tree));
+        return p;
+    }
+
+    TreePath getTreePath(JCCompilationUnit toplevel, JCTree tree) {
+        // don't bother to cache paths for classes and members
+        return new TreePath(getTreePath(toplevel), tree);
+    }
+
     /**
      * Set the encoding.
      */
--- a/langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -35,6 +35,9 @@
 import javax.tools.FileObject;
 
 import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
 import com.sun.tools.javac.util.Position;
 
 /**
@@ -61,6 +64,12 @@
     protected final DocEnv env;   //### Rename this everywhere to 'docenv' ?
 
     /**
+     * Back pointer to the tree node for this doc item.
+     * May be null if there is no associated tree.
+     */
+    protected TreePath treePath;
+
+    /**
      *  The complex comment object, lazily initialized.
      */
     private Comment comment;
@@ -88,11 +97,21 @@
     /**
      * Constructor.
      */
-    DocImpl(DocEnv env, String documentation) {
-        this.documentation = documentation;
+    DocImpl(DocEnv env, TreePath treePath) {
+        this.treePath = treePath;
+        this.documentation = getCommentText(treePath);
         this.env = env;
     }
 
+    private static String getCommentText(TreePath p) {
+        if (p == null)
+            return null;
+
+        JCCompilationUnit topLevel = (JCCompilationUnit) p.getCompilationUnit();
+        JCTree tree = (JCTree) p.getLeaf();
+        return topLevel.docComments.getCommentText(tree);
+    }
+
     /**
      * So subclasses have the option to do lazy initialization of
      * "documentation" string.
@@ -213,11 +232,21 @@
      * operations like internalization.
      */
     public void setRawCommentText(String rawDocumentation) {
+        treePath = null;
         documentation = rawDocumentation;
         comment = null;
     }
 
     /**
+     * Set the full unprocessed text of the comment and tree path.
+     */
+    void setTreePath(TreePath treePath) {
+        this.treePath = treePath;
+        documentation = getCommentText(treePath);
+        comment = null;
+    }
+
+    /**
      * return a key for sorting.
      */
     CollationKey key() {
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -30,13 +30,12 @@
 
 import com.sun.javadoc.*;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Represents a method or constructor of a java class.
@@ -60,9 +59,8 @@
     /**
      * Constructor.
      */
-    public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym,
-                                   String rawDocs, JCMethodDecl tree, Position.LineMap lineMap) {
-        super(env, sym, rawDocs, tree, lineMap);
+    public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
         this.sym = sym;
     }
 
@@ -70,7 +68,7 @@
      * Constructor.
      */
     public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
-        this(env, sym, null, null, null);
+        this(env, sym, null);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -25,6 +25,7 @@
 
 package com.sun.tools.javadoc;
 
+import com.sun.source.util.TreePath;
 import java.lang.reflect.Modifier;
 
 import com.sun.javadoc.*;
@@ -61,9 +62,8 @@
     /**
      * Constructor.
      */
-    public FieldDocImpl(DocEnv env, VarSymbol sym,
-                        String rawDocs, JCVariableDecl tree, Position.LineMap lineMap) {
-        super(env, sym, rawDocs, tree, lineMap);
+    public FieldDocImpl(DocEnv env, VarSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
         this.sym = sym;
     }
 
@@ -71,7 +71,7 @@
      * Constructor.
      */
     public FieldDocImpl(DocEnv env, VarSymbol sym) {
-        this(env, sym, null, null, null);
+        this(env, sym, null);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java	Tue Dec 11 15:05:55 2012 -0800
@@ -25,13 +25,14 @@
 
 package com.sun.tools.javadoc;
 
+
 import javax.tools.JavaFileObject;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Kinds;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.comp.Enter;
 import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.tree.TreeInfo;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.util.List;
@@ -85,8 +86,7 @@
     public void visitTopLevel(JCCompilationUnit tree) {
         super.visitTopLevel(tree);
         if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
-            String comment = TreeInfo.getCommentText(env, tree);
-            docenv.makePackageDoc(tree.packge, comment, tree);
+            docenv.makePackageDoc(tree.packge, docenv.getTreePath(tree));
         }
     }
 
@@ -95,9 +95,8 @@
         super.visitClassDef(tree);
         if (tree.sym == null) return;
         if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) {
-            String comment = TreeInfo.getCommentText(env, tree);
             ClassSymbol c = tree.sym;
-            docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap);
+            docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree));
         }
     }
 
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java	Tue Dec 11 15:05:55 2012 -0800
@@ -25,14 +25,13 @@
 
 package com.sun.tools.javadoc;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.Kinds;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.comp.MemberEnter;
 import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.tree.TreeInfo;
 import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.Position;
 
 /**
  *  Javadoc's own memberEnter phase does a few things above and beyond that
@@ -73,14 +72,13 @@
         super.visitMethodDef(tree);
         MethodSymbol meth = tree.sym;
         if (meth == null || meth.kind != Kinds.MTH) return;
-        String docComment = TreeInfo.getCommentText(env, tree);
-        Position.LineMap lineMap = env.toplevel.lineMap;
+        TreePath treePath = docenv.getTreePath(env.toplevel, tree);
         if (meth.isConstructor())
-            docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
+            docenv.makeConstructorDoc(meth, treePath);
         else if (isAnnotationTypeElement(meth))
-            docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap);
+            docenv.makeAnnotationTypeElementDoc(meth, treePath);
         else
-            docenv.makeMethodDoc(meth, docComment, tree, lineMap);
+            docenv.makeMethodDoc(meth, treePath);
 
         // release resources
         tree.body = null;
@@ -92,9 +90,7 @@
         if (tree.sym != null &&
                 tree.sym.kind == Kinds.VAR &&
                 !isParameter(tree.sym)) {
-            String docComment = TreeInfo.getCommentText(env, tree);
-            Position.LineMap lineMap = env.toplevel.lineMap;
-            docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
+            docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, tree));
         }
     }
 
--- a/langtools/src/share/classes/com/sun/tools/javadoc/MemberDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/MemberDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -27,9 +27,8 @@
 
 import com.sun.javadoc.*;
 
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.util.Position;
 
 /**
  * Represents a member of a java class: field, constructor, or method.
@@ -57,8 +56,8 @@
     /**
      * constructor.
      */
-    public MemberDocImpl(DocEnv env, Symbol sym, String doc, JCTree tree, Position.LineMap lineMap) {
-        super(env, sym, doc, tree, lineMap);
+    public MemberDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
+        super(env, sym, treePath);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -28,12 +28,10 @@
 import java.lang.reflect.Modifier;
 
 import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
-import com.sun.tools.javac.util.Position;
-
 import static com.sun.tools.javac.code.TypeTag.CLASS;
 
 /**
@@ -62,9 +60,8 @@
     /**
      * constructor.
      */
-    public MethodDocImpl(DocEnv env, MethodSymbol sym,
-                         String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
-        super(env, sym, docComment, tree, lineMap);
+    public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+        super(env, sym, treePath);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -31,6 +31,7 @@
 import javax.tools.FileObject;
 
 import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Attribute;
 import com.sun.tools.javac.code.Scope;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
@@ -75,17 +76,16 @@
      * Constructor
      */
     public PackageDocImpl(DocEnv env, PackageSymbol sym) {
-        this(env, sym, null, null);
+        this(env, sym, null);
     }
 
     /**
      * Constructor
      */
-    public PackageDocImpl(DocEnv env, PackageSymbol sym,
-                          String documentation, JCTree tree) {
-        super(env, documentation);
+    public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
+        super(env, treePath);
         this.sym = sym;
-        this.tree = (JCCompilationUnit) tree;
+        this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
         foundDoc = (documentation != null);
     }
 
@@ -93,8 +93,8 @@
         this.tree = (JCCompilationUnit) tree;
     }
 
-    public void setRawCommentText(String rawDocumentation) {
-        super.setRawCommentText(rawDocumentation);
+    public void setTreePath(TreePath treePath) {
+        super.setTreePath(treePath);
         checkDoc();
     }
 
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -29,10 +29,12 @@
 import java.text.CollationKey;
 
 import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.code.Attribute;
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
 import com.sun.tools.javac.util.Position;
 
 /**
@@ -66,16 +68,20 @@
     // Cache for getModifiers().
     private int modifiers = -1;
 
-    protected ProgramElementDocImpl(DocEnv env, Symbol sym,
-                                    String doc, JCTree tree, Position.LineMap lineMap) {
-        super(env, doc);
+    protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
+        super(env, treePath);
         this.sym = sym;
-        this.tree = tree;
-        this.lineMap = lineMap;
+        if (treePath != null) {
+            tree = (JCTree) treePath.getLeaf();
+            lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
+        }
     }
 
-    void setTree(JCTree tree) {
-        this.tree = tree;
+    @Override
+    void setTreePath(TreePath treePath) {
+        super.setTreePath(treePath);
+        this.tree = (JCTree) treePath.getLeaf();
+        this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Mon Dec 10 16:21:26 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Tue Dec 11 15:05:55 2012 -0800
@@ -331,7 +331,6 @@
     @Override
     protected String documentation() {
         if (documentation == null) {
-            int cnt = options.length();
             JavaFileObject overviewPath = getOverviewPath();
             if (overviewPath == null) {
                 // no doc file to be had