8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
Reviewed-by: bpatel, jjg
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -62,7 +62,7 @@
return htmlDoclet.sourceVersion();
}
- public boolean run(DocletEnvironment root) {
- return htmlDoclet.run(root);
+ public boolean run(DocletEnvironment docEnv) {
+ return htmlDoclet.run(docEnv);
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -178,7 +178,7 @@
*/
public static void generate(ConfigurationImpl configuration, ClassTree classtree) {
ClassUseMapper mapper = new ClassUseMapper(configuration, classtree);
- for (TypeElement aClass : configuration.root.getIncludedClasses()) {
+ for (TypeElement aClass : configuration.docEnv.getIncludedClasses()) {
// If -nodeprecated option is set and the containing package is marked
// as deprecated, do not generate the class-use page. We will still generate
// the class-use page if the class is marked as deprecated but the containing
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java Tue Jun 28 16:43:41 2016 -0700
@@ -208,7 +208,7 @@
bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
HtmlTree div = new HtmlTree(HtmlTag.DIV);
div.addStyle(HtmlStyle.header);
- ModuleElement mdle = configuration.root.getElementUtils().getModuleOf(typeElement);
+ ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(typeElement);
if (mdle != null && !mdle.isUnnamed()) {
Content classModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInClass, moduleLabel);
Content moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classModuleLabel);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConfigurationImpl.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConfigurationImpl.java Tue Jun 28 16:43:41 2016 -0700
@@ -360,10 +360,10 @@
if (!validateOptions()) {
return false;
}
- if (!root.getSpecifiedElements().isEmpty()) {
+ if (!docEnv.getSpecifiedElements().isEmpty()) {
Map<String, PackageElement> map = new HashMap<>();
PackageElement pkg;
- List<TypeElement> classes = new ArrayList<>(root.getIncludedClasses());
+ List<TypeElement> classes = new ArrayList<>(docEnv.getIncludedClasses());
for (TypeElement aClass : classes) {
pkg = utils.containingPackage(aClass);
if (!map.containsKey(utils.getPackageName(pkg))) {
@@ -372,7 +372,7 @@
}
}
setCreateOverview();
- setTopFile(root);
+ setTopFile(docEnv);
workArounds.initDocLint(doclintOpts.values(), tagletManager.getCustomTagNames(),
Utils.toLowerCase(htmlVersion.name()));
return true;
@@ -441,8 +441,8 @@
return null;
}
- protected boolean checkForDeprecation(DocletEnvironment root) {
- for (TypeElement te : root.getIncludedClasses()) {
+ protected boolean checkForDeprecation(DocletEnvironment docEnv) {
+ for (TypeElement te : docEnv.getIncludedClasses()) {
if (isGeneratedDoc(te)) {
return true;
}
@@ -496,7 +496,7 @@
*/
@Override
public JavaFileManager getFileManager() {
- return root.getJavaFileManager();
+ return docEnv.getJavaFileManager();
}
@Override
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java Tue Jun 28 16:43:41 2016 -0700
@@ -82,12 +82,12 @@
/**
* The "start" method as required by Javadoc.
*
- * @param root the root of the documentation tree.
+ * @param docEnv the root of the documentation tree.
* @see jdk.doclet.DocletEnvironment
* @return true if the doclet ran without encountering any errors.
*/
- public boolean run(DocletEnvironment root) {
- return startDoclet(root);
+ public boolean run(DocletEnvironment docEnv) {
+ return startDoclet(docEnv);
}
/**
@@ -109,12 +109,12 @@
*
* @see jdk.doclet.RootDoc
*/
- protected void generateOtherFiles(DocletEnvironment root, ClassTree classtree)
+ protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree)
throws Exception {
- super.generateOtherFiles(root, classtree);
+ super.generateOtherFiles(docEnv, classtree);
if (configuration.linksource) {
SourceToHTMLConverter.convertRoot(configuration,
- root, DocPaths.SOURCE_OUTPUT);
+ docEnv, DocPaths.SOURCE_OUTPUT);
}
if (configuration.topFile.isEmpty()) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageFrameWriter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageFrameWriter.java Tue Jun 28 16:43:41 2016 -0700
@@ -86,7 +86,7 @@
this.packageElement = packageElement;
if (utils.getSpecifiedPackages().isEmpty()) {
documentedClasses = new TreeSet<>(utils.makeGeneralPurposeComparator());
- documentedClasses.addAll(configuration.root.getIncludedClasses());
+ documentedClasses.addAll(configuration.docEnv.getIncludedClasses());
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java Tue Jun 28 16:43:41 2016 -0700
@@ -59,7 +59,7 @@
/**
* Root of the program structure. Used for "overview" documentation.
*/
- private DocletEnvironment root;
+ private DocletEnvironment docEnv;
/**
* Map representing the group of packages as specified on the command line.
@@ -87,7 +87,7 @@
*/
public PackageIndexWriter(ConfigurationImpl configuration, DocPath filename) throws IOException {
super(configuration, filename);
- this.root = configuration.root;
+ this.docEnv = configuration.docEnv;
groupPackageMap = configuration.group.groupPackages(packages);
groupList = configuration.group.getGroupList();
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java Tue Jun 28 16:43:41 2016 -0700
@@ -125,7 +125,7 @@
}
HtmlTree div = new HtmlTree(HtmlTag.DIV);
div.addStyle(HtmlStyle.header);
- ModuleElement mdle = configuration.root.getElementUtils().getModuleOf(packageElement);
+ ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(packageElement);
if (mdle != null && !mdle.isUnnamed()) {
Content classModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInClass, moduleLabel);
Content moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classModuleLabel);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -70,7 +70,7 @@
public SerializedFormWriterImpl(ConfigurationImpl configuration)
throws IOException {
super(configuration, DocPaths.SERIALIZED_FORM);
- visibleClasses = configuration.root.getIncludedClasses();
+ visibleClasses = configuration.docEnv.getIncludedClasses();
}
/**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Tue Jun 28 16:43:41 2016 -0700
@@ -75,7 +75,7 @@
private final ConfigurationImpl configuration;
private final Utils utils;
- private final DocletEnvironment rootDoc;
+ private final DocletEnvironment docEnv;
private DocPath outputdir;
@@ -89,7 +89,7 @@
DocPath outputdir) {
this.configuration = configuration;
this.utils = configuration.utils;
- this.rootDoc = rd;
+ this.docEnv = rd;
this.outputdir = outputdir;
}
@@ -97,16 +97,16 @@
* Translate the TypeElements in the given DocletEnvironment to HTML representation.
*
* @param configuration the configuration.
- * @param root the DocletEnvironment to convert.
+ * @param docEnv the DocletEnvironment to convert.
* @param outputdir the name of the directory to output to.
*/
- public static void convertRoot(ConfigurationImpl configuration, DocletEnvironment root,
+ public static void convertRoot(ConfigurationImpl configuration, DocletEnvironment docEnv,
DocPath outputdir) {
- new SourceToHTMLConverter(configuration, root, outputdir).generate();
+ new SourceToHTMLConverter(configuration, docEnv, outputdir).generate();
}
void generate() {
- if (rootDoc == null || outputdir == null) {
+ if (docEnv == null || outputdir == null) {
return;
}
for (PackageElement pkg : utils.getSpecifiedPackages()) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java Tue Jun 28 16:43:41 2016 -0700
@@ -91,7 +91,7 @@
*/
public boolean startDoclet(DocletEnvironment root) {
configuration = configuration();
- configuration.root = root;
+ configuration.docEnv = root;
configuration.cmtUtils = new CommentUtils(configuration);
configuration.utils = new Utils(configuration);
utils = configuration.utils;
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java Tue Jun 28 16:43:41 2016 -0700
@@ -66,9 +66,9 @@
protected CommentUtils(Configuration configuration) {
this.configuration = configuration;
- trees = configuration.root.getDocTrees();
+ trees = configuration.docEnv.getDocTrees();
treeFactory = trees.getDocTreeFactory();
- elementUtils = configuration.root.getElementUtils();
+ elementUtils = configuration.docEnv.getElementUtils();
}
public List<? extends DocTree> makePropertyDescriptionTree(List<? extends DocTree> content) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Tue Jun 28 16:43:41 2016 -0700
@@ -179,7 +179,7 @@
/**
* The Root of the generated Program Structure from the Doclet API.
*/
- public DocletEnvironment root;
+ public DocletEnvironment docEnv;
/**
* An utility class for commonly used helpers
@@ -365,7 +365,7 @@
metakeywords = new MetaKeywords(this);
optionsProcessed = new ArrayList<>();
groups = new ArrayList<>(0);
- overviewElement = new OverviewElement(root);
+ overviewElement = new OverviewElement(docEnv);
}
/**
@@ -388,7 +388,7 @@
// Build the modules structure used by the doclet
modulePackages = new TreeMap<>(utils.makeModuleComparator());
for (PackageElement p: packages) {
- ModuleElement mdle = root.getElementUtils().getModuleOf(p);
+ ModuleElement mdle = docEnv.getElementUtils().getModuleOf(p);
if (mdle != null && !mdle.isUnnamed()) {
Set<PackageElement> s = modulePackages.get(mdle);
if (s == null)
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Tue Jun 28 16:43:41 2016 -0700
@@ -65,8 +65,8 @@
import com.sun.tools.javac.util.Names;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
-import jdk.javadoc.internal.tool.DocEnv;
-import jdk.javadoc.internal.tool.RootDocImpl;
+import jdk.javadoc.internal.tool.ToolEnvironment;
+import jdk.javadoc.internal.tool.DocEnvImpl;
import static com.sun.tools.javac.code.Kinds.Kind.*;
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
@@ -87,7 +87,7 @@
public class WorkArounds {
public final Configuration configuration;
- public final DocEnv env;
+ public final ToolEnvironment toolEnv;
public final Utils utils;
private DocLint doclint;
@@ -95,7 +95,7 @@
public WorkArounds(Configuration configuration) {
this.configuration = configuration;
this.utils = this.configuration.utils;
- this.env = ((RootDocImpl)this.configuration.root).env;
+ this.toolEnv = ((DocEnvImpl)this.configuration.docEnv).toolEnv;
}
Map<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>();
@@ -135,7 +135,7 @@
doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion);
- JavacTask t = BasicJavacTask.instance(env.context);
+ JavacTask t = BasicJavacTask.instance(toolEnv.context);
doclint = new DocLint();
// standard doclet normally generates H1, H2
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
@@ -151,7 +151,7 @@
// so we use javac directly, investigate why jx.l.m is not cutting it.
public List<TypeMirror> interfaceTypesOf(TypeMirror type) {
com.sun.tools.javac.util.List<com.sun.tools.javac.code.Type> interfaces =
- ((RootDocImpl)configuration.root).env.getTypes().interfaces((com.sun.tools.javac.code.Type)type);
+ ((DocEnvImpl)configuration.docEnv).toolEnv.getTypes().interfaces((com.sun.tools.javac.code.Type)type);
if (interfaces.isEmpty()) {
return Collections.emptyList();
}
@@ -171,7 +171,7 @@
if (!utils.getDeprecatedTrees(e).isEmpty()) {
return true;
}
- JavacTypes jctypes = ((RootDocImpl)configuration.root).env.typeutils;
+ JavacTypes jctypes = ((DocEnvImpl)configuration.docEnv).toolEnv.typeutils;
TypeMirror deprecatedType = utils.getDeprecatedType();
for (AnnotationMirror anno : e.getAnnotationMirrors()) {
if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), deprecatedType))
@@ -187,7 +187,7 @@
// TODO: implement using jx.l.model
public boolean isVisible(TypeElement te) {
- return env.isVisible((ClassSymbol)te);
+ return toolEnv.isVisible((ClassSymbol)te);
}
// TODO: fix the caller
@@ -197,13 +197,13 @@
//TODO: DocTrees: Trees.getPath(Element e) is slow a factor 4-5 times.
public Map<Element, TreePath> getElementToTreePath() {
- return env.elementToTreePath;
+ return toolEnv.elementToTreePath;
}
// TODO: needs to ported to jx.l.m.
public TypeElement searchClass(TypeElement klass, String className) {
// search by qualified name first
- TypeElement te = configuration.root.getElementUtils().getTypeElement(className);
+ TypeElement te = configuration.docEnv.getElementUtils().getTypeElement(className);
if (te != null) {
return te;
}
@@ -233,7 +233,7 @@
if (tsym.sourcefile != null) {
//### This information is available only for source classes.
- Env<AttrContext> compenv = env.getEnv(tsym);
+ Env<AttrContext> compenv = toolEnv.getEnv(tsym);
if (compenv == null) {
return null;
}
@@ -271,12 +271,12 @@
}
MethodSymbol sym = (MethodSymbol)method;
ClassSymbol origin = (ClassSymbol) sym.owner;
- for (com.sun.tools.javac.code.Type t = env.getTypes().supertype(origin.type);
+ for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type);
t.hasTag(com.sun.tools.javac.code.TypeTag.CLASS);
- t = env.getTypes().supertype(t)) {
+ t = toolEnv.getTypes().supertype(t)) {
ClassSymbol c = (ClassSymbol) t.tsym;
for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) {
- if (sym.overrides(sym2, origin, env.getTypes(), true)) {
+ if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) {
return t;
}
}
@@ -286,7 +286,7 @@
// TODO: investigate and reimplement without javac dependencies.
public boolean shouldDocument(Element e) {
- return env.shouldDocument(e);
+ return toolEnv.shouldDocument(e);
}
//------------------Start of Serializable Implementation---------------------//
@@ -295,7 +295,7 @@
public SortedSet<VariableElement> getSerializableFields(Utils utils, TypeElement klass) {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.root.getElementUtils(), klass);
+ sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.fields;
@@ -304,7 +304,7 @@
public SortedSet<ExecutableElement> getSerializationMethods(Utils utils, TypeElement klass) {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.root.getElementUtils(), klass);
+ sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.methods;
@@ -316,7 +316,7 @@
} else {
NewSerializedForm sf = serializedForms.get(klass);
if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.root.getElementUtils(), klass);
+ sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
serializedForms.put(klass, sf);
}
return sf.definesSerializableFields;
@@ -533,7 +533,7 @@
// TODO: this is a fast way to get the JavaFileObject for
// a package.html file, however we need to eliminate this.
public JavaFileObject getJavaFileObject(PackageElement pe) {
- return env.pkgToJavaFOMap.get(pe);
+ return toolEnv.pkgToJavaFOMap.get(pe);
}
// TODO: we need to eliminate this, as it is hacky.
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java Tue Jun 28 16:43:41 2016 -0700
@@ -125,7 +125,7 @@
*/
public void build() throws IOException {
SortedSet<TypeElement> rootclasses = new TreeSet<>(utils.makeGeneralPurposeComparator());
- rootclasses.addAll(configuration.root.getIncludedClasses());
+ rootclasses.addAll(configuration.docEnv.getIncludedClasses());
if (!serialClassFoundToDocument(rootclasses)) {
//Nothing to document.
return;
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java Tue Jun 28 16:43:41 2016 -0700
@@ -161,7 +161,7 @@
memberName = sigValues[0];
} else {
//Case 3: @value in different class.
- Elements elements = config.root.getElementUtils();
+ Elements elements = config.docEnv.getElementUtils();
te = elements.getTypeElement(sigValues[0]);
memberName = sigValues[1];
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassTree.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassTree.java Tue Jun 28 16:43:41 2016 -0700
@@ -113,7 +113,7 @@
baseEnums = new TreeSet<>(comparator);
baseClasses = new TreeSet<>(comparator);
baseInterfaces = new TreeSet<>(comparator);
- buildTree(configuration.root.getIncludedClasses());
+ buildTree(configuration.docEnv.getIncludedClasses());
}
/**
@@ -130,7 +130,7 @@
baseEnums = new TreeSet<>(comparator);
baseClasses = new TreeSet<>(comparator);
baseInterfaces = new TreeSet<>(comparator);
- buildTree(configuration.root.getIncludedClasses());
+ buildTree(configuration.docEnv.getIncludedClasses());
}
/**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java Tue Jun 28 16:43:41 2016 -0700
@@ -187,15 +187,15 @@
*/
public final Map<TypeElement, List<VariableElement>> annotationToField = new HashMap<>();
- private final DocletEnvironment root;
+ private final DocletEnvironment docEnv;
private final Elements elementUtils;
private final Types typeUtils;
private final Utils utils;
public ClassUseMapper(ConfigurationImpl configuration, ClassTree classtree) {
- root = configuration.root;
- elementUtils = root.getElementUtils();
- typeUtils = root.getTypeUtils();
+ docEnv = configuration.docEnv;
+ elementUtils = docEnv.getElementUtils();
+ typeUtils = docEnv.getTypeUtils();
utils = configuration.utils;
this.classtree = classtree;
classToPackage = new TreeMap<>(utils.makeClassUseComparator());
@@ -208,7 +208,7 @@
implementingClasses(intfc);
}
// Map methods, fields, constructors using a class.
- Set<TypeElement> classes = root.getIncludedClasses();
+ Set<TypeElement> classes = docEnv.getIncludedClasses();
for (TypeElement aClass : classes) {
PackageElement pkg = elementUtils.getPackageOf(aClass);
mapAnnotations(classToPackageAnnotations, pkg, pkg);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java Tue Jun 28 16:43:41 2016 -0700
@@ -148,7 +148,7 @@
if (symbol == null) {
return null;
}
- return c.root.getTypeUtils().asElement(symbol);
+ return c.docEnv.getTypeUtils().asElement(symbol);
}
// case A: the element contains no comments associated and
// the comments need to be copied from ancestor
@@ -172,7 +172,7 @@
}
return null;
}
- DocTrees doctrees = c.root.getDocTrees();
+ DocTrees doctrees = c.docEnv.getDocTrees();
return doctrees.getElement(docTreePath);
}
@@ -419,7 +419,7 @@
}
public List<? extends DocTree> getFirstSentenceTrees(Configuration c, List<? extends DocTree> body) {
- List<DocTree> firstSentence = c.root.getDocTrees().getFirstSentence(body);
+ List<DocTree> firstSentence = c.docEnv.getDocTrees().getFirstSentence(body);
return firstSentence;
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DeprecatedAPIListBuilder.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DeprecatedAPIListBuilder.java Tue Jun 28 16:43:41 2016 -0700
@@ -96,7 +96,7 @@
}
}
deprecatedMap.put(DeprElementKind.PACKAGE, pset);
- for (Element e : configuration.root.getIncludedClasses()) {
+ for (Element e : configuration.docEnv.getIncludedClasses()) {
TypeElement te = (TypeElement)e;
SortedSet<Element> eset;
if (utils.isDeprecated(e)) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java Tue Jun 28 16:43:41 2016 -0700
@@ -110,7 +110,7 @@
comparator = classesOnly
? utils.makeAllClassesComparator()
: utils.makeIndexUseComparator();
- buildIndexMap(configuration.root);
+ buildIndexMap(configuration.docEnv);
}
/**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -70,7 +70,7 @@
PackageListWriter packgen;
try {
packgen = new PackageListWriter(configuration);
- packgen.generatePackageListFile(configuration.root);
+ packgen.generatePackageListFile(configuration.docEnv);
packgen.close();
} catch (IOException exc) {
configuration.message.error("doclet.exception_encountered",
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Tue Jun 28 16:43:41 2016 -0700
@@ -108,9 +108,9 @@
public Utils(Configuration c) {
configuration = c;
- elementUtils = c.root.getElementUtils();
- typeUtils = c.root.getTypeUtils();
- docTrees = c.root.getDocTrees();
+ elementUtils = c.docEnv.getElementUtils();
+ typeUtils = c.docEnv.getTypeUtils();
+ docTrees = c.docEnv.getDocTrees();
}
// our own little symbol table
@@ -530,7 +530,7 @@
public boolean isFunctionalInterface(AnnotationMirror amirror) {
return amirror.getAnnotationType().equals(getFunctionalInterface()) &&
- configuration.root.getSourceVersion()
+ configuration.docEnv.getSourceVersion()
.compareTo(SourceVersion.RELEASE_8) >= 0;
}
@@ -2223,9 +2223,9 @@
private void initSpecifiedElements() {
specifiedClasses = new LinkedHashSet<>(
- ElementFilter.typesIn(configuration.root.getSpecifiedElements()));
+ ElementFilter.typesIn(configuration.docEnv.getSpecifiedElements()));
specifiedPackages = new LinkedHashSet<>(
- ElementFilter.packagesIn(configuration.root.getSpecifiedElements()));
+ ElementFilter.packagesIn(configuration.docEnv.getSpecifiedElements()));
}
public Set<TypeElement> getSpecifiedClasses() {
@@ -2571,7 +2571,7 @@
}
public boolean isIncluded(Element e) {
- return configuration.root.isIncluded(e);
+ return configuration.docEnv.isIncluded(e);
}
/**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnv.java Tue Jun 28 15:29:20 2016 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,848 +0,0 @@
-/*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.javadoc.internal.tool;
-
-
-import java.lang.reflect.Modifier;
-import java.util.*;
-
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.VariableElement;
-import javax.lang.model.util.Elements;
-import javax.lang.model.util.SimpleElementVisitor9;
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-
-import com.sun.source.util.DocTrees;
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.api.JavacTrees;
-import com.sun.tools.javac.code.ClassFinder;
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.Kinds.Kind;
-import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Symbol.CompletionFailure;
-import com.sun.tools.javac.code.Symbol.MethodSymbol;
-import com.sun.tools.javac.code.Symbol.ModuleSymbol;
-import com.sun.tools.javac.code.Symbol.PackageSymbol;
-import com.sun.tools.javac.code.Symbol.VarSymbol;
-import com.sun.tools.javac.code.Symtab;
-import com.sun.tools.javac.comp.AttrContext;
-import com.sun.tools.javac.comp.Check;
-import com.sun.tools.javac.comp.Enter;
-import com.sun.tools.javac.comp.Env;
-import com.sun.tools.javac.file.JavacFileManager;
-import com.sun.tools.javac.model.JavacElements;
-import com.sun.tools.javac.model.JavacTypes;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
-import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-import com.sun.tools.javac.tree.JCTree.JCPackageDecl;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.Convert;
-import com.sun.tools.javac.util.DefinedBy;
-import com.sun.tools.javac.util.DefinedBy.Api;
-import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.Names;
-
-import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
-
-/**
- * Holds the environment for a run of javadoc.
- * Holds only the information needed throughout the
- * run and not the compiler info that could be GC'ed
- * or ported.
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own risk.
- * This code and its internal interfaces are subject to change or
- * deletion without notice.</b>
- *
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (generics)
- */
-public class DocEnv {
- protected static final Context.Key<DocEnv> docEnvKey = new Context.Key<>();
-
- public static DocEnv instance(Context context) {
- DocEnv instance = context.get(docEnvKey);
- if (instance == null)
- instance = new DocEnv(context);
- return instance;
- }
-
- private final Messager messager;
-
- /** Predefined symbols known to the compiler. */
- public final Symtab syms;
-
- /** Referenced directly in RootDocImpl. */
- private final ClassFinder finder;
-
- /** Javadoc's own version of the compiler's enter phase. */
- final Enter enter;
-
- /** The name table. */
- private Names names;
-
- /** The encoding name. */
- private String encoding;
-
- final Symbol externalizableSym;
-
- /** Access filter (public, protected, ...). */
- protected ModifierFilter filter;
-
- /**
- * True if we do not want to print any notifications at all.
- */
- boolean quiet = false;
-
- Check chk;
- com.sun.tools.javac.code.Types types;
- JavaFileManager fileManager;
- public final Context context;
-
- WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<>();
-
- public final HashMap<PackageElement, JavaFileObject> pkgToJavaFOMap = new HashMap<>();
-
- /** Allow documenting from class files? */
- boolean docClasses = false;
-
- /**
- * The source language version.
- */
- public final Source source;
-
- public final Elements elements;
-
- public final JavacTypes typeutils;
-
- protected RootDocImpl root;
-
- public final DocTrees docTrees;
-
- public final Map<Element, TreePath> elementToTreePath;
-
- /**
- * Constructor
- *
- * @param context Context for this javadoc instance.
- */
- protected DocEnv(Context context) {
- context.put(docEnvKey, this);
- this.context = context;
-
- messager = Messager.instance0(context);
- syms = Symtab.instance(context);
- finder = JavadocClassFinder.instance(context);
- enter = JavadocEnter.instance(context);
- names = Names.instance(context);
- externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
- chk = Check.instance(context);
- types = com.sun.tools.javac.code.Types.instance(context);
- fileManager = context.get(JavaFileManager.class);
- if (fileManager instanceof JavacFileManager) {
- ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
- }
- docTrees = JavacTrees.instance(context);
- source = Source.instance(context);
- elements = JavacElements.instance(context);
- typeutils = JavacTypes.instance(context);
- elementToTreePath = new HashMap<>();
- }
-
- public void intialize(String encoding,
- String showAccess,
- String overviewpath,
- List<String> javaNames,
- Iterable<? extends JavaFileObject> fileObjects,
- List<String> subPackages,
- List<String> excludedPackages,
- boolean docClasses,
- boolean quiet) {
- this.filter = ModifierFilter.getModifierFilter(showAccess);
- this.quiet = quiet;
-
- this.setEncoding(encoding);
- this.docClasses = docClasses;
- }
-
- /**
- * Load a class by qualified name.
- */
- public TypeElement loadClass(String name) {
- try {
- Name nameImpl = names.fromString(name);
- ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
- ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
- return c;
- } catch (CompletionFailure ex) {
- chk.completionError(null, ex);
- return null;
- }
- }
-
- private boolean isSynthetic(long flags) {
- return (flags & Flags.SYNTHETIC) != 0;
- }
-
- private boolean isSynthetic(Symbol sym) {
- return isSynthetic(sym.flags_field);
- }
-
- SimpleElementVisitor9<Boolean, Void> shouldDocumentVisitor = null;
- public boolean shouldDocument(Element e) {
- if (shouldDocumentVisitor == null) {
- shouldDocumentVisitor = new SimpleElementVisitor9<Boolean, Void>() {
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitType(TypeElement e, Void p) {
- return shouldDocument((ClassSymbol)e);
- }
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitVariable(VariableElement e, Void p) {
- return shouldDocument((VarSymbol)e);
- }
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitExecutable(ExecutableElement e, Void p) {
- return shouldDocument((MethodSymbol)e);
- }
- };
- }
- return shouldDocumentVisitor.visit(e);
- }
-
- /** Check whether this member should be documented. */
- public boolean shouldDocument(VarSymbol sym) {
- long mod = sym.flags();
- if (isSynthetic(mod)) {
- return false;
- }
- return filter.checkModifier(translateModifiers(mod));
- }
-
- /** Check whether this member should be documented. */
- public boolean shouldDocument(MethodSymbol sym) {
- long mod = sym.flags();
- if (isSynthetic(mod)) {
- return false;
- }
- return filter.checkModifier(translateModifiers(mod));
- }
-
- void setElementToTreePath(Element e, TreePath tree) {
- if (e == null || tree == null)
- return;
- elementToTreePath.put(e, tree);
- }
-
- private boolean hasLeaf(ClassSymbol sym) {
- TreePath path = elementToTreePath.get(sym);
- if (path == null)
- return false;
- return path.getLeaf() != null;
- }
-
- /** check whether this class should be documented. */
- public boolean shouldDocument(ClassSymbol sym) {
- return
- !isSynthetic(sym.flags_field) && // no synthetics
- (docClasses || hasLeaf(sym)) &&
- isVisible(sym);
- }
-
- //### Comment below is inaccurate wrt modifier filter testing
- /**
- * Check the visibility if this is an nested class.
- * if this is not a nested class, return true.
- * if this is an static visible nested class,
- * return true.
- * if this is an visible nested class
- * if the outer class is visible return true.
- * else return false.
- * IMPORTANT: This also allows, static nested classes
- * to be defined inside an nested class, which is not
- * allowed by the compiler. So such an test case will
- * not reach upto this method itself, but if compiler
- * allows it, then that will go through.
- */
- public boolean isVisible(ClassSymbol sym) {
- long mod = sym.flags_field;
- if (!filter.checkModifier(translateModifiers(mod))) {
- return false;
- }
- ClassSymbol encl = sym.owner.enclClass();
- return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl));
- }
-
- //---------------- print forwarders ----------------//
-
- // ERRORS
- /**
- * Print error message, increment error count.
- *
- * @param msg message to print.
- */
- public void printError(String msg) {
- messager.printError(msg);
- }
-
-// /**
-// * Print error message, increment error count.
-// *
-// * @param key selects message from resource
-// */
-// public void error(Element element, String key) {
-// if (element == null)
-// messager.error(key);
-// else
-// messager.error(element, key);
-// }
-//
-// public void error(String prefix, String key) {
-// printError(prefix + ":" + messager.getText(key));
-// }
-//
-// /**
-// * Print error message, increment error count.
-// *
-// * @param path the path to the source
-// * @param key selects message from resource
-// */
-// public void error(DocTreePath path, String key) {
-// messager.error(path, key);
-// }
-//
-// /**
-// * Print error message, increment error count.
-// *
-// * @param path the path to the source
-// * @param msg message to print.
-// */
-// public void printError(DocTreePath path, String msg) {
-// messager.printError(path, msg);
-// }
-//
-// /**
-// * Print error message, increment error count.
-// * @param e the target element
-// * @param msg message to print.
-// */
-// public void printError(Element e, String msg) {
-// messager.printError(e, msg);
-// }
-
- /**
- * Print error message, increment error count.
- *
- * @param element the source element
- * @param key selects message from resource
- * @param args replacement arguments
- */
- public void error(Element element, String key, String... args) {
- if (element == null)
- messager.error(key, (Object[]) args);
- else
- messager.error(element, key, (Object[]) args);
- }
-
- // WARNINGS
-
-// /**
-// * Print warning message, increment warning count.
-// *
-// * @param msg message to print.
-// */
-// public void printWarning(String msg) {
-// messager.printWarning(msg);
-// }
-//
-// public void warning(String key) {
-// warning((Element)null, key);
-// }
-
- public void warning(String key, String... args) {
- warning((Element)null, key, args);
- }
-
-// /**
-// * Print warning message, increment warning count.
-// *
-// * @param element the source element
-// * @param key selects message from resource
-// */
-// public void warning(Element element, String key) {
-// if (element == null)
-// messager.warning(key);
-// else
-// messager.warning(element, key);
-// }
-//
-// /**
-// * Print warning message, increment warning count.
-// *
-// * @param path the path to the source
-// * @param msg message to print.
-// */
-// public void printWarning(DocTreePath path, String msg) {
-// messager.printWarning(path, msg);
-// }
-//
-// /**
-// * Print warning message, increment warning count.
-// *
-// * @param e the source element
-// * @param msg message to print.
-// */
-// public void printWarning(Element e, String msg) {
-// messager.printWarning(e, msg);
-// }
-
- /**
- * Print warning message, increment warning count.
- *
- * @param e the source element
- * @param key selects message from resource
- * @param args the replace arguments
- */
- public void warning(Element e, String key, String... args) {
- if (e == null)
- messager.warning(key, (Object[]) args);
- else
- messager.warning(e, key, (Object[]) args);
- }
-
-// Note: no longer required
-// /**
-// * Print a message.
-// *
-// * @param msg message to print.
-// */
-// public void printNotice(String msg) {
-// if (quiet) {
-// return;
-// }
-// messager.printNotice(msg);
-// }
-
-// Note: no longer required
-// /**
-// * Print a message.
-// *
-// * @param e the source element
-// * @param msg message to print.
-// */
-// public void printNotice(Element e, String msg) {
-// if (quiet) {
-// return;
-// }
-// messager.printNotice(e, msg);
-// }
-
- // NOTICES
- /**
- * Print a message.
- *
- * @param key selects message from resource
- */
- public void notice(String key) {
- if (quiet) {
- return;
- }
- messager.notice(key);
- }
-
-// Note: not used anymore
-// /**
-// * Print a message.
-// *
-// * @param path the path to the source
-// * @param msg message to print.
-// */
-// public void printNotice(DocTreePath path, String msg) {
-// if (quiet) {
-// return;
-// }
-// messager.printNotice(path, msg);
-// }
-
- /**
- * Print a message.
- *
- * @param key selects message from resource
- * @param a1 first argument
- */
- public void notice(String key, String a1) {
- if (quiet) {
- return;
- }
- messager.notice(key, a1);
- }
-
-// Note: not used anymore
-// /**
-// * Print a message.
-// *
-// * @param key selects message from resource
-// * @param a1 first argument
-// * @param a2 second argument
-// */
-// public void notice(String key, String a1, String a2) {
-// if (quiet) {
-// return;
-// }
-// messager.notice(key, a1, a2);
-// }
-//
-
-// Note: not used anymore
-// /**
-// * Print a message.
-// *
-// * @param key selects message from resource
-// * @param a1 first argument
-// * @param a2 second argument
-// * @param a3 third argument
-// */
-// public void notice(String key, String a1, String a2, String a3) {
-// if (quiet) {
-// return;
-// }
-// messager.notice(key, a1, a2, a3);
-// }
-
- /**
- * Exit, reporting errors and warnings.
- */
- public void exit() {
- // Messager should be replaced by a more general
- // compilation environment. This can probably
- // subsume DocEnv as well.
- throw new Messager.ExitJavadoc();
- }
-
- /**
- * Adds all inner classes of this class, and their inner classes recursively, to the list
- */
- void addAllClasses(Collection<TypeElement> list, TypeElement typeElement, boolean filtered) {
- ClassSymbol klass = (ClassSymbol)typeElement;
- try {
- if (isSynthetic(klass.flags())) return;
- // sometimes synthetic classes are not marked synthetic
- if (!JavadocTool.isValidClassName(klass.name.toString())) return;
- if (filtered && !shouldDocument(klass)) return;
- if (list.contains(klass)) return;
- list.add(klass);
- for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
- if (sym != null && sym.kind == Kind.TYP) {
- ClassSymbol s = (ClassSymbol)sym;
- if (!isSynthetic(s.flags())) {
- addAllClasses(list, s, filtered);
- }
- }
- }
- } catch (CompletionFailure e) {
- // quietly ignore completion failures
- }
- }
-
- /**
- * Return a list of all classes contained in this package, including
- * member classes of those classes, and their member classes, etc.
- */
- void addAllClasses(Collection<TypeElement> list, PackageElement pkg) {
- boolean filtered = true;
- PackageSymbol sym = (PackageSymbol)pkg;
- for (Symbol isym : sym.members().getSymbols(NON_RECURSIVE)) {
- if (isym != null) {
- ClassSymbol s = (ClassSymbol)isym;
- if (!isSynthetic(s)) {
- addAllClasses(list, s, filtered);
- }
- }
- }
- }
-
- 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, JCPackageDecl tree) {
- TreePath p = treePaths.get(tree);
- if (p == null)
- treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
- return p;
- }
-
- TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
- TreePath p = treePaths.get(tree);
- if (p == null)
- treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
- return p;
- }
-
- TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) {
- return new TreePath(getTreePath(toplevel, cdecl), tree);
- }
-
- public com.sun.tools.javac.code.Types getTypes() {
- return types;
- }
-
- /**
- * Set the encoding.
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- public Env<AttrContext> getEnv(ClassSymbol tsym) {
- return enter.getEnv(tsym);
- }
-
- /**
- * Get the encoding.
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * Convert modifier bits from private coding used by
- * the compiler to that of java.lang.reflect.Modifier.
- */
- static int translateModifiers(long flags) {
- int result = 0;
- if ((flags & Flags.ABSTRACT) != 0)
- result |= Modifier.ABSTRACT;
- if ((flags & Flags.FINAL) != 0)
- result |= Modifier.FINAL;
- if ((flags & Flags.INTERFACE) != 0)
- result |= Modifier.INTERFACE;
- if ((flags & Flags.NATIVE) != 0)
- result |= Modifier.NATIVE;
- if ((flags & Flags.PRIVATE) != 0)
- result |= Modifier.PRIVATE;
- if ((flags & Flags.PROTECTED) != 0)
- result |= Modifier.PROTECTED;
- if ((flags & Flags.PUBLIC) != 0)
- result |= Modifier.PUBLIC;
- if ((flags & Flags.STATIC) != 0)
- result |= Modifier.STATIC;
- if ((flags & Flags.SYNCHRONIZED) != 0)
- result |= Modifier.SYNCHRONIZED;
- if ((flags & Flags.TRANSIENT) != 0)
- result |= Modifier.TRANSIENT;
- if ((flags & Flags.VOLATILE) != 0)
- result |= Modifier.VOLATILE;
- return result;
- }
-
- private final Set<Element> includedSet = new HashSet<>();
-
- public void setIncluded(Element element) {
- includedSet.add(element);
- }
-
- private SimpleElementVisitor9<Boolean, Void> includedVisitor = null;
-
- public boolean isIncluded(Element e) {
- if (e == null) {
- return false;
- }
- if (includedVisitor == null) {
- includedVisitor = new SimpleElementVisitor9<Boolean, Void>() {
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitType(TypeElement e, Void p) {
- if (includedSet.contains(e)) {
- return true;
- }
- if (shouldDocument(e)) {
- // Class is nameable from top-level and
- // the class and all enclosing classes
- // pass the modifier filter.
- PackageElement pkg = elements.getPackageOf(e);
- if (includedSet.contains(pkg)) {
- setIncluded(e);
- return true;
- }
- Element enclosing = e.getEnclosingElement();
- if (enclosing != null && includedSet.contains(enclosing)) {
- setIncluded(e);
- return true;
- }
- }
- return false;
- }
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitPackage(PackageElement e, Void p) {
- return includedSet.contains(e);
- }
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean visitUnknown(Element e, Void p) {
- throw new AssertionError("unknown element: " + e);
- }
-
- @Override @DefinedBy(Api.LANGUAGE_MODEL)
- public Boolean defaultAction(Element e, Void p) {
- return visit(e.getEnclosingElement()) && shouldDocument(e);
- }
- };
- }
- return includedVisitor.visit(e);
- }
-
- public boolean isQuiet() {
- return quiet;
- }
-
- /**
- * A class which filters the access flags on classes, fields, methods, etc.
- *
- * <p>
- * <b>This is NOT part of any supported API. If you write code that depends on this, you do so
- * at your own risk. This code and its internal interfaces are subject to change or deletion
- * without notice.</b>
- *
- * @see javax.lang.model.element.Modifier
- * @author Robert Field
- */
-
- private static class ModifierFilter {
-
- static enum FilterFlag {
- PACKAGE,
- PRIVATE,
- PROTECTED,
- PUBLIC
- }
-
- private Set<FilterFlag> oneOf;
-
- /**
- * Constructor - Specify a filter.
- *
- * @param oneOf a set containing desired flags to be matched.
- */
- ModifierFilter(Set<FilterFlag> oneOf) {
- this.oneOf = oneOf;
- }
-
- /**
- * Constructor - Specify a filter.
- *
- * @param oneOf an array containing desired flags to be matched.
- */
- ModifierFilter(FilterFlag... oneOf) {
- this.oneOf = new HashSet<>();
- this.oneOf.addAll(Arrays.asList(oneOf));
- }
-
- static ModifierFilter getModifierFilter(String showAccess) {
- switch (showAccess) {
- case "public":
- return new ModifierFilter(FilterFlag.PUBLIC);
- case "package":
- return new ModifierFilter(FilterFlag.PUBLIC, FilterFlag.PROTECTED,
- FilterFlag.PACKAGE);
- case "private":
- return new ModifierFilter(FilterFlag.PRIVATE);
- default:
- return new ModifierFilter(FilterFlag.PUBLIC, FilterFlag.PROTECTED);
- }
- }
-
- private boolean hasFlag(long flag, long modifierBits) {
- return (flag & modifierBits) != 0;
- }
-
- private List<FilterFlag> flagsToModifiers(long modifierBits) {
- List<FilterFlag> list = new ArrayList<>();
- boolean isPackage = true;
- if (hasFlag(com.sun.tools.javac.code.Flags.PRIVATE, modifierBits)) {
- list.add(FilterFlag.PRIVATE);
- isPackage = false;
- }
- if (hasFlag(com.sun.tools.javac.code.Flags.PROTECTED, modifierBits)) {
- list.add(FilterFlag.PROTECTED);
- isPackage = false;
- }
- if (hasFlag(com.sun.tools.javac.code.Flags.PUBLIC, modifierBits)) {
- list.add(FilterFlag.PUBLIC);
- isPackage = false;
- }
- if (isPackage) {
- list.add(FilterFlag.PACKAGE);
- }
- return list;
- }
-
- /**
- * Filter on modifier bits.
- *
- * @param modifierBits Bits as specified in the Modifier class
- *
- * @return Whether the modifierBits pass this filter.
- */
- public boolean checkModifier(int modifierBits) {
- return checkModifier(flagsToModifiers(modifierBits));
- }
-
- /**
- * Filter on Filter flags
- *
- * @param modifiers Flags as specified in the FilterFlags enumeration.
- *
- * @return if the modifier is contained.
- */
- public boolean checkModifier(List<FilterFlag> modifiers) {
- if (oneOf.contains(FilterFlag.PRIVATE)) {
- return true;
- }
- for (FilterFlag mod : modifiers) {
- if (oneOf.contains(mod)) {
- return true;
- }
- }
- return false;
- }
-
- } // end ModifierFilter
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnvImpl.java Tue Jun 28 16:43:41 2016 -0700
@@ -0,0 +1,304 @@
+/*
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.javadoc.internal.tool;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.Types;
+import javax.tools.JavaFileManager;
+
+import com.sun.source.util.DocTrees;
+import com.sun.tools.javac.code.Source;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import jdk.javadoc.doclet.DocletEnvironment;
+
+/**
+ * This class holds the information from one run of javadoc.
+ * Particularly the packages, classes and options specified
+ * by the user.
+ *
+ * <p><b>This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ *
+ * @author Robert Field
+ * @author Atul M Dambalkar
+ * @author Neal Gafter (rewrite)
+ */
+public class DocEnvImpl implements DocletEnvironment {
+
+ /**
+ * list of classes specified on the command line.
+ */
+ private Set<TypeElement> cmdLineClasses;
+
+ /**
+ * list of packages specified on the command line.
+ */
+ private Set<PackageElement> cmdLinePackages;
+
+ public final ToolEnvironment toolEnv;
+
+ /**
+ * Constructor used when reading source files.
+ *
+ * @param toolEnv the documentation environment, state for this javadoc run
+ * @param classes list of classes specified on the commandline
+ * @param packages list of package names specified on the commandline
+ */
+ public DocEnvImpl(ToolEnvironment toolEnv, List<JCClassDecl> classes, List<String> packages) {
+ this.toolEnv = toolEnv;
+ setPackages(toolEnv, packages);
+ setClasses(toolEnv, classes);
+ }
+
+ /**
+ * Constructor used when reading class files.
+ *
+ * @param toolEnv the documentation environment, state for this javadoc run
+ * @param classes list of class names specified on the commandline
+ */
+ public DocEnvImpl(ToolEnvironment toolEnv, List<String> classes) {
+ //super(env, null);
+ this.toolEnv = toolEnv;
+
+ Set<TypeElement> classList = new LinkedHashSet<>();
+ for (String className : classes) {
+ TypeElement c = toolEnv.loadClass(className);
+ if (c == null)
+ toolEnv.error(null, "javadoc.class_not_found", className);
+ else
+ classList.add(c);
+ }
+ cmdLineClasses = classList;
+ }
+
+ /**
+ * Initialize classes information. Those classes are input from
+ * command line.
+ *
+ * @param toolEnv the compilation environment
+ * @param classes a list of ClassDeclaration
+ */
+ private void setClasses(ToolEnvironment toolEnv, List<JCClassDecl> classes) {
+ Set<TypeElement> result = new LinkedHashSet<>();
+ classes.stream().filter((def) -> (toolEnv.shouldDocument(def.sym))).forEach((def) -> {
+ TypeElement te = (TypeElement)def.sym;
+ if (te != null) {
+ toolEnv.setIncluded((Element)def.sym);
+ result.add(te);
+ }
+ });
+ cmdLineClasses = Collections.unmodifiableSet(result);
+ }
+
+ /**
+ * Initialize packages information.
+ *
+ * @param toolEnv the compilation environment
+ * @param packages a list of package names (String)
+ */
+ private void setPackages(ToolEnvironment toolEnv, List<String> packages) {
+ Set<PackageElement> packlist = new LinkedHashSet<>();
+ packages.stream().forEach((name) -> {
+ PackageElement pkg = getElementUtils().getPackageElement(name);
+ if (pkg != null) {
+ toolEnv.setIncluded(pkg);
+ packlist.add(pkg);
+ } else {
+ toolEnv.warning("main.no_source_files_for_package", name);
+ }
+ });
+ cmdLinePackages = Collections.unmodifiableSet(packlist);
+ }
+
+ /**
+ * Packages specified on the command line.
+ */
+ public Set<PackageElement> specifiedPackages() {
+ return cmdLinePackages;
+ }
+
+ /**
+ * Classes and interfaces specified on the command line,
+ * including their inner classes
+ */
+ public Set<TypeElement> specifiedClasses() {
+ Set<TypeElement> out = new LinkedHashSet<>();
+ cmdLineClasses.stream().forEach((te) -> {
+ toolEnv.addAllClasses(out, te, true);
+ });
+ return out;
+ }
+
+ private Set<TypeElement> classesToDocument = null;
+ /**
+ * Return all classes and interfaces (including those inside
+ * packages) to be documented.
+ */
+ public Set<TypeElement> getIncludedClasses() {
+ if (classesToDocument == null) {
+ Set<TypeElement> classes = new LinkedHashSet<>();
+
+ cmdLineClasses.stream().forEach((te) -> {
+ toolEnv.addAllClasses(classes, te, true);
+ });
+ cmdLinePackages.stream().forEach((pkg) -> {
+ toolEnv.addAllClasses(classes, pkg);
+ });
+ classesToDocument = Collections.unmodifiableSet(classes);
+ }
+ return classesToDocument;
+ }
+
+ /**
+ * Return the name of this item.
+ *
+ * @return the string <code>"*RootDocImpl*"</code>.
+ */
+ public String name() {
+ return "*RootDocImpl*";
+ }
+
+ /**
+ * Return the name of this Doc item.
+ *
+ * @return the string <code>"*RootDocImpl*"</code>.
+ */
+ public String qualifiedName() {
+ return "*RootDocImpl*";
+ }
+
+ /**
+ * Return true if this Element is included in the active set.
+ * RootDocImpl isn't even a program entity so it is always false.
+ */
+ @Override
+ public boolean isIncluded(Element e) {
+ return toolEnv.isIncluded(e);
+ }
+
+// Note: these reporting methods are no longer used.
+// /**
+// * Print error message, increment error count.
+// *
+// * @param msg message to print
+// */
+// public void printError(String msg) {
+// env.printError(msg);
+// }
+//
+// /**
+// * Print error message, increment error count.
+// *
+// * @param msg message to print
+// */
+// public void printError(DocTreePath path, String msg) {
+// env.printError(path, msg);
+// }
+//
+// public void printError(Element e, String msg) {
+// env.printError(e, msg);
+// }
+//
+// public void printWarning(Element e, String msg) {
+// env.printWarning(e, msg);
+// }
+//
+// public void printNotice(Element e, String msg) {
+// env.printNotice(e, msg);
+// }
+//
+// /**
+// * Print warning message, increment warning count.
+// *
+// * @param msg message to print
+// */
+// public void printWarning(String msg) {
+// env.printWarning(msg);
+// }
+
+ /**
+ * Return the current file manager.
+ */
+ public JavaFileManager getFileManager() {
+ return toolEnv.fileManager;
+ }
+
+ @Override
+ public DocTrees getDocTrees() {
+ return toolEnv.docTrees;
+ }
+
+ @Override
+ public Elements getElementUtils() {
+ return toolEnv.elements;
+ }
+
+ @Override
+ public List<Element> getSelectedElements(List<? extends Element> elements) {
+ return elements.stream()
+ .filter(e -> isIncluded(e))
+ .collect(Collectors.<Element>toList());
+ }
+
+ @Override
+ public Set<Element> getSpecifiedElements() {
+ Set<Element> out = new LinkedHashSet<>();
+ specifiedPackages().stream().forEach((pe) -> {
+ out.add(pe);
+ });
+ specifiedClasses().stream().forEach((e) -> {
+ out.add(e);
+ });
+ return out;
+ }
+
+ @Override
+ public Types getTypeUtils() {
+ return toolEnv.typeutils;
+ }
+
+ @Override
+ public JavaFileManager getJavaFileManager() {
+ return toolEnv.fileManager;
+ }
+
+ @Override
+ public SourceVersion getSourceVersion() {
+ return Source.toSourceVersion(toolEnv.source);
+ }
+}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocClassFinder.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocClassFinder.java Tue Jun 28 16:43:41 2016 -0700
@@ -60,7 +60,7 @@
});
}
- private DocEnv docenv;
+ private ToolEnvironment toolEnv;
private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,
JavaFileObject.Kind.SOURCE,
JavaFileObject.Kind.HTML);
@@ -72,7 +72,7 @@
public JavadocClassFinder(Context context) {
super(context);
- docenv = DocEnv.instance(context);
+ toolEnv = ToolEnvironment.instance(context);
preferSource = true;
trees = JavacTrees.instance(context);
}
@@ -82,7 +82,7 @@
*/
@Override
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
- return docenv.docClasses ? noSource : all;
+ return toolEnv.docClasses ? noSource : all;
}
/**
@@ -91,7 +91,7 @@
@Override
protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML)) {
- docenv.pkgToJavaFOMap.put(pack, fo);
+ toolEnv.pkgToJavaFOMap.put(pack, fo);
trees.putJavaFileObject(pack, fo);
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -67,11 +67,11 @@
protected JavadocEnter(Context context) {
super(context);
messager = Messager.instance0(context);
- docenv = DocEnv.instance(context);
+ toolEnv = ToolEnvironment.instance(context);
}
final Messager messager;
- final DocEnv docenv;
+ final ToolEnvironment toolEnv;
@Override
public void main(List<JCCompilationUnit> trees) {
@@ -87,8 +87,8 @@
super.visitTopLevel(tree);
if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
JCPackageDecl pd = tree.getPackage();
- TreePath tp = pd == null ? docenv.getTreePath(tree) : docenv.getTreePath(tree, pd);
- docenv.setElementToTreePath(tree.packge, tp);
+ TreePath tp = pd == null ? toolEnv.getTreePath(tree) : toolEnv.getTreePath(tree, pd);
+ toolEnv.setElementToTreePath(tree.packge, tp);
}
}
@@ -98,7 +98,7 @@
if (tree.sym == null) return;
if (tree.sym.kind == TYP || tree.sym.kind == ERR) {
ClassSymbol c = tree.sym;
- docenv.setElementToTreePath(c, docenv.getTreePath(env.toplevel, tree));
+ toolEnv.setElementToTreePath(c, toolEnv.getTreePath(env.toplevel, tree));
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocMemberEnter.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocMemberEnter.java Tue Jun 28 16:43:41 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -63,11 +63,11 @@
});
}
- final DocEnv docenv;
+ final ToolEnvironment toolEnv;
protected JavadocMemberEnter(Context context) {
super(context);
- docenv = DocEnv.instance(context);
+ toolEnv = ToolEnvironment.instance(context);
}
@Override
@@ -75,12 +75,12 @@
super.visitMethodDef(tree);
MethodSymbol meth = tree.sym;
if (meth == null || meth.kind != MTH) return;
- TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree);
+ TreePath treePath = toolEnv.getTreePath(env.toplevel, env.enclClass, tree);
// do not add those methods that may be mandated by the spec,
// or those that are synthesized, thus if it does not exist in
// tree best to let other logic determine the TreePath.
if (env.enclClass.defs.contains(tree)) {
- docenv.setElementToTreePath(meth, treePath);
+ toolEnv.setElementToTreePath(meth, treePath);
}
// release resources
tree.body = null;
@@ -101,7 +101,7 @@
}
super.visitVarDef(tree);
if (tree.sym != null && tree.sym.kind == VAR && !isParameter(tree.sym)) {
- docenv.setElementToTreePath(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree));
+ toolEnv.setElementToTreePath(tree.sym, toolEnv.getTreePath(env.toplevel, env.enclClass, tree));
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java Tue Jun 28 15:29:20 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java Tue Jun 28 16:43:41 2016 -0700
@@ -74,7 +74,7 @@
* @author Neal Gafter
*/
public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
- DocEnv docenv;
+ ToolEnvironment toolEnv;
final Messager messager;
final ClassFinder javadocFinder;
@@ -138,8 +138,8 @@
List<String> excludedPackages,
boolean docClasses,
boolean quiet) throws IOException {
- docenv = DocEnv.instance(context);
- docenv.intialize(encoding, showAccess, overviewpath, args, fileObjects,
+ toolEnv = ToolEnvironment.instance(context);
+ toolEnv.intialize(encoding, showAccess, overviewpath, args, fileObjects,
subPackages, excludedPackages, docClasses, quiet);
javadocFinder.sourceCompleter = docClasses ? Completer.NULL_COMPLETER : sourceCompleter;
@@ -148,12 +148,12 @@
// If -Xclasses is set, the args should be a series of class names
for (String arg: args) {
if (!isValidPackageName(arg)) // checks
- docenv.error(null, "main.illegal_class_name", arg);
+ toolEnv.error(null, "main.illegal_class_name", arg);
}
if (messager.nerrors() != 0) {
return null;
}
- return new RootDocImpl(docenv, args);
+ return new DocEnvImpl(toolEnv, args);
}
ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<>();
@@ -161,15 +161,15 @@
try {
- StandardJavaFileManager fm = docenv.fileManager instanceof StandardJavaFileManager
- ? (StandardJavaFileManager) docenv.fileManager : null;
+ StandardJavaFileManager fm = toolEnv.fileManager instanceof StandardJavaFileManager
+ ? (StandardJavaFileManager) toolEnv.fileManager : null;
Set<String> packageNames = new LinkedHashSet<>();
// Normally, the args should be a series of package names or file names.
// Parse the files and collect the package names.
for (String arg: args) {
if (fm != null && arg.endsWith(".java") && new File(arg).exists()) {
if (new File(arg).getName().equals("module-info.java")) {
- docenv.warning("main.file_ignored", arg);
+ toolEnv.warning("main.file_ignored", arg);
} else {
parse(fm.getJavaFileObjects(arg), classTrees, true);
}
@@ -179,9 +179,9 @@
if (fm == null)
throw new IllegalArgumentException();
else
- docenv.error(null, "main.file_not_found", arg);
+ toolEnv.error(null, "main.file_not_found", arg);
} else {
- docenv.error(null, "main.illegal_package_name", arg);
+ toolEnv.error(null, "main.illegal_package_name", arg);
}
}
@@ -193,10 +193,10 @@
// Build up the complete list of any packages to be documented
Location location = modules.multiModuleMode ? StandardLocation.MODULE_SOURCE_PATH
- : docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH
+ : toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH
: StandardLocation.CLASS_PATH;
- PackageTable t = new PackageTable(docenv.fileManager, location)
+ PackageTable t = new PackageTable(toolEnv.fileManager, location)
.packages(packageNames)
.subpackages(subPackages, excludedPackages);
@@ -206,9 +206,9 @@
ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
for (String packageName: includedPackages) {
List<JavaFileObject> files = t.getFiles(packageName);
- docenv.notice("main.Loading_source_files_for_package", packageName);
+ toolEnv.notice("main.Loading_source_files_for_package", packageName);
if (files.isEmpty())
- docenv.warning("main.no_source_files_for_package", packageName);
+ toolEnv.warning("main.no_source_files_for_package", packageName);
parse(files, packageTrees, false);
}
modules.enter(packageTrees.toList(), null);
@@ -218,7 +218,7 @@
}
// Enter symbols for all files
- docenv.notice("main.Building_tree");
+ toolEnv.notice("main.Building_tree");
javadocEnter.main(classTrees.toList().appendList(packageTrees.toList()));
enterDone = true;
@@ -226,9 +226,9 @@
if (messager.nerrors() != 0)
return null;
- docenv.root = new RootDocImpl(docenv, listClasses(classTrees.toList()),
+ toolEnv.docEnv = new DocEnvImpl(toolEnv, listClasses(classTrees.toList()),
new ArrayList<>(includedPackages));
- return docenv.root;
+ return toolEnv.docEnv;
}
/** Is the given string a valid package name? */
@@ -246,7 +246,7 @@
for (JavaFileObject fo: files) {
if (uniquefiles.add(fo)) { // ignore duplicates
if (trace)
- docenv.notice("main.Loading_source_file", fo.getName());
+ toolEnv.notice("main.Loading_source_file", fo.getName());
trees.append(parse(fo));
}
}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/RootDocImpl.java Tue Jun 28 15:29:20 2016 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,304 +0,0 @@
-/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.javadoc.internal.tool;
-
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.Elements;
-import javax.lang.model.util.Types;
-import javax.tools.JavaFileManager;
-
-import com.sun.source.util.DocTrees;
-import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
-import jdk.javadoc.doclet.DocletEnvironment;
-
-/**
- * This class holds the information from one run of javadoc.
- * Particularly the packages, classes and options specified
- * by the user.
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own risk.
- * This code and its internal interfaces are subject to change or
- * deletion without notice.</b>
- *
- * @author Robert Field
- * @author Atul M Dambalkar
- * @author Neal Gafter (rewrite)
- */
-public class RootDocImpl implements DocletEnvironment {
-
- /**
- * list of classes specified on the command line.
- */
- private Set<TypeElement> cmdLineClasses;
-
- /**
- * list of packages specified on the command line.
- */
- private Set<PackageElement> cmdLinePackages;
-
- public final DocEnv env;
-
- /**
- * Constructor used when reading source files.
- *
- * @param env the documentation environment, state for this javadoc run
- * @param classes list of classes specified on the commandline
- * @param packages list of package names specified on the commandline
- */
- public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages) {
- this.env = env;
- setPackages(env, packages);
- setClasses(env, classes);
- }
-
- /**
- * Constructor used when reading class files.
- *
- * @param env the documentation environment, state for this javadoc run
- * @param classes list of class names specified on the commandline
- */
- public RootDocImpl(DocEnv env, List<String> classes) {
- //super(env, null);
- this.env = env;
-
- Set<TypeElement> classList = new LinkedHashSet<>();
- for (String className : classes) {
- TypeElement c = env.loadClass(className);
- if (c == null)
- env.error(null, "javadoc.class_not_found", className);
- else
- classList.add(c);
- }
- cmdLineClasses = classList;
- }
-
- /**
- * Initialize classes information. Those classes are input from
- * command line.
- *
- * @param env the compilation environment
- * @param classes a list of ClassDeclaration
- */
- private void setClasses(DocEnv env, List<JCClassDecl> classes) {
- Set<TypeElement> result = new LinkedHashSet<>();
- classes.stream().filter((def) -> (env.shouldDocument(def.sym))).forEach((def) -> {
- TypeElement te = (TypeElement)def.sym;
- if (te != null) {
- env.setIncluded((Element)def.sym);
- result.add(te);
- }
- });
- cmdLineClasses = Collections.unmodifiableSet(result);
- }
-
- /**
- * Initialize packages information.
- *
- * @param env the compilation environment
- * @param packages a list of package names (String)
- */
- private void setPackages(DocEnv env, List<String> packages) {
- Set<PackageElement> packlist = new LinkedHashSet<>();
- packages.stream().forEach((name) -> {
- PackageElement pkg = getElementUtils().getPackageElement(name);
- if (pkg != null) {
- env.setIncluded(pkg);
- packlist.add(pkg);
- } else {
- env.warning("main.no_source_files_for_package", name);
- }
- });
- cmdLinePackages = Collections.unmodifiableSet(packlist);
- }
-
- /**
- * Packages specified on the command line.
- */
- public Set<PackageElement> specifiedPackages() {
- return cmdLinePackages;
- }
-
- /**
- * Classes and interfaces specified on the command line,
- * including their inner classes
- */
- public Set<TypeElement> specifiedClasses() {
- Set<TypeElement> out = new LinkedHashSet<>();
- cmdLineClasses.stream().forEach((te) -> {
- env.addAllClasses(out, te, true);
- });
- return out;
- }
-
- private Set<TypeElement> classesToDocument = null;
- /**
- * Return all classes and interfaces (including those inside
- * packages) to be documented.
- */
- public Set<TypeElement> getIncludedClasses() {
- if (classesToDocument == null) {
- Set<TypeElement> classes = new LinkedHashSet<>();
-
- cmdLineClasses.stream().forEach((te) -> {
- env.addAllClasses(classes, te, true);
- });
- cmdLinePackages.stream().forEach((pkg) -> {
- env.addAllClasses(classes, pkg);
- });
- classesToDocument = Collections.unmodifiableSet(classes);
- }
- return classesToDocument;
- }
-
- /**
- * Return the name of this item.
- *
- * @return the string <code>"*RootDocImpl*"</code>.
- */
- public String name() {
- return "*RootDocImpl*";
- }
-
- /**
- * Return the name of this Doc item.
- *
- * @return the string <code>"*RootDocImpl*"</code>.
- */
- public String qualifiedName() {
- return "*RootDocImpl*";
- }
-
- /**
- * Return true if this Element is included in the active set.
- * RootDocImpl isn't even a program entity so it is always false.
- */
- @Override
- public boolean isIncluded(Element e) {
- return env.isIncluded(e);
- }
-
-// Note: these reporting methods are no longer used.
-// /**
-// * Print error message, increment error count.
-// *
-// * @param msg message to print
-// */
-// public void printError(String msg) {
-// env.printError(msg);
-// }
-//
-// /**
-// * Print error message, increment error count.
-// *
-// * @param msg message to print
-// */
-// public void printError(DocTreePath path, String msg) {
-// env.printError(path, msg);
-// }
-//
-// public void printError(Element e, String msg) {
-// env.printError(e, msg);
-// }
-//
-// public void printWarning(Element e, String msg) {
-// env.printWarning(e, msg);
-// }
-//
-// public void printNotice(Element e, String msg) {
-// env.printNotice(e, msg);
-// }
-//
-// /**
-// * Print warning message, increment warning count.
-// *
-// * @param msg message to print
-// */
-// public void printWarning(String msg) {
-// env.printWarning(msg);
-// }
-
- /**
- * Return the current file manager.
- */
- public JavaFileManager getFileManager() {
- return env.fileManager;
- }
-
- @Override
- public DocTrees getDocTrees() {
- return env.docTrees;
- }
-
- @Override
- public Elements getElementUtils() {
- return env.elements;
- }
-
- @Override
- public List<Element> getSelectedElements(List<? extends Element> elements) {
- return elements.stream()
- .filter(e -> isIncluded(e))
- .collect(Collectors.<Element>toList());
- }
-
- @Override
- public Set<Element> getSpecifiedElements() {
- Set<Element> out = new LinkedHashSet<>();
- specifiedPackages().stream().forEach((pe) -> {
- out.add(pe);
- });
- specifiedClasses().stream().forEach((e) -> {
- out.add(e);
- });
- return out;
- }
-
- @Override
- public Types getTypeUtils() {
- return env.typeutils;
- }
-
- @Override
- public JavaFileManager getJavaFileManager() {
- return env.fileManager;
- }
-
- @Override
- public SourceVersion getSourceVersion() {
- return Source.toSourceVersion(env.source);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java Tue Jun 28 16:43:41 2016 -0700
@@ -0,0 +1,848 @@
+/*
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.javadoc.internal.tool;
+
+
+import java.lang.reflect.Modifier;
+import java.util.*;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor9;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.api.JavacTrees;
+import com.sun.tools.javac.code.ClassFinder;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Kinds.Kind;
+import com.sun.tools.javac.code.Source;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.CompletionFailure;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
+import com.sun.tools.javac.code.Symbol.ModuleSymbol;
+import com.sun.tools.javac.code.Symbol.PackageSymbol;
+import com.sun.tools.javac.code.Symbol.VarSymbol;
+import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.comp.AttrContext;
+import com.sun.tools.javac.comp.Check;
+import com.sun.tools.javac.comp.Enter;
+import com.sun.tools.javac.comp.Env;
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.model.JavacElements;
+import com.sun.tools.javac.model.JavacTypes;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.tree.JCTree.JCPackageDecl;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.Convert;
+import com.sun.tools.javac.util.DefinedBy;
+import com.sun.tools.javac.util.DefinedBy.Api;
+import com.sun.tools.javac.util.Name;
+import com.sun.tools.javac.util.Names;
+
+import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
+
+/**
+ * Holds the environment for a run of javadoc.
+ * Holds only the information needed throughout the
+ * run and not the compiler info that could be GC'ed
+ * or ported.
+ *
+ * <p><b>This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ *
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (generics)
+ */
+public class ToolEnvironment {
+ protected static final Context.Key<ToolEnvironment> ToolEnvKey = new Context.Key<>();
+
+ public static ToolEnvironment instance(Context context) {
+ ToolEnvironment instance = context.get(ToolEnvKey);
+ if (instance == null)
+ instance = new ToolEnvironment(context);
+ return instance;
+ }
+
+ private final Messager messager;
+
+ /** Predefined symbols known to the compiler. */
+ public final Symtab syms;
+
+ /** Referenced directly in RootDocImpl. */
+ private final ClassFinder finder;
+
+ /** Javadoc's own version of the compiler's enter phase. */
+ final Enter enter;
+
+ /** The name table. */
+ private Names names;
+
+ /** The encoding name. */
+ private String encoding;
+
+ final Symbol externalizableSym;
+
+ /** Access filter (public, protected, ...). */
+ protected ModifierFilter filter;
+
+ /**
+ * True if we do not want to print any notifications at all.
+ */
+ boolean quiet = false;
+
+ Check chk;
+ com.sun.tools.javac.code.Types types;
+ JavaFileManager fileManager;
+ public final Context context;
+
+ WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<>();
+
+ public final HashMap<PackageElement, JavaFileObject> pkgToJavaFOMap = new HashMap<>();
+
+ /** Allow documenting from class files? */
+ boolean docClasses = false;
+
+ /**
+ * The source language version.
+ */
+ public final Source source;
+
+ public final Elements elements;
+
+ public final JavacTypes typeutils;
+
+ protected DocEnvImpl docEnv;
+
+ public final DocTrees docTrees;
+
+ public final Map<Element, TreePath> elementToTreePath;
+
+ /**
+ * Constructor
+ *
+ * @param context Context for this javadoc instance.
+ */
+ protected ToolEnvironment(Context context) {
+ context.put(ToolEnvKey, this);
+ this.context = context;
+
+ messager = Messager.instance0(context);
+ syms = Symtab.instance(context);
+ finder = JavadocClassFinder.instance(context);
+ enter = JavadocEnter.instance(context);
+ names = Names.instance(context);
+ externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
+ chk = Check.instance(context);
+ types = com.sun.tools.javac.code.Types.instance(context);
+ fileManager = context.get(JavaFileManager.class);
+ if (fileManager instanceof JavacFileManager) {
+ ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
+ }
+ docTrees = JavacTrees.instance(context);
+ source = Source.instance(context);
+ elements = JavacElements.instance(context);
+ typeutils = JavacTypes.instance(context);
+ elementToTreePath = new HashMap<>();
+ }
+
+ public void intialize(String encoding,
+ String showAccess,
+ String overviewpath,
+ List<String> javaNames,
+ Iterable<? extends JavaFileObject> fileObjects,
+ List<String> subPackages,
+ List<String> excludedPackages,
+ boolean docClasses,
+ boolean quiet) {
+ this.filter = ModifierFilter.getModifierFilter(showAccess);
+ this.quiet = quiet;
+
+ this.setEncoding(encoding);
+ this.docClasses = docClasses;
+ }
+
+ /**
+ * Load a class by qualified name.
+ */
+ public TypeElement loadClass(String name) {
+ try {
+ Name nameImpl = names.fromString(name);
+ ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
+ ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
+ return c;
+ } catch (CompletionFailure ex) {
+ chk.completionError(null, ex);
+ return null;
+ }
+ }
+
+ private boolean isSynthetic(long flags) {
+ return (flags & Flags.SYNTHETIC) != 0;
+ }
+
+ private boolean isSynthetic(Symbol sym) {
+ return isSynthetic(sym.flags_field);
+ }
+
+ SimpleElementVisitor9<Boolean, Void> shouldDocumentVisitor = null;
+ public boolean shouldDocument(Element e) {
+ if (shouldDocumentVisitor == null) {
+ shouldDocumentVisitor = new SimpleElementVisitor9<Boolean, Void>() {
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitType(TypeElement e, Void p) {
+ return shouldDocument((ClassSymbol)e);
+ }
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitVariable(VariableElement e, Void p) {
+ return shouldDocument((VarSymbol)e);
+ }
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitExecutable(ExecutableElement e, Void p) {
+ return shouldDocument((MethodSymbol)e);
+ }
+ };
+ }
+ return shouldDocumentVisitor.visit(e);
+ }
+
+ /** Check whether this member should be documented. */
+ public boolean shouldDocument(VarSymbol sym) {
+ long mod = sym.flags();
+ if (isSynthetic(mod)) {
+ return false;
+ }
+ return filter.checkModifier(translateModifiers(mod));
+ }
+
+ /** Check whether this member should be documented. */
+ public boolean shouldDocument(MethodSymbol sym) {
+ long mod = sym.flags();
+ if (isSynthetic(mod)) {
+ return false;
+ }
+ return filter.checkModifier(translateModifiers(mod));
+ }
+
+ void setElementToTreePath(Element e, TreePath tree) {
+ if (e == null || tree == null)
+ return;
+ elementToTreePath.put(e, tree);
+ }
+
+ private boolean hasLeaf(ClassSymbol sym) {
+ TreePath path = elementToTreePath.get(sym);
+ if (path == null)
+ return false;
+ return path.getLeaf() != null;
+ }
+
+ /** check whether this class should be documented. */
+ public boolean shouldDocument(ClassSymbol sym) {
+ return
+ !isSynthetic(sym.flags_field) && // no synthetics
+ (docClasses || hasLeaf(sym)) &&
+ isVisible(sym);
+ }
+
+ //### Comment below is inaccurate wrt modifier filter testing
+ /**
+ * Check the visibility if this is an nested class.
+ * if this is not a nested class, return true.
+ * if this is an static visible nested class,
+ * return true.
+ * if this is an visible nested class
+ * if the outer class is visible return true.
+ * else return false.
+ * IMPORTANT: This also allows, static nested classes
+ * to be defined inside an nested class, which is not
+ * allowed by the compiler. So such an test case will
+ * not reach upto this method itself, but if compiler
+ * allows it, then that will go through.
+ */
+ public boolean isVisible(ClassSymbol sym) {
+ long mod = sym.flags_field;
+ if (!filter.checkModifier(translateModifiers(mod))) {
+ return false;
+ }
+ ClassSymbol encl = sym.owner.enclClass();
+ return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl));
+ }
+
+ //---------------- print forwarders ----------------//
+
+ // ERRORS
+ /**
+ * Print error message, increment error count.
+ *
+ * @param msg message to print.
+ */
+ public void printError(String msg) {
+ messager.printError(msg);
+ }
+
+// /**
+// * Print error message, increment error count.
+// *
+// * @param key selects message from resource
+// */
+// public void error(Element element, String key) {
+// if (element == null)
+// messager.error(key);
+// else
+// messager.error(element, key);
+// }
+//
+// public void error(String prefix, String key) {
+// printError(prefix + ":" + messager.getText(key));
+// }
+//
+// /**
+// * Print error message, increment error count.
+// *
+// * @param path the path to the source
+// * @param key selects message from resource
+// */
+// public void error(DocTreePath path, String key) {
+// messager.error(path, key);
+// }
+//
+// /**
+// * Print error message, increment error count.
+// *
+// * @param path the path to the source
+// * @param msg message to print.
+// */
+// public void printError(DocTreePath path, String msg) {
+// messager.printError(path, msg);
+// }
+//
+// /**
+// * Print error message, increment error count.
+// * @param e the target element
+// * @param msg message to print.
+// */
+// public void printError(Element e, String msg) {
+// messager.printError(e, msg);
+// }
+
+ /**
+ * Print error message, increment error count.
+ *
+ * @param element the source element
+ * @param key selects message from resource
+ * @param args replacement arguments
+ */
+ public void error(Element element, String key, String... args) {
+ if (element == null)
+ messager.error(key, (Object[]) args);
+ else
+ messager.error(element, key, (Object[]) args);
+ }
+
+ // WARNINGS
+
+// /**
+// * Print warning message, increment warning count.
+// *
+// * @param msg message to print.
+// */
+// public void printWarning(String msg) {
+// messager.printWarning(msg);
+// }
+//
+// public void warning(String key) {
+// warning((Element)null, key);
+// }
+
+ public void warning(String key, String... args) {
+ warning((Element)null, key, args);
+ }
+
+// /**
+// * Print warning message, increment warning count.
+// *
+// * @param element the source element
+// * @param key selects message from resource
+// */
+// public void warning(Element element, String key) {
+// if (element == null)
+// messager.warning(key);
+// else
+// messager.warning(element, key);
+// }
+//
+// /**
+// * Print warning message, increment warning count.
+// *
+// * @param path the path to the source
+// * @param msg message to print.
+// */
+// public void printWarning(DocTreePath path, String msg) {
+// messager.printWarning(path, msg);
+// }
+//
+// /**
+// * Print warning message, increment warning count.
+// *
+// * @param e the source element
+// * @param msg message to print.
+// */
+// public void printWarning(Element e, String msg) {
+// messager.printWarning(e, msg);
+// }
+
+ /**
+ * Print warning message, increment warning count.
+ *
+ * @param e the source element
+ * @param key selects message from resource
+ * @param args the replace arguments
+ */
+ public void warning(Element e, String key, String... args) {
+ if (e == null)
+ messager.warning(key, (Object[]) args);
+ else
+ messager.warning(e, key, (Object[]) args);
+ }
+
+// Note: no longer required
+// /**
+// * Print a message.
+// *
+// * @param msg message to print.
+// */
+// public void printNotice(String msg) {
+// if (quiet) {
+// return;
+// }
+// messager.printNotice(msg);
+// }
+
+// Note: no longer required
+// /**
+// * Print a message.
+// *
+// * @param e the source element
+// * @param msg message to print.
+// */
+// public void printNotice(Element e, String msg) {
+// if (quiet) {
+// return;
+// }
+// messager.printNotice(e, msg);
+// }
+
+ // NOTICES
+ /**
+ * Print a message.
+ *
+ * @param key selects message from resource
+ */
+ public void notice(String key) {
+ if (quiet) {
+ return;
+ }
+ messager.notice(key);
+ }
+
+// Note: not used anymore
+// /**
+// * Print a message.
+// *
+// * @param path the path to the source
+// * @param msg message to print.
+// */
+// public void printNotice(DocTreePath path, String msg) {
+// if (quiet) {
+// return;
+// }
+// messager.printNotice(path, msg);
+// }
+
+ /**
+ * Print a message.
+ *
+ * @param key selects message from resource
+ * @param a1 first argument
+ */
+ public void notice(String key, String a1) {
+ if (quiet) {
+ return;
+ }
+ messager.notice(key, a1);
+ }
+
+// Note: not used anymore
+// /**
+// * Print a message.
+// *
+// * @param key selects message from resource
+// * @param a1 first argument
+// * @param a2 second argument
+// */
+// public void notice(String key, String a1, String a2) {
+// if (quiet) {
+// return;
+// }
+// messager.notice(key, a1, a2);
+// }
+//
+
+// Note: not used anymore
+// /**
+// * Print a message.
+// *
+// * @param key selects message from resource
+// * @param a1 first argument
+// * @param a2 second argument
+// * @param a3 third argument
+// */
+// public void notice(String key, String a1, String a2, String a3) {
+// if (quiet) {
+// return;
+// }
+// messager.notice(key, a1, a2, a3);
+// }
+
+ /**
+ * Exit, reporting errors and warnings.
+ */
+ public void exit() {
+ // Messager should be replaced by a more general
+ // compilation environment. This can probably
+ // subsume DocEnv as well.
+ throw new Messager.ExitJavadoc();
+ }
+
+ /**
+ * Adds all inner classes of this class, and their inner classes recursively, to the list
+ */
+ void addAllClasses(Collection<TypeElement> list, TypeElement typeElement, boolean filtered) {
+ ClassSymbol klass = (ClassSymbol)typeElement;
+ try {
+ if (isSynthetic(klass.flags())) return;
+ // sometimes synthetic classes are not marked synthetic
+ if (!JavadocTool.isValidClassName(klass.name.toString())) return;
+ if (filtered && !shouldDocument(klass)) return;
+ if (list.contains(klass)) return;
+ list.add(klass);
+ for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
+ if (sym != null && sym.kind == Kind.TYP) {
+ ClassSymbol s = (ClassSymbol)sym;
+ if (!isSynthetic(s.flags())) {
+ addAllClasses(list, s, filtered);
+ }
+ }
+ }
+ } catch (CompletionFailure e) {
+ // quietly ignore completion failures
+ }
+ }
+
+ /**
+ * Return a list of all classes contained in this package, including
+ * member classes of those classes, and their member classes, etc.
+ */
+ void addAllClasses(Collection<TypeElement> list, PackageElement pkg) {
+ boolean filtered = true;
+ PackageSymbol sym = (PackageSymbol)pkg;
+ for (Symbol isym : sym.members().getSymbols(NON_RECURSIVE)) {
+ if (isym != null) {
+ ClassSymbol s = (ClassSymbol)isym;
+ if (!isSynthetic(s)) {
+ addAllClasses(list, s, filtered);
+ }
+ }
+ }
+ }
+
+ 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, JCPackageDecl tree) {
+ TreePath p = treePaths.get(tree);
+ if (p == null)
+ treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
+ return p;
+ }
+
+ TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
+ TreePath p = treePaths.get(tree);
+ if (p == null)
+ treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
+ return p;
+ }
+
+ TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) {
+ return new TreePath(getTreePath(toplevel, cdecl), tree);
+ }
+
+ public com.sun.tools.javac.code.Types getTypes() {
+ return types;
+ }
+
+ /**
+ * Set the encoding.
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public Env<AttrContext> getEnv(ClassSymbol tsym) {
+ return enter.getEnv(tsym);
+ }
+
+ /**
+ * Get the encoding.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Convert modifier bits from private coding used by
+ * the compiler to that of java.lang.reflect.Modifier.
+ */
+ static int translateModifiers(long flags) {
+ int result = 0;
+ if ((flags & Flags.ABSTRACT) != 0)
+ result |= Modifier.ABSTRACT;
+ if ((flags & Flags.FINAL) != 0)
+ result |= Modifier.FINAL;
+ if ((flags & Flags.INTERFACE) != 0)
+ result |= Modifier.INTERFACE;
+ if ((flags & Flags.NATIVE) != 0)
+ result |= Modifier.NATIVE;
+ if ((flags & Flags.PRIVATE) != 0)
+ result |= Modifier.PRIVATE;
+ if ((flags & Flags.PROTECTED) != 0)
+ result |= Modifier.PROTECTED;
+ if ((flags & Flags.PUBLIC) != 0)
+ result |= Modifier.PUBLIC;
+ if ((flags & Flags.STATIC) != 0)
+ result |= Modifier.STATIC;
+ if ((flags & Flags.SYNCHRONIZED) != 0)
+ result |= Modifier.SYNCHRONIZED;
+ if ((flags & Flags.TRANSIENT) != 0)
+ result |= Modifier.TRANSIENT;
+ if ((flags & Flags.VOLATILE) != 0)
+ result |= Modifier.VOLATILE;
+ return result;
+ }
+
+ private final Set<Element> includedSet = new HashSet<>();
+
+ public void setIncluded(Element element) {
+ includedSet.add(element);
+ }
+
+ private SimpleElementVisitor9<Boolean, Void> includedVisitor = null;
+
+ public boolean isIncluded(Element e) {
+ if (e == null) {
+ return false;
+ }
+ if (includedVisitor == null) {
+ includedVisitor = new SimpleElementVisitor9<Boolean, Void>() {
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitType(TypeElement e, Void p) {
+ if (includedSet.contains(e)) {
+ return true;
+ }
+ if (shouldDocument(e)) {
+ // Class is nameable from top-level and
+ // the class and all enclosing classes
+ // pass the modifier filter.
+ PackageElement pkg = elements.getPackageOf(e);
+ if (includedSet.contains(pkg)) {
+ setIncluded(e);
+ return true;
+ }
+ Element enclosing = e.getEnclosingElement();
+ if (enclosing != null && includedSet.contains(enclosing)) {
+ setIncluded(e);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitPackage(PackageElement e, Void p) {
+ return includedSet.contains(e);
+ }
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean visitUnknown(Element e, Void p) {
+ throw new AssertionError("unknown element: " + e);
+ }
+
+ @Override @DefinedBy(Api.LANGUAGE_MODEL)
+ public Boolean defaultAction(Element e, Void p) {
+ return visit(e.getEnclosingElement()) && shouldDocument(e);
+ }
+ };
+ }
+ return includedVisitor.visit(e);
+ }
+
+ public boolean isQuiet() {
+ return quiet;
+ }
+
+ /**
+ * A class which filters the access flags on classes, fields, methods, etc.
+ *
+ * <p>
+ * <b>This is NOT part of any supported API. If you write code that depends on this, you do so
+ * at your own risk. This code and its internal interfaces are subject to change or deletion
+ * without notice.</b>
+ *
+ * @see javax.lang.model.element.Modifier
+ * @author Robert Field
+ */
+
+ private static class ModifierFilter {
+
+ static enum FilterFlag {
+ PACKAGE,
+ PRIVATE,
+ PROTECTED,
+ PUBLIC
+ }
+
+ private Set<FilterFlag> oneOf;
+
+ /**
+ * Constructor - Specify a filter.
+ *
+ * @param oneOf a set containing desired flags to be matched.
+ */
+ ModifierFilter(Set<FilterFlag> oneOf) {
+ this.oneOf = oneOf;
+ }
+
+ /**
+ * Constructor - Specify a filter.
+ *
+ * @param oneOf an array containing desired flags to be matched.
+ */
+ ModifierFilter(FilterFlag... oneOf) {
+ this.oneOf = new HashSet<>();
+ this.oneOf.addAll(Arrays.asList(oneOf));
+ }
+
+ static ModifierFilter getModifierFilter(String showAccess) {
+ switch (showAccess) {
+ case "public":
+ return new ModifierFilter(FilterFlag.PUBLIC);
+ case "package":
+ return new ModifierFilter(FilterFlag.PUBLIC, FilterFlag.PROTECTED,
+ FilterFlag.PACKAGE);
+ case "private":
+ return new ModifierFilter(FilterFlag.PRIVATE);
+ default:
+ return new ModifierFilter(FilterFlag.PUBLIC, FilterFlag.PROTECTED);
+ }
+ }
+
+ private boolean hasFlag(long flag, long modifierBits) {
+ return (flag & modifierBits) != 0;
+ }
+
+ private List<FilterFlag> flagsToModifiers(long modifierBits) {
+ List<FilterFlag> list = new ArrayList<>();
+ boolean isPackage = true;
+ if (hasFlag(com.sun.tools.javac.code.Flags.PRIVATE, modifierBits)) {
+ list.add(FilterFlag.PRIVATE);
+ isPackage = false;
+ }
+ if (hasFlag(com.sun.tools.javac.code.Flags.PROTECTED, modifierBits)) {
+ list.add(FilterFlag.PROTECTED);
+ isPackage = false;
+ }
+ if (hasFlag(com.sun.tools.javac.code.Flags.PUBLIC, modifierBits)) {
+ list.add(FilterFlag.PUBLIC);
+ isPackage = false;
+ }
+ if (isPackage) {
+ list.add(FilterFlag.PACKAGE);
+ }
+ return list;
+ }
+
+ /**
+ * Filter on modifier bits.
+ *
+ * @param modifierBits Bits as specified in the Modifier class
+ *
+ * @return Whether the modifierBits pass this filter.
+ */
+ public boolean checkModifier(int modifierBits) {
+ return checkModifier(flagsToModifiers(modifierBits));
+ }
+
+ /**
+ * Filter on Filter flags
+ *
+ * @param modifiers Flags as specified in the FilterFlags enumeration.
+ *
+ * @return if the modifier is contained.
+ */
+ public boolean checkModifier(List<FilterFlag> modifiers) {
+ if (oneOf.contains(FilterFlag.PRIVATE)) {
+ return true;
+ }
+ for (FilterFlag mod : modifiers) {
+ if (oneOf.contains(mod)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ } // end ModifierFilter
+}