langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java
changeset 14802 969e90f68ac5
parent 14543 43edeaf6d0a9
child 15354 52a04c670c05
equal deleted inserted replaced
14801:d66cab4ef397 14802:969e90f68ac5
    25 
    25 
    26 package com.sun.tools.javadoc;
    26 package com.sun.tools.javadoc;
    27 
    27 
    28 import java.lang.reflect.Modifier;
    28 import java.lang.reflect.Modifier;
    29 import java.util.*;
    29 import java.util.*;
       
    30 
    30 import javax.tools.JavaFileManager;
    31 import javax.tools.JavaFileManager;
    31 
    32 
    32 import com.sun.javadoc.*;
    33 import com.sun.javadoc.*;
    33 
    34 import com.sun.source.util.TreePath;
       
    35 import com.sun.tools.javac.api.JavacTrees;
    34 import com.sun.tools.javac.code.*;
    36 import com.sun.tools.javac.code.*;
    35 import com.sun.tools.javac.code.Symbol.*;
    37 import com.sun.tools.javac.code.Symbol.*;
    36 import com.sun.tools.javac.code.Type.ClassType;
    38 import com.sun.tools.javac.code.Type.ClassType;
    37 import com.sun.tools.javac.comp.Check;
    39 import com.sun.tools.javac.comp.Check;
       
    40 import com.sun.tools.javac.tree.JCTree;
    38 import com.sun.tools.javac.tree.JCTree.*;
    41 import com.sun.tools.javac.tree.JCTree.*;
    39 import com.sun.tools.javac.util.Context;
    42 import com.sun.tools.javac.util.Context;
    40 import com.sun.tools.javac.util.Names;
    43 import com.sun.tools.javac.util.Names;
    41 import com.sun.tools.javac.util.Position;
       
    42 
    44 
    43 /**
    45 /**
    44  * Holds the environment for a run of javadoc.
    46  * Holds the environment for a run of javadoc.
    45  * Holds only the information needed throughout the
    47  * Holds only the information needed throughout the
    46  * run and not the compiler info that could be GC'ed
    48  * run and not the compiler info that could be GC'ed
   102     Check chk;
   104     Check chk;
   103     Types types;
   105     Types types;
   104     JavaFileManager fileManager;
   106     JavaFileManager fileManager;
   105     Context context;
   107     Context context;
   106 
   108 
       
   109     WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
       
   110 
   107     /** Allow documenting from class files? */
   111     /** Allow documenting from class files? */
   108     boolean docClasses = false;
   112     boolean docClasses = false;
   109 
   113 
   110     /** Does the doclet only expect pre-1.5 doclet API? */
   114     /** Does the doclet only expect pre-1.5 doclet API? */
   111     protected boolean legacyDoclet = true;
   115     protected boolean legacyDoclet = true;
   538     }
   542     }
   539 
   543 
   540     /**
   544     /**
   541      * Create the PackageDoc (or a subtype) for a package symbol.
   545      * Create the PackageDoc (or a subtype) for a package symbol.
   542      */
   546      */
   543     void makePackageDoc(PackageSymbol pack, String docComment, JCCompilationUnit tree) {
   547     void makePackageDoc(PackageSymbol pack, TreePath treePath) {
   544         PackageDocImpl result = packageMap.get(pack);
   548         PackageDocImpl result = packageMap.get(pack);
   545         if (result != null) {
   549         if (result != null) {
   546             if (docComment != null) result.setRawCommentText(docComment);
   550             if (treePath != null) result.setTreePath(treePath);
   547             if (tree != null) result.setTree(tree);
   551         } else {
   548         } else {
   552             result = new PackageDocImpl(this, pack, treePath);
   549             result = new PackageDocImpl(this, pack, docComment, tree);
       
   550             packageMap.put(pack, result);
   553             packageMap.put(pack, result);
   551         }
   554         }
   552     }
   555     }
   553 
   556 
   554 
   557 
   570     }
   573     }
   571 
   574 
   572     /**
   575     /**
   573      * Create the ClassDoc (or a subtype) for a class symbol.
   576      * Create the ClassDoc (or a subtype) for a class symbol.
   574      */
   577      */
   575     protected void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) {
   578     protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
   576         ClassDocImpl result = classMap.get(clazz);
   579         ClassDocImpl result = classMap.get(clazz);
   577         if (result != null) {
   580         if (result != null) {
   578             if (docComment != null) result.setRawCommentText(docComment);
   581             if (treePath != null) result.setTreePath(treePath);
   579             if (tree != null) result.setTree(tree);
   582             return;
   580             return;
   583         }
   581         }
   584         if (isAnnotationType((JCClassDecl) treePath.getLeaf())) {   // flags of clazz may not yet be set
   582         if (isAnnotationType(tree)) {   // flags of clazz may not yet be set
   585             result = new AnnotationTypeDocImpl(this, clazz, treePath);
   583             result = new AnnotationTypeDocImpl(this, clazz, docComment, tree, lineMap);
   586         } else {
   584         } else {
   587             result = new ClassDocImpl(this, clazz, treePath);
   585             result = new ClassDocImpl(this, clazz, docComment, tree, lineMap);
       
   586         }
   588         }
   587         classMap.put(clazz, result);
   589         classMap.put(clazz, result);
   588     }
   590     }
   589 
   591 
   590     protected static boolean isAnnotationType(ClassSymbol clazz) {
   592     protected static boolean isAnnotationType(ClassSymbol clazz) {
   608         return result;
   610         return result;
   609     }
   611     }
   610     /**
   612     /**
   611      * Create a FieldDoc for a var symbol.
   613      * Create a FieldDoc for a var symbol.
   612      */
   614      */
   613     protected void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) {
   615     protected void makeFieldDoc(VarSymbol var, TreePath treePath) {
   614         FieldDocImpl result = fieldMap.get(var);
   616         FieldDocImpl result = fieldMap.get(var);
   615         if (result != null) {
   617         if (result != null) {
   616             if (docComment != null) result.setRawCommentText(docComment);
   618             if (treePath != null) result.setTreePath(treePath);
   617             if (tree != null) result.setTree(tree);
   619         } else {
   618         } else {
   620             result = new FieldDocImpl(this, var, treePath);
   619             result = new FieldDocImpl(this, var, docComment, tree, lineMap);
       
   620             fieldMap.put(var, result);
   621             fieldMap.put(var, result);
   621         }
   622         }
   622     }
   623     }
   623 
   624 
   624     protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap =
   625     protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap =
   625             new HashMap<MethodSymbol, ExecutableMemberDocImpl>();
   626             new HashMap<MethodSymbol, ExecutableMemberDocImpl>();
   626     /**
   627     /**
   627      * Create a MethodDoc for this MethodSymbol.
   628      * Create a MethodDoc for this MethodSymbol.
   628      * Should be called only on symbols representing methods.
   629      * Should be called only on symbols representing methods.
   629      */
   630      */
   630     protected void makeMethodDoc(MethodSymbol meth, String docComment,
   631     protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
   631                        JCMethodDecl tree, Position.LineMap lineMap) {
       
   632         MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
   632         MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
   633         if (result != null) {
   633         if (result != null) {
   634             if (docComment != null) result.setRawCommentText(docComment);
   634             if (treePath != null) result.setTreePath(treePath);
   635             if (tree != null) result.setTree(tree);
   635         } else {
   636         } else {
   636             result = new MethodDocImpl(this, meth, treePath);
   637             result = new MethodDocImpl(this, meth, docComment, tree, lineMap);
       
   638             methodMap.put(meth, result);
   637             methodMap.put(meth, result);
   639         }
   638         }
   640     }
   639     }
   641 
   640 
   642     /**
   641     /**
   654 
   653 
   655     /**
   654     /**
   656      * Create the ConstructorDoc for a MethodSymbol.
   655      * Create the ConstructorDoc for a MethodSymbol.
   657      * Should be called only on symbols representing constructors.
   656      * Should be called only on symbols representing constructors.
   658      */
   657      */
   659     protected void makeConstructorDoc(MethodSymbol meth, String docComment,
   658     protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
   660                             JCMethodDecl tree, Position.LineMap lineMap) {
       
   661         ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
   659         ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
   662         if (result != null) {
   660         if (result != null) {
   663             if (docComment != null) result.setRawCommentText(docComment);
   661             if (treePath != null) result.setTreePath(treePath);
   664             if (tree != null) result.setTree(tree);
   662         } else {
   665         } else {
   663             result = new ConstructorDocImpl(this, meth, treePath);
   666             result = new ConstructorDocImpl(this, meth, docComment, tree, lineMap);
       
   667             methodMap.put(meth, result);
   664             methodMap.put(meth, result);
   668         }
   665         }
   669     }
   666     }
   670 
   667 
   671     /**
   668     /**
   683 
   680 
   684     /**
   681     /**
   685      * Create the AnnotationTypeElementDoc for a MethodSymbol.
   682      * Create the AnnotationTypeElementDoc for a MethodSymbol.
   686      * Should be called only on symbols representing annotation type elements.
   683      * Should be called only on symbols representing annotation type elements.
   687      */
   684      */
   688     protected void makeAnnotationTypeElementDoc(MethodSymbol meth,
   685     protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
   689                                       String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
       
   690         AnnotationTypeElementDocImpl result =
   686         AnnotationTypeElementDocImpl result =
   691             (AnnotationTypeElementDocImpl)methodMap.get(meth);
   687             (AnnotationTypeElementDocImpl)methodMap.get(meth);
   692         if (result != null) {
   688         if (result != null) {
   693             if (docComment != null) result.setRawCommentText(docComment);
   689             if (treePath != null) result.setTreePath(treePath);
   694             if (tree != null) result.setTree(tree);
       
   695         } else {
   690         } else {
   696             result =
   691             result =
   697                 new AnnotationTypeElementDocImpl(this, meth, docComment, tree, lineMap);
   692                 new AnnotationTypeElementDocImpl(this, meth, treePath);
   698             methodMap.put(meth, result);
   693             methodMap.put(meth, result);
   699         }
   694         }
   700     }
   695     }
   701 
   696 
   702     /**
   697     /**
   726 //      ParameterizedTypeImpl result = parameterizedTypeMap.get(t);
   721 //      ParameterizedTypeImpl result = parameterizedTypeMap.get(t);
   727 //      if (result != null) return result;
   722 //      if (result != null) return result;
   728 //      result = new ParameterizedTypeImpl(this, t);
   723 //      result = new ParameterizedTypeImpl(this, t);
   729 //      parameterizedTypeMap.put(t, result);
   724 //      parameterizedTypeMap.put(t, result);
   730 //      return result;
   725 //      return result;
       
   726     }
       
   727 
       
   728     TreePath getTreePath(JCCompilationUnit tree) {
       
   729         TreePath p = treePaths.get(tree);
       
   730         if (p == null)
       
   731             treePaths.put(tree, p = new TreePath(tree));
       
   732         return p;
       
   733     }
       
   734 
       
   735     TreePath getTreePath(JCCompilationUnit toplevel, JCTree tree) {
       
   736         // don't bother to cache paths for classes and members
       
   737         return new TreePath(getTreePath(toplevel), tree);
   731     }
   738     }
   732 
   739 
   733     /**
   740     /**
   734      * Set the encoding.
   741      * Set the encoding.
   735      */
   742      */