langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java
changeset 14802 969e90f68ac5
parent 14260 727a84636f12
child 15354 52a04c670c05
equal deleted inserted replaced
14801:d66cab4ef397 14802:969e90f68ac5
    33 import java.util.regex.Pattern;
    33 import java.util.regex.Pattern;
    34 
    34 
    35 import javax.tools.FileObject;
    35 import javax.tools.FileObject;
    36 
    36 
    37 import com.sun.javadoc.*;
    37 import com.sun.javadoc.*;
       
    38 import com.sun.source.util.TreePath;
       
    39 import com.sun.tools.javac.tree.JCTree;
       
    40 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
    38 import com.sun.tools.javac.util.Position;
    41 import com.sun.tools.javac.util.Position;
    39 
    42 
    40 /**
    43 /**
    41  * abstract base class of all Doc classes.  Doc item's are representations
    44  * abstract base class of all Doc classes.  Doc item's are representations
    42  * of java language constructs (class, package, method,...) which have
    45  * of java language constructs (class, package, method,...) which have
    59      * Doc environment
    62      * Doc environment
    60      */
    63      */
    61     protected final DocEnv env;   //### Rename this everywhere to 'docenv' ?
    64     protected final DocEnv env;   //### Rename this everywhere to 'docenv' ?
    62 
    65 
    63     /**
    66     /**
       
    67      * Back pointer to the tree node for this doc item.
       
    68      * May be null if there is no associated tree.
       
    69      */
       
    70     protected TreePath treePath;
       
    71 
       
    72     /**
    64      *  The complex comment object, lazily initialized.
    73      *  The complex comment object, lazily initialized.
    65      */
    74      */
    66     private Comment comment;
    75     private Comment comment;
    67 
    76 
    68     /**
    77     /**
    86     private Tag[] inlineTags;
    95     private Tag[] inlineTags;
    87 
    96 
    88     /**
    97     /**
    89      * Constructor.
    98      * Constructor.
    90      */
    99      */
    91     DocImpl(DocEnv env, String documentation) {
   100     DocImpl(DocEnv env, TreePath treePath) {
    92         this.documentation = documentation;
   101         this.treePath = treePath;
       
   102         this.documentation = getCommentText(treePath);
    93         this.env = env;
   103         this.env = env;
       
   104     }
       
   105 
       
   106     private static String getCommentText(TreePath p) {
       
   107         if (p == null)
       
   108             return null;
       
   109 
       
   110         JCCompilationUnit topLevel = (JCCompilationUnit) p.getCompilationUnit();
       
   111         JCTree tree = (JCTree) p.getLeaf();
       
   112         return topLevel.docComments.getCommentText(tree);
    94     }
   113     }
    95 
   114 
    96     /**
   115     /**
    97      * So subclasses have the option to do lazy initialization of
   116      * So subclasses have the option to do lazy initialization of
    98      * "documentation" string.
   117      * "documentation" string.
   211      * Set the full unprocessed text of the comment.  Tags
   230      * Set the full unprocessed text of the comment.  Tags
   212      * are included as text.  Used mainly for store and retrieve
   231      * are included as text.  Used mainly for store and retrieve
   213      * operations like internalization.
   232      * operations like internalization.
   214      */
   233      */
   215     public void setRawCommentText(String rawDocumentation) {
   234     public void setRawCommentText(String rawDocumentation) {
       
   235         treePath = null;
   216         documentation = rawDocumentation;
   236         documentation = rawDocumentation;
       
   237         comment = null;
       
   238     }
       
   239 
       
   240     /**
       
   241      * Set the full unprocessed text of the comment and tree path.
       
   242      */
       
   243     void setTreePath(TreePath treePath) {
       
   244         this.treePath = treePath;
       
   245         documentation = getCommentText(treePath);
   217         comment = null;
   246         comment = null;
   218     }
   247     }
   219 
   248 
   220     /**
   249     /**
   221      * return a key for sorting.
   250      * return a key for sorting.