8004828: refactor init of *DocImpl classes

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2012-12-11 15:05:55 -08:00
parent 8fc2d739bd
commit 1c8e65a20e
15 changed files with 128 additions and 107 deletions

View file

@ -27,13 +27,13 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Scope; import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position;
/** /**
* Represents an annotation type. * Represents an annotation type.
@ -51,12 +51,11 @@ public class AnnotationTypeDocImpl
extends ClassDocImpl implements AnnotationTypeDoc { extends ClassDocImpl implements AnnotationTypeDoc {
public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
this(env, sym, null, null, null); this(env, sym, null);
} }
public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
String doc, JCClassDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, doc, tree, lineMap);
} }
/** /**

View file

@ -27,9 +27,9 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.Position;
/** /**
* Represents an element of an annotation type. * Represents an element of an annotation type.
@ -50,9 +50,8 @@ public class AnnotationTypeElementDocImpl
super(env, sym); super(env, sym);
} }
public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
String doc, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, doc, tree, lineMap);
} }
/** /**

View file

@ -31,13 +31,14 @@ import java.lang.reflect.Modifier;
import java.net.URI; import java.net.URI;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.tools.FileObject; import javax.tools.FileObject;
import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileManager.Location;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Scope; import com.sun.tools.javac.code.Scope;
@ -45,22 +46,17 @@ import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.tree.JCTree; 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.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCImport; import com.sun.tools.javac.tree.JCTree.JCImport;
import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTag.CLASS; import static com.sun.tools.javac.code.TypeTag.CLASS;
import static com.sun.tools.javac.tree.JCTree.Tag.*; import static com.sun.tools.javac.tree.JCTree.Tag.*;
@ -100,15 +96,14 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Constructor * Constructor
*/ */
public ClassDocImpl(DocEnv env, ClassSymbol sym) { public ClassDocImpl(DocEnv env, ClassSymbol sym) {
this(env, sym, null, null, null); this(env, sym, null);
} }
/** /**
* Constructor * Constructor
*/ */
public ClassDocImpl(DocEnv env, ClassSymbol sym, String documentation, public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
JCClassDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, documentation, tree, lineMap);
this.type = (ClassType)sym.type; this.type = (ClassType)sym.type;
this.tsym = sym; this.tsym = sym;
} }

View file

@ -27,10 +27,9 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; 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.ClassSymbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol; 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. * Represents a constructor of a java class.
@ -58,9 +57,8 @@ public class ConstructorDocImpl
/** /**
* constructor. * constructor.
*/ */
public ConstructorDocImpl(DocEnv env, MethodSymbol sym, public ConstructorDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
String docComment, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, docComment, tree, lineMap);
} }
/** /**

View file

@ -27,18 +27,20 @@ package com.sun.tools.javadoc;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import com.sun.javadoc.*; 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.*;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.comp.Check; 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.tree.JCTree.*;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position;
/** /**
* Holds the environment for a run of javadoc. * Holds the environment for a run of javadoc.
@ -104,6 +106,8 @@ public class DocEnv {
JavaFileManager fileManager; JavaFileManager fileManager;
Context context; Context context;
WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
/** Allow documenting from class files? */ /** Allow documenting from class files? */
boolean docClasses = false; boolean docClasses = false;
@ -540,13 +544,12 @@ public class DocEnv {
/** /**
* Create the PackageDoc (or a subtype) for a package symbol. * 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); PackageDocImpl result = packageMap.get(pack);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
} else { } else {
result = new PackageDocImpl(this, pack, docComment, tree); result = new PackageDocImpl(this, pack, treePath);
packageMap.put(pack, result); packageMap.put(pack, result);
} }
} }
@ -572,17 +575,16 @@ public class DocEnv {
/** /**
* Create the ClassDoc (or a subtype) for a class symbol. * 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); ClassDocImpl result = classMap.get(clazz);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
return; return;
} }
if (isAnnotationType(tree)) { // flags of clazz may not yet be set if (isAnnotationType((JCClassDecl) treePath.getLeaf())) { // flags of clazz may not yet be set
result = new AnnotationTypeDocImpl(this, clazz, docComment, tree, lineMap); result = new AnnotationTypeDocImpl(this, clazz, treePath);
} else { } else {
result = new ClassDocImpl(this, clazz, docComment, tree, lineMap); result = new ClassDocImpl(this, clazz, treePath);
} }
classMap.put(clazz, result); classMap.put(clazz, result);
} }
@ -610,13 +612,12 @@ public class DocEnv {
/** /**
* Create a FieldDoc for a var symbol. * 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); FieldDocImpl result = fieldMap.get(var);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
} else { } else {
result = new FieldDocImpl(this, var, docComment, tree, lineMap); result = new FieldDocImpl(this, var, treePath);
fieldMap.put(var, result); fieldMap.put(var, result);
} }
} }
@ -627,14 +628,12 @@ public class DocEnv {
* Create a MethodDoc for this MethodSymbol. * Create a MethodDoc for this MethodSymbol.
* Should be called only on symbols representing methods. * Should be called only on symbols representing methods.
*/ */
protected void makeMethodDoc(MethodSymbol meth, String docComment, protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
JCMethodDecl tree, Position.LineMap lineMap) {
MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
} else { } else {
result = new MethodDocImpl(this, meth, docComment, tree, lineMap); result = new MethodDocImpl(this, meth, treePath);
methodMap.put(meth, result); methodMap.put(meth, result);
} }
} }
@ -656,14 +655,12 @@ public class DocEnv {
* Create the ConstructorDoc for a MethodSymbol. * Create the ConstructorDoc for a MethodSymbol.
* Should be called only on symbols representing constructors. * Should be called only on symbols representing constructors.
*/ */
protected void makeConstructorDoc(MethodSymbol meth, String docComment, protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
JCMethodDecl tree, Position.LineMap lineMap) {
ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
} else { } else {
result = new ConstructorDocImpl(this, meth, docComment, tree, lineMap); result = new ConstructorDocImpl(this, meth, treePath);
methodMap.put(meth, result); methodMap.put(meth, result);
} }
} }
@ -685,16 +682,14 @@ public class DocEnv {
* Create the AnnotationTypeElementDoc for a MethodSymbol. * Create the AnnotationTypeElementDoc for a MethodSymbol.
* Should be called only on symbols representing annotation type elements. * Should be called only on symbols representing annotation type elements.
*/ */
protected void makeAnnotationTypeElementDoc(MethodSymbol meth, protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
AnnotationTypeElementDocImpl result = AnnotationTypeElementDocImpl result =
(AnnotationTypeElementDocImpl)methodMap.get(meth); (AnnotationTypeElementDocImpl)methodMap.get(meth);
if (result != null) { if (result != null) {
if (docComment != null) result.setRawCommentText(docComment); if (treePath != null) result.setTreePath(treePath);
if (tree != null) result.setTree(tree);
} else { } else {
result = result =
new AnnotationTypeElementDocImpl(this, meth, docComment, tree, lineMap); new AnnotationTypeElementDocImpl(this, meth, treePath);
methodMap.put(meth, result); methodMap.put(meth, result);
} }
} }
@ -730,6 +725,18 @@ public class DocEnv {
// return result; // 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. * Set the encoding.
*/ */

View file

@ -35,6 +35,9 @@ import java.util.regex.Pattern;
import javax.tools.FileObject; import javax.tools.FileObject;
import com.sun.javadoc.*; 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; import com.sun.tools.javac.util.Position;
/** /**
@ -60,6 +63,12 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
*/ */
protected final DocEnv env; //### Rename this everywhere to 'docenv' ? 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. * The complex comment object, lazily initialized.
*/ */
@ -88,11 +97,21 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
/** /**
* Constructor. * Constructor.
*/ */
DocImpl(DocEnv env, String documentation) { DocImpl(DocEnv env, TreePath treePath) {
this.documentation = documentation; this.treePath = treePath;
this.documentation = getCommentText(treePath);
this.env = env; 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 * So subclasses have the option to do lazy initialization of
* "documentation" string. * "documentation" string.
@ -213,10 +232,20 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
* operations like internalization. * operations like internalization.
*/ */
public void setRawCommentText(String rawDocumentation) { public void setRawCommentText(String rawDocumentation) {
treePath = null;
documentation = rawDocumentation; documentation = rawDocumentation;
comment = null; 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. * return a key for sorting.
*/ */

View file

@ -30,13 +30,12 @@ import java.text.CollationKey;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type; 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.List;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Position;
/** /**
* Represents a method or constructor of a java class. * Represents a method or constructor of a java class.
@ -60,9 +59,8 @@ public abstract class ExecutableMemberDocImpl
/** /**
* Constructor. * Constructor.
*/ */
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
String rawDocs, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, rawDocs, tree, lineMap);
this.sym = sym; this.sym = sym;
} }
@ -70,7 +68,7 @@ public abstract class ExecutableMemberDocImpl
* Constructor. * Constructor.
*/ */
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) { public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
this(env, sym, null, null, null); this(env, sym, null);
} }
/** /**

View file

@ -25,6 +25,7 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import com.sun.source.util.TreePath;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import com.sun.javadoc.*; import com.sun.javadoc.*;
@ -61,9 +62,8 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
/** /**
* Constructor. * Constructor.
*/ */
public FieldDocImpl(DocEnv env, VarSymbol sym, public FieldDocImpl(DocEnv env, VarSymbol sym, TreePath treePath) {
String rawDocs, JCVariableDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, rawDocs, tree, lineMap);
this.sym = sym; this.sym = sym;
} }
@ -71,7 +71,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
* Constructor. * Constructor.
*/ */
public FieldDocImpl(DocEnv env, VarSymbol sym) { public FieldDocImpl(DocEnv env, VarSymbol sym) {
this(env, sym, null, null, null); this(env, sym, null);
} }
/** /**

View file

@ -25,13 +25,14 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.comp.Enter; import com.sun.tools.javac.comp.Enter;
import com.sun.tools.javac.tree.JCTree.*; 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.Context;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
@ -85,8 +86,7 @@ public class JavadocEnter extends Enter {
public void visitTopLevel(JCCompilationUnit tree) { public void visitTopLevel(JCCompilationUnit tree) {
super.visitTopLevel(tree); super.visitTopLevel(tree);
if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
String comment = TreeInfo.getCommentText(env, tree); docenv.makePackageDoc(tree.packge, docenv.getTreePath(tree));
docenv.makePackageDoc(tree.packge, comment, tree);
} }
} }
@ -95,9 +95,8 @@ public class JavadocEnter extends Enter {
super.visitClassDef(tree); super.visitClassDef(tree);
if (tree.sym == null) return; if (tree.sym == null) return;
if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) { if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) {
String comment = TreeInfo.getCommentText(env, tree);
ClassSymbol c = tree.sym; ClassSymbol c = tree.sym;
docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap); docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree));
} }
} }

View file

@ -25,14 +25,13 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.comp.MemberEnter;
import com.sun.tools.javac.tree.JCTree.*; 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.Context;
import com.sun.tools.javac.util.Position;
/** /**
* Javadoc's own memberEnter phase does a few things above and beyond that * Javadoc's own memberEnter phase does a few things above and beyond that
@ -73,14 +72,13 @@ public class JavadocMemberEnter extends MemberEnter {
super.visitMethodDef(tree); super.visitMethodDef(tree);
MethodSymbol meth = tree.sym; MethodSymbol meth = tree.sym;
if (meth == null || meth.kind != Kinds.MTH) return; if (meth == null || meth.kind != Kinds.MTH) return;
String docComment = TreeInfo.getCommentText(env, tree); TreePath treePath = docenv.getTreePath(env.toplevel, tree);
Position.LineMap lineMap = env.toplevel.lineMap;
if (meth.isConstructor()) if (meth.isConstructor())
docenv.makeConstructorDoc(meth, docComment, tree, lineMap); docenv.makeConstructorDoc(meth, treePath);
else if (isAnnotationTypeElement(meth)) else if (isAnnotationTypeElement(meth))
docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap); docenv.makeAnnotationTypeElementDoc(meth, treePath);
else else
docenv.makeMethodDoc(meth, docComment, tree, lineMap); docenv.makeMethodDoc(meth, treePath);
// release resources // release resources
tree.body = null; tree.body = null;
@ -92,9 +90,7 @@ public class JavadocMemberEnter extends MemberEnter {
if (tree.sym != null && if (tree.sym != null &&
tree.sym.kind == Kinds.VAR && tree.sym.kind == Kinds.VAR &&
!isParameter(tree.sym)) { !isParameter(tree.sym)) {
String docComment = TreeInfo.getCommentText(env, tree); docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, tree));
Position.LineMap lineMap = env.toplevel.lineMap;
docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
} }
} }

View file

@ -27,9 +27,8 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Symbol; 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. * Represents a member of a java class: field, constructor, or method.
@ -57,8 +56,8 @@ public abstract class MemberDocImpl
/** /**
* constructor. * constructor.
*/ */
public MemberDocImpl(DocEnv env, Symbol sym, String doc, JCTree tree, Position.LineMap lineMap) { public MemberDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
super(env, sym, doc, tree, lineMap); super(env, sym, treePath);
} }
/** /**

View file

@ -28,12 +28,10 @@ package com.sun.tools.javadoc;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type; 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; import static com.sun.tools.javac.code.TypeTag.CLASS;
/** /**
@ -62,9 +60,8 @@ public class MethodDocImpl
/** /**
* constructor. * constructor.
*/ */
public MethodDocImpl(DocEnv env, MethodSymbol sym, public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
String docComment, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, treePath);
super(env, sym, docComment, tree, lineMap);
} }
/** /**

View file

@ -31,6 +31,7 @@ import java.io.InputStream;
import javax.tools.FileObject; import javax.tools.FileObject;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Scope; import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
@ -75,17 +76,16 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
* Constructor * Constructor
*/ */
public PackageDocImpl(DocEnv env, PackageSymbol sym) { public PackageDocImpl(DocEnv env, PackageSymbol sym) {
this(env, sym, null, null); this(env, sym, null);
} }
/** /**
* Constructor * Constructor
*/ */
public PackageDocImpl(DocEnv env, PackageSymbol sym, public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
String documentation, JCTree tree) { super(env, treePath);
super(env, documentation);
this.sym = sym; this.sym = sym;
this.tree = (JCCompilationUnit) tree; this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
foundDoc = (documentation != null); foundDoc = (documentation != null);
} }
@ -93,8 +93,8 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
this.tree = (JCCompilationUnit) tree; this.tree = (JCCompilationUnit) tree;
} }
public void setRawCommentText(String rawDocumentation) { public void setTreePath(TreePath treePath) {
super.setRawCommentText(rawDocumentation); super.setTreePath(treePath);
checkDoc(); checkDoc();
} }

View file

@ -29,10 +29,12 @@ import java.lang.reflect.Modifier;
import java.text.CollationKey; import java.text.CollationKey;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
/** /**
@ -66,16 +68,20 @@ public abstract class ProgramElementDocImpl
// Cache for getModifiers(). // Cache for getModifiers().
private int modifiers = -1; private int modifiers = -1;
protected ProgramElementDocImpl(DocEnv env, Symbol sym, protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
String doc, JCTree tree, Position.LineMap lineMap) { super(env, treePath);
super(env, doc);
this.sym = sym; this.sym = sym;
this.tree = tree; if (treePath != null) {
this.lineMap = lineMap; tree = (JCTree) treePath.getLeaf();
lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
}
} }
void setTree(JCTree tree) { @Override
this.tree = tree; void setTreePath(TreePath treePath) {
super.setTreePath(treePath);
this.tree = (JCTree) treePath.getLeaf();
this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
} }
/** /**

View file

@ -331,7 +331,6 @@ public class RootDocImpl extends DocImpl implements RootDoc {
@Override @Override
protected String documentation() { protected String documentation() {
if (documentation == null) { if (documentation == null) {
int cnt = options.length();
JavaFileObject overviewPath = getOverviewPath(); JavaFileObject overviewPath = getOverviewPath();
if (overviewPath == null) { if (overviewPath == null) {
// no doc file to be had // no doc file to be had