< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java

Print this page
rev 48841 : imported patch 8187950


  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.javadoc.internal.tool;
  27 
  28 
  29 import java.io.File;
  30 import java.util.ArrayList;
  31 import java.util.HashSet;
  32 import java.util.LinkedHashSet;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 import javax.tools.JavaFileObject;
  38 import javax.tools.StandardJavaFileManager;
  39 
  40 import com.sun.tools.javac.code.ClassFinder;

  41 import com.sun.tools.javac.code.Symbol.Completer;
  42 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  43 import com.sun.tools.javac.comp.Enter;
  44 import com.sun.tools.javac.tree.JCTree;
  45 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
  46 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  47 import com.sun.tools.javac.util.Abort;
  48 import com.sun.tools.javac.util.Context;
  49 import com.sun.tools.javac.util.ListBuffer;
  50 import com.sun.tools.javac.util.Position;
  51 import jdk.javadoc.doclet.DocletEnvironment;
  52 
  53 import static jdk.javadoc.internal.tool.Main.Result.*;
  54 
  55 /**
  56  *  This class could be the main entry point for Javadoc when Javadoc is used as a
  57  *  component in a larger software system. It provides operations to
  58  *  construct a new javadoc processor, and to run it on a set of source
  59  *  files.
  60  *
  61  *  <p><b>This is NOT part of any supported API.
  62  *  If you write code that depends on this, you do so at your own risk.
  63  *  This code and its internal interfaces are subject to change or
  64  *  deletion without notice.</b>
  65  *
  66  *  @author Neal Gafter
  67  */
  68 public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
  69     ToolEnvironment toolEnv;
  70 
  71     final Messager messager;
  72     final ClassFinder javadocFinder;

  73     final Enter javadocEnter;
  74     final Set<JavaFileObject> uniquefiles;
  75 
  76     /**
  77      * Construct a new JavaCompiler processor, using appropriately
  78      * extended phases of the underlying compiler.
  79      */
  80     protected JavadocTool(Context context) {
  81         super(context);
  82         messager = Messager.instance0(context);
  83         javadocFinder = JavadocClassFinder.instance(context);

  84         javadocEnter = JavadocEnter.instance(context);
  85         uniquefiles = new HashSet<>();
  86     }
  87 
  88     /**
  89      * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler.
  90      */
  91     @Override
  92     protected boolean keepComments() {
  93         return true;
  94     }
  95 
  96     /**
  97      *  Construct a new javadoc tool.
  98      */
  99     public static JavadocTool make0(Context context) {
 100         Messager messager = null;
 101         try {
 102             // force the use of Javadoc's class finder
 103             JavadocClassFinder.preRegister(context);


 191 
 192             // Parse the files in the packages and subpackages to be documented
 193             ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
 194             parse(etable.getFilesToParse(), packageTrees, false);
 195             modules.enter(packageTrees.toList(), null);
 196 
 197             if (messager.hasErrors()) {
 198                 return null;
 199             }
 200 
 201             // Enter symbols for all files
 202             toolEnv.notice("main.Building_tree");
 203             javadocEnter.main(classTrees.toList().appendList(packageTrees));
 204 
 205             if (messager.hasErrors()) {
 206                 return null;
 207             }
 208 
 209             etable.setClassDeclList(listClasses(classTrees.toList()));
 210 

 211             etable.analyze();
 212         } catch (CompletionFailure cf) {
 213             throw new ToolException(ABNORMAL, cf.getMessage(), cf);
 214         } catch (Abort abort) {
 215             if (messager.hasErrors()) {
 216                 // presumably a message has been emitted, keep silent
 217                 throw new ToolException(ABNORMAL, "", abort);
 218             } else {
 219                 String text = messager.getText("main.internal.error");
 220                 Throwable t = abort.getCause() == null ? abort : abort.getCause();
 221                 throw new ToolException(ABNORMAL, text, t);
 222             }
 223         }
 224 
 225         if (messager.hasErrors())
 226             return null;
 227 
 228         toolEnv.docEnv = new DocEnvImpl(toolEnv, etable);
 229         return toolEnv.docEnv;
 230     }




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.javadoc.internal.tool;
  27 
  28 
  29 import java.io.File;
  30 import java.util.ArrayList;
  31 import java.util.HashSet;
  32 import java.util.LinkedHashSet;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 import javax.tools.JavaFileObject;
  38 import javax.tools.StandardJavaFileManager;
  39 
  40 import com.sun.tools.javac.code.ClassFinder;
  41 import com.sun.tools.javac.code.DeferredCompletionFailureHandler;
  42 import com.sun.tools.javac.code.Symbol.Completer;
  43 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  44 import com.sun.tools.javac.comp.Enter;
  45 import com.sun.tools.javac.tree.JCTree;
  46 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
  47 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  48 import com.sun.tools.javac.util.Abort;
  49 import com.sun.tools.javac.util.Context;
  50 import com.sun.tools.javac.util.ListBuffer;
  51 import com.sun.tools.javac.util.Position;
  52 import jdk.javadoc.doclet.DocletEnvironment;
  53 
  54 import static jdk.javadoc.internal.tool.Main.Result.*;
  55 
  56 /**
  57  *  This class could be the main entry point for Javadoc when Javadoc is used as a
  58  *  component in a larger software system. It provides operations to
  59  *  construct a new javadoc processor, and to run it on a set of source
  60  *  files.
  61  *
  62  *  <p><b>This is NOT part of any supported API.
  63  *  If you write code that depends on this, you do so at your own risk.
  64  *  This code and its internal interfaces are subject to change or
  65  *  deletion without notice.</b>
  66  *
  67  *  @author Neal Gafter
  68  */
  69 public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
  70     ToolEnvironment toolEnv;
  71 
  72     final Messager messager;
  73     final ClassFinder javadocFinder;
  74     final DeferredCompletionFailureHandler dcfh;
  75     final Enter javadocEnter;
  76     final Set<JavaFileObject> uniquefiles;
  77 
  78     /**
  79      * Construct a new JavaCompiler processor, using appropriately
  80      * extended phases of the underlying compiler.
  81      */
  82     protected JavadocTool(Context context) {
  83         super(context);
  84         messager = Messager.instance0(context);
  85         javadocFinder = JavadocClassFinder.instance(context);
  86         dcfh = DeferredCompletionFailureHandler.instance(context);
  87         javadocEnter = JavadocEnter.instance(context);
  88         uniquefiles = new HashSet<>();
  89     }
  90 
  91     /**
  92      * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler.
  93      */
  94     @Override
  95     protected boolean keepComments() {
  96         return true;
  97     }
  98 
  99     /**
 100      *  Construct a new javadoc tool.
 101      */
 102     public static JavadocTool make0(Context context) {
 103         Messager messager = null;
 104         try {
 105             // force the use of Javadoc's class finder
 106             JavadocClassFinder.preRegister(context);


 194 
 195             // Parse the files in the packages and subpackages to be documented
 196             ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
 197             parse(etable.getFilesToParse(), packageTrees, false);
 198             modules.enter(packageTrees.toList(), null);
 199 
 200             if (messager.hasErrors()) {
 201                 return null;
 202             }
 203 
 204             // Enter symbols for all files
 205             toolEnv.notice("main.Building_tree");
 206             javadocEnter.main(classTrees.toList().appendList(packageTrees));
 207 
 208             if (messager.hasErrors()) {
 209                 return null;
 210             }
 211 
 212             etable.setClassDeclList(listClasses(classTrees.toList()));
 213 
 214             dcfh.setHandler(dcfh.userCodeHandler);
 215             etable.analyze();
 216         } catch (CompletionFailure cf) {
 217             throw new ToolException(ABNORMAL, cf.getMessage(), cf);
 218         } catch (Abort abort) {
 219             if (messager.hasErrors()) {
 220                 // presumably a message has been emitted, keep silent
 221                 throw new ToolException(ABNORMAL, "", abort);
 222             } else {
 223                 String text = messager.getText("main.internal.error");
 224                 Throwable t = abort.getCause() == null ? abort : abort.getCause();
 225                 throw new ToolException(ABNORMAL, text, t);
 226             }
 227         }
 228 
 229         if (messager.hasErrors())
 230             return null;
 231 
 232         toolEnv.docEnv = new DocEnvImpl(toolEnv, etable);
 233         return toolEnv.docEnv;
 234     }


< prev index next >