# HG changeset patch # User amurillo # Date 1467326349 0 # Node ID 59320a0754e718e114feaebdddd9051c9787623f # Parent f3c3b4447c633efceb19f95e7b5bcb1b5aab0f84# Parent 3a9d6e8c6fde3a1fb87b953e44b85594e5fd99a2 Merge diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor6.java --- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor6.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor6.java Thu Jun 30 22:39:09 2016 +0000 @@ -113,7 +113,7 @@ /** * {@inheritDoc} * - *

The default implementation of this method in {@code + * @implSpec The default implementation of this method in {@code * AbstractAnnotationValueVisitor6} will always throw {@code * UnknownAnnotationValueException}. This behavior is not * required of a subclass. @@ -121,6 +121,7 @@ * @param av {@inheritDoc} * @param p {@inheritDoc} */ + @Override public R visitUnknown(AnnotationValue av, P p) { throw new UnknownAnnotationValueException(av, p); } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java --- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Thu Jun 30 22:39:09 2016 +0000 @@ -118,25 +118,28 @@ /** * {@inheritDoc} * - *

The default implementation of this method in + * @implSpec The default implementation of this method in * {@code AbstractElementVisitor6} will always throw * {@code UnknownElementException}. * This behavior is not required of a subclass. * - * @param e the element to visit - * @param p a visitor-specified parameter + * @param e {@inheritDoc} + * @param p {@inheritDoc} * @return a visitor-specified result * @throws UnknownElementException * a visitor implementation may optionally throw this exception */ + @Override public R visitUnknown(Element e, P p) { throw new UnknownElementException(e, p); } /** - * Visits a {@code ModuleElement} by calling {@code + * {@inheritDoc} + * + * @implSpec Visits a {@code ModuleElement} by calling {@code * visitUnknown}. - + * * @param e {@inheritDoc} * @param p {@inheritDoc} * @return the result of {@code visitUnknown} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java --- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Thu Jun 30 22:39:09 2016 +0000 @@ -114,9 +114,11 @@ } /** - * Visits a {@code UnionType} element by calling {@code + * {@inheritDoc} + * + * @implSpec Visits a {@code UnionType} element by calling {@code * visitUnknown}. - + * * @param t {@inheritDoc} * @param p {@inheritDoc} * @return the result of {@code visitUnknown} @@ -128,15 +130,18 @@ } /** - * Visits an {@code IntersectionType} element by calling {@code + * {@inheritDoc} + * + * @implSpec Visits an {@code IntersectionType} element by calling {@code * visitUnknown}. - + * * @param t {@inheritDoc} * @param p {@inheritDoc} * @return the result of {@code visitUnknown} * * @since 1.8 */ + @Override public R visitIntersection(IntersectionType t, P p) { return visitUnknown(t, p); } @@ -144,16 +149,18 @@ /** * {@inheritDoc} * - *

The default implementation of this method in {@code + * @implSpec The default implementation of this method in {@code * AbstractTypeVisitor6} will always throw {@code * UnknownTypeException}. This behavior is not required of a * subclass. * - * @param t the type to visit + * @param t {@inheritDoc} + * @param p {@inheritDoc} * @return a visitor-specified result * @throws UnknownTypeException * a visitor implementation may optionally throw this exception */ + @Override public R visitUnknown(TypeMirror t, P p) { throw new UnknownTypeException(t, p); } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor7.java --- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor7.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor7.java Thu Jun 30 22:39:09 2016 +0000 @@ -89,5 +89,6 @@ * @param p {@inheritDoc} * @return the result of the visit as defined by a subclass */ + @Override public abstract R visitUnion(UnionType t, P p); } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java --- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java Thu Jun 30 22:39:09 2016 +0000 @@ -88,5 +88,6 @@ * @param p {@inheritDoc} * @return the result of the visit as defined by a subclass */ + @Override public abstract R visitIntersection(IntersectionType t, P p); } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Jun 30 22:39:09 2016 +0000 @@ -1126,10 +1126,13 @@ @Override public Boolean visitWildcardType(WildcardType t, Type s) { - if (s.isPartial()) - return visit(s, t); - else + if (!s.hasTag(WILDCARD)) { return false; + } else { + WildcardType t2 = (WildcardType)s; + return (t.kind == t2.kind || (t.isExtendsBound() && s.isExtendsBound())) && + isSameType(t.type, t2.type, true); + } } @Override diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/InferenceContext.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/InferenceContext.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/InferenceContext.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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,7 +67,7 @@ * This code and its internal interfaces are subject to change or * deletion without notice. */ -class InferenceContext { +public class InferenceContext { /** list of inference vars as undet vars */ List undetvars; @@ -112,6 +112,13 @@ } /** + * returns the list of undetermined variables in this inference context + */ + public List undetVars() { + return undetvars; + } + + /** * returns the list of uninstantiated variables (as type-variables) in this * inference context */ @@ -208,7 +215,7 @@ * undet vars (used ahead of subtyping/compatibility checks to allow propagation * of inference constraints). */ - final Type asUndetVar(Type t) { + public final Type asUndetVar(Type t) { return types.subst(t, inferencevars, undetvars); } @@ -286,7 +293,7 @@ /** * Save the state of this inference context */ - List save() { + public List save() { ListBuffer buf = new ListBuffer<>(); for (Type t : undetvars) { buf.add(((UndetVar)t).dup(infer.types)); @@ -298,7 +305,7 @@ * Consider that the number of saved undetermined variables can be different to the current * amount. This is because new captured variables could have been added. */ - void rollback(List saved_undet) { + public void rollback(List saved_undet) { Assert.check(saved_undet != null); //restore bounds (note: we need to preserve the old instances) ListBuffer newUndetVars = new ListBuffer<>(); diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Thu Jun 30 22:39:09 2016 +0000 @@ -50,6 +50,7 @@ import javax.tools.JavaFileObject.Kind; import javax.tools.StandardLocation; +import com.sun.tools.javac.code.ClassFinder; import com.sun.tools.javac.code.Directive; import com.sun.tools.javac.code.Directive.ExportsDirective; import com.sun.tools.javac.code.Directive.RequiresDirective; @@ -101,6 +102,8 @@ import com.sun.tools.javac.tree.JCTree.JCDirective; import com.sun.tools.javac.tree.JCTree.Tag; +import com.sun.tools.javac.util.Abort; +import com.sun.tools.javac.util.Position; import static com.sun.tools.javac.code.Flags.ABSTRACT; import static com.sun.tools.javac.code.Flags.ENUM; @@ -217,6 +220,9 @@ for (ModuleSymbol msym: roots) { msym.complete(); } + } catch (CompletionFailure ex) { + log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue()); + if (ex instanceof ClassFinder.BadClassFile) throw new Abort(); } finally { depth--; } @@ -503,7 +509,9 @@ for (ModuleSymbol ms : allModules()) { if (ms == syms.unnamedModule || ms == msym) continue; - RequiresDirective d = new RequiresDirective(ms, EnumSet.of(RequiresFlag.PUBLIC)); + Set flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ? + EnumSet.of(RequiresFlag.PUBLIC) : EnumSet.noneOf(RequiresFlag.class); + RequiresDirective d = new RequiresDirective(ms, flags); directives.add(d); requires.add(d); } @@ -1000,29 +1008,19 @@ Set readable = new LinkedHashSet<>(); Set requiresPublic = new HashSet<>(); - if ((msym.flags() & Flags.AUTOMATIC_MODULE) == 0) { - for (RequiresDirective d : msym.requires) { - d.module.complete(); - readable.add(d.module); - Set s = retrieveRequiresPublic(d.module); - Assert.checkNonNull(s, () -> "no entry in cache for " + d.module); - readable.addAll(s); - if (d.flags.contains(RequiresFlag.PUBLIC)) { - requiresPublic.add(d.module); - requiresPublic.addAll(s); - } + + for (RequiresDirective d : msym.requires) { + d.module.complete(); + readable.add(d.module); + Set s = retrieveRequiresPublic(d.module); + Assert.checkNonNull(s, () -> "no entry in cache for " + d.module); + readable.addAll(s); + if (d.flags.contains(RequiresFlag.PUBLIC)) { + requiresPublic.add(d.module); + requiresPublic.addAll(s); } - } else { - //the module graph may contain cycles involving automatic modules - //handle automatic modules separatelly: - Set s = retrieveRequiresPublic(msym); + } - readable.addAll(s); - requiresPublic.addAll(s); - - //ensure the unnamed module is added (it is not requires public): - readable.add(syms.unnamedModule); - } requiresPublicCache.put(msym, requiresPublic); initVisiblePackages(msym, readable); for (ExportsDirective d: msym.exports) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java Thu Jun 30 22:39:09 2016 +0000 @@ -25,10 +25,8 @@ package com.sun.tools.javac.file; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.lang.ref.SoftReference; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -43,7 +41,6 @@ import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -65,7 +62,6 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy.Api; -import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Options; @@ -334,8 +330,7 @@ private String defaultEncodingName; private String getDefaultEncodingName() { if (defaultEncodingName == null) { - defaultEncodingName = - new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); + defaultEncodingName = Charset.defaultCharset().name(); } return defaultEncodingName; } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Jun 30 22:39:09 2016 +0000 @@ -2418,6 +2418,9 @@ // reset and read rest of classinfo bp = startbp; int n = nextChar(); + if ((flags & MODULE) != 0 && n > 0) { + throw badClassFile("module.info.invalid.super.class"); + } if (ct.supertype_field == null) ct.supertype_field = (n == 0) ? Type.noType diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Jun 30 22:39:09 2016 +0000 @@ -1605,7 +1605,7 @@ /** * Convert import-style string for supported annotations into a - * regex matching that string. If the string is a valid + * regex matching that string. If the string is not a valid * import-style string, return a regex that won't match anything. */ private static Pattern importStringToPattern(String s, Processor p, Log log) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jun 30 22:39:09 2016 +0000 @@ -1850,6 +1850,9 @@ compiler.misc.class.file.wrong.class=\ class file contains wrong class: {0} +compiler.misc.module.info.invalid.super.class=\ + module-info with invalid super class + compiler.misc.class.file.not.found=\ class file for {0} not found diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java Thu Jun 30 22:39:09 2016 +0000 @@ -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); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java Thu Jun 30 22:39:09 2016 +0000 @@ -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); diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConfigurationImpl.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConfigurationImpl.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConfigurationImpl.java Thu Jun 30 22:39:09 2016 +0000 @@ -360,10 +360,10 @@ if (!validateOptions()) { return false; } - if (!root.getSpecifiedElements().isEmpty()) { + if (!docEnv.getSpecifiedElements().isEmpty()) { Map map = new HashMap<>(); PackageElement pkg; - List classes = new ArrayList<>(root.getIncludedClasses()); + List 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 diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java Thu Jun 30 22:39:09 2016 +0000 @@ -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()) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageFrameWriter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageFrameWriter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageFrameWriter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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()); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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(); } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java Thu Jun 30 22:39:09 2016 +0000 @@ -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); diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java Thu Jun 30 22:39:09 2016 +0000 @@ -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(); } /** diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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()) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java Thu Jun 30 22:39:09 2016 +0000 @@ -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; diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 makePropertyDescriptionTree(List content) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 s = modulePackages.get(mdle); if (s == null) diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 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 interfaceTypesOf(TypeMirror type) { com.sun.tools.javac.util.List 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 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 compenv = env.getEnv(tsym); + Env 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 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 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. diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java Thu Jun 30 22:39:09 2016 +0000 @@ -125,7 +125,7 @@ */ public void build() throws IOException { SortedSet rootclasses = new TreeSet<>(utils.makeGeneralPurposeComparator()); - rootclasses.addAll(configuration.root.getIncludedClasses()); + rootclasses.addAll(configuration.docEnv.getIncludedClasses()); if (!serialClassFoundToDocument(rootclasses)) { //Nothing to document. return; diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java Thu Jun 30 22:39:09 2016 +0000 @@ -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]; } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassTree.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassTree.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassTree.java Thu Jun 30 22:39:09 2016 +0000 @@ -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()); } /** diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java Thu Jun 30 22:39:09 2016 +0000 @@ -187,15 +187,15 @@ */ public final Map> 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 classes = root.getIncludedClasses(); + Set classes = docEnv.getIncludedClasses(); for (TypeElement aClass : classes) { PackageElement pkg = elementUtils.getPackageOf(aClass); mapAnnotations(classToPackageAnnotations, pkg, pkg); diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 getFirstSentenceTrees(Configuration c, List body) { - List firstSentence = c.root.getDocTrees().getFirstSentence(body); + List firstSentence = c.docEnv.getDocTrees().getFirstSentence(body); return firstSentence; } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DeprecatedAPIListBuilder.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DeprecatedAPIListBuilder.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DeprecatedAPIListBuilder.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 eset; if (utils.isDeprecated(e)) { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java Thu Jun 30 22:39:09 2016 +0000 @@ -110,7 +110,7 @@ comparator = classesOnly ? utils.makeAllClassesComparator() : utils.makeIndexUseComparator(); - buildIndexMap(configuration.root); + buildIndexMap(configuration.docEnv); } /** diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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", diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 getSpecifiedClasses() { @@ -2571,7 +2571,7 @@ } public boolean isIncluded(Element e) { - return configuration.root.isIncluded(e); + return configuration.docEnv.isIncluded(e); } /** diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnv.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnv.java Thu Jun 30 22:10:11 2016 +0000 +++ /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. - * - *

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. - * - * @author Robert Field - * @author Neal Gafter (rewrite) - * @author Scott Seligman (generics) - */ -public class DocEnv { - protected static final Context.Key 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 treePaths = new WeakHashMap<>(); - - public final HashMap 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 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 javaNames, - Iterable fileObjects, - List subPackages, - List 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 shouldDocumentVisitor = null; - public boolean shouldDocument(Element e) { - if (shouldDocumentVisitor == null) { - shouldDocumentVisitor = new SimpleElementVisitor9() { - - @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 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 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 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 includedSet = new HashSet<>(); - - public void setIncluded(Element element) { - includedSet.add(element); - } - - private SimpleElementVisitor9 includedVisitor = null; - - public boolean isIncluded(Element e) { - if (e == null) { - return false; - } - if (includedVisitor == null) { - includedVisitor = new SimpleElementVisitor9() { - @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. - * - *

- * 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. - * - * @see javax.lang.model.element.Modifier - * @author Robert Field - */ - - private static class ModifierFilter { - - static enum FilterFlag { - PACKAGE, - PRIVATE, - PROTECTED, - PUBLIC - } - - private Set oneOf; - - /** - * Constructor - Specify a filter. - * - * @param oneOf a set containing desired flags to be matched. - */ - ModifierFilter(Set 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 flagsToModifiers(long modifierBits) { - List 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 modifiers) { - if (oneOf.contains(FilterFlag.PRIVATE)) { - return true; - } - for (FilterFlag mod : modifiers) { - if (oneOf.contains(mod)) { - return true; - } - } - return false; - } - - } // end ModifierFilter -} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnvImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/DocEnvImpl.java Thu Jun 30 22:39:09 2016 +0000 @@ -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. + * + *

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. + * + * @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 cmdLineClasses; + + /** + * list of packages specified on the command line. + */ + private Set 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 classes, List 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 classes) { + //super(env, null); + this.toolEnv = toolEnv; + + Set 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 classes) { + Set 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 packages) { + Set 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 specifiedPackages() { + return cmdLinePackages; + } + + /** + * Classes and interfaces specified on the command line, + * including their inner classes + */ + public Set specifiedClasses() { + Set out = new LinkedHashSet<>(); + cmdLineClasses.stream().forEach((te) -> { + toolEnv.addAllClasses(out, te, true); + }); + return out; + } + + private Set classesToDocument = null; + /** + * Return all classes and interfaces (including those inside + * packages) to be documented. + */ + public Set getIncludedClasses() { + if (classesToDocument == null) { + Set 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 "*RootDocImpl*". + */ + public String name() { + return "*RootDocImpl*"; + } + + /** + * Return the name of this Doc item. + * + * @return the string "*RootDocImpl*". + */ + 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 getSelectedElements(List elements) { + return elements.stream() + .filter(e -> isIncluded(e)) + .collect(Collectors.toList()); + } + + @Override + public Set getSpecifiedElements() { + Set 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); + } +} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocClassFinder.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocClassFinder.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocClassFinder.java Thu Jun 30 22:39:09 2016 +0000 @@ -60,7 +60,7 @@ }); } - private DocEnv docenv; + private ToolEnvironment toolEnv; private EnumSet 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 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); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 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)); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocMemberEnter.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocMemberEnter.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocMemberEnter.java Thu Jun 30 22:39:09 2016 +0000 @@ -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)); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java Thu Jun 30 22:39:09 2016 +0000 @@ -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 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 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 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 packageTrees = new ListBuffer<>(); for (String packageName: includedPackages) { List 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)); } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/RootDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/RootDocImpl.java Thu Jun 30 22:10:11 2016 +0000 +++ /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. - * - *

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. - * - * @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 cmdLineClasses; - - /** - * list of packages specified on the command line. - */ - private Set 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 classes, List 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 classes) { - //super(env, null); - this.env = env; - - Set 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 classes) { - Set 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 packages) { - Set 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 specifiedPackages() { - return cmdLinePackages; - } - - /** - * Classes and interfaces specified on the command line, - * including their inner classes - */ - public Set specifiedClasses() { - Set out = new LinkedHashSet<>(); - cmdLineClasses.stream().forEach((te) -> { - env.addAllClasses(out, te, true); - }); - return out; - } - - private Set classesToDocument = null; - /** - * Return all classes and interfaces (including those inside - * packages) to be documented. - */ - public Set getIncludedClasses() { - if (classesToDocument == null) { - Set 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 "*RootDocImpl*". - */ - public String name() { - return "*RootDocImpl*"; - } - - /** - * Return the name of this Doc item. - * - * @return the string "*RootDocImpl*". - */ - 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 getSelectedElements(List elements) { - return elements.stream() - .filter(e -> isIncluded(e)) - .collect(Collectors.toList()); - } - - @Override - public Set getSpecifiedElements() { - Set 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); - } -} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java Thu Jun 30 22:39:09 2016 +0000 @@ -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. + * + *

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. + * + * @author Robert Field + * @author Neal Gafter (rewrite) + * @author Scott Seligman (generics) + */ +public class ToolEnvironment { + protected static final Context.Key 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 treePaths = new WeakHashMap<>(); + + public final HashMap 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 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 javaNames, + Iterable fileObjects, + List subPackages, + List 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 shouldDocumentVisitor = null; + public boolean shouldDocument(Element e) { + if (shouldDocumentVisitor == null) { + shouldDocumentVisitor = new SimpleElementVisitor9() { + + @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 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 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 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 includedSet = new HashSet<>(); + + public void setIncluded(Element element) { + includedSet.add(element); + } + + private SimpleElementVisitor9 includedVisitor = null; + + public boolean isIncluded(Element e) { + if (e == null) { + return false; + } + if (includedVisitor == null) { + includedVisitor = new SimpleElementVisitor9() { + @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. + * + *

+ * 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. + * + * @see javax.lang.model.element.Modifier + * @author Robert Field + */ + + private static class ModifierFilter { + + static enum FilterFlag { + PACKAGE, + PRIVATE, + PROTECTED, + PUBLIC + } + + private Set oneOf; + + /** + * Constructor - Specify a filter. + * + * @param oneOf a set containing desired flags to be matched. + */ + ModifierFilter(Set 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 flagsToModifiers(long modifierBits) { + List 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 modifiers) { + if (oneOf.contains(FilterFlag.PRIVATE)) { + return true; + } + for (FilterFlag mod : modifiers) { + if (oneOf.contains(mod)) { + return true; + } + } + return false; + } + + } // end ModifierFilter +} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/ProblemList.txt --- a/langtools/test/ProblemList.txt Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/ProblemList.txt Thu Jun 30 22:39:09 2016 +0000 @@ -76,6 +76,7 @@ tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java 8057687 generic-all emit correct byte code an attributes for type annotations tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java 8057687 generic-all emit correct byte code an attributes for type annotations tools/javac/warnings/suppress/TypeAnnotations.java 8057683 generic-all improve ordering of errors with type annotations +tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java 8160396 generic-all current version of jtreg needs a new promotion to include lastes version of ASM ########################################################################### # diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/T8159970/TypeEqualityInInferenceTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/T8159970/TypeEqualityInInferenceTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +/* + * @test + * @bug 8159970 + * @summary javac, JLS8 18.2.4 is not completely implemented by the compiler + * @library /tools/lib/types + * @modules jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.code + * jdk.compiler/com.sun.tools.javac.comp + * jdk.compiler/com.sun.tools.javac.tree + * jdk.compiler/com.sun.tools.javac.util + * jdk.compiler/com.sun.tools.javac.file + * @build TypeHarness + * @run main TypeEqualityInInferenceTest + */ + +import java.util.ArrayList; +import java.util.List; + +import com.sun.tools.javac.code.Type; +import com.sun.tools.javac.code.Type.UndetVar; +import com.sun.tools.javac.code.Type.UndetVar.InferenceBound; +import com.sun.tools.javac.util.Assert; + +public class TypeEqualityInInferenceTest extends TypeHarness { + StrToTypeFactory strToTypeFactory; + + public static void main(String... args) throws Exception { + new TypeEqualityInInferenceTest().runAll(); + } + + void runAll() { + List imports = new ArrayList<>(); + imports.add("java.util.*"); + List typeVars = new ArrayList<>(); + typeVars.add("T"); + strToTypeFactory = new StrToTypeFactory(null, imports, typeVars); + + runTest("List", "List", predef.stringType); + runTest("List", "List", predef.objectType); + runTest("List", "List", predef.stringType); + } + + void runTest(String freeTypeStr, String typeStr, Type equalityBoundType) { + Type freeType = strToTypeFactory.getType(freeTypeStr); + Type aType = strToTypeFactory.getType(typeStr); + + withInferenceContext(strToTypeFactory.getTypeVars(), inferenceContext -> { + assertSameType(inferenceContext.asUndetVar(freeType), aType); + UndetVar undetVarForT = (UndetVar)inferenceContext.undetVars().head; + checkEqualityBound(undetVarForT, equalityBoundType); + }); + + withInferenceContext(strToTypeFactory.getTypeVars(), inferenceContext -> { + assertSameType(aType, inferenceContext.asUndetVar(freeType)); + UndetVar undetVarForT = (UndetVar)inferenceContext.undetVars().head; + checkEqualityBound(undetVarForT, equalityBoundType); + }); + } + + void checkEqualityBound(UndetVar uv, Type boundType) { + com.sun.tools.javac.util.List equalBounds = uv.getBounds(InferenceBound.EQ); + Assert.check(!equalBounds.isEmpty() && equalBounds.length() == 1, + "undetVar must have only one equality bound"); + Type bound = equalBounds.head; + Assert.check(bound == boundType, "equal bound must be of type " + boundType); + } +} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/diags/examples.not-yet.txt --- a/langtools/test/tools/javac/diags/examples.not-yet.txt Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/diags/examples.not-yet.txt Thu Jun 30 22:39:09 2016 +0000 @@ -120,6 +120,7 @@ compiler.misc.bad.module-info.name # bad class file compiler.err.locn.bad.module-info # bad class file compiler.err.locn.cant.read.file # bad class file +compiler.misc.module.info.invalid.super.class # bad class file compiler.err.locn.cant.read.directory # file system issue compiler.misc.unnamed.module # fragment uninteresting in and of itself compiler.misc.kindname.module # fragment uninteresting in and of itself diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/file/T8132857.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/file/T8132857.java Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +/** + * @test + * @bug 8132857 + * @summary Verify an up-to-date name for UTF-8 encoding is provided in error messages. + * @modules jdk.compiler + */ + +import java.io.*; +import java.nio.charset.Charset; + +public class T8132857 { + public static void main(String... args) throws Exception{ + new T8132857().run(); + } + + void run() throws IOException { + if (!Charset.defaultCharset().equals(Charset.forName("UTF-8"))) { + System.err.println("skipping test, default charset is not UTF-8"); + return; + } + + File src = new File("src"); + src.mkdirs(); + try (OutputStream out = new FileOutputStream(new File(src, "Test.java"))) { + out.write('/'); + out.write('/'); + out.write(0b1100_0000); + out.write('a'); + } + + try (StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out)) { + int rc = com.sun.tools.javac.Main.compile(new String[] {"-XDrawDiagnostics", "src/Test.java"}, pw); + + pw.flush(); + + String lineSeparator = System.getProperty("line.separator"); + String expected = + "Test.java:1:3: compiler.err.illegal.char.for.encoding: C0, UTF-8" + lineSeparator + + "1 error" + lineSeparator; + String actual = out.toString(); + + System.err.println(actual); + + if (rc == 0) { + throw new Error("compilation unexpectedly passed: " + rc); + } + + if (!expected.equals(actual)) { + throw new Error("unexpected output: " + actual); + } + } + } + +} + diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/modules/AutomaticModules.java --- a/langtools/test/tools/javac/modules/AutomaticModules.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/modules/AutomaticModules.java Thu Jun 30 22:39:09 2016 +0000 @@ -23,9 +23,11 @@ /** * @test + * @bug 8155026 * @summary Test automatic modules * @library /tools/lib * @modules + * java.desktop * jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * @build toolbox.ToolBox toolbox.JavacTask toolbox.JarTask ModuleTestBase @@ -34,11 +36,12 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; import toolbox.JarTask; import toolbox.JavacTask; import toolbox.Task; -import toolbox.ToolBox; public class AutomaticModules extends ModuleTestBase { @@ -86,11 +89,11 @@ Files.createDirectories(classes); tb.writeJavaFiles(m1, - "module m1 { requires test.api; }", + "module m1 { requires test.api; requires java.desktop; }", "package impl; public class Impl { public void e(api.Api api) { api.actionPerformed(null); } }"); new JavacTask(tb) - .options("-modulesourcepath", moduleSrc.toString(), "-modulepath", modulePath.toString(), "-addmods", "java.desktop") + .options("-modulesourcepath", moduleSrc.toString(), "-modulepath", modulePath.toString()) .outdir(classes) .files(findJavaFiles(moduleSrc)) .run() @@ -224,4 +227,85 @@ .run() .writeAll(); } + + @Test + public void testAutomaticAndNamedModules(Path base) throws Exception { + Path modulePath = base.resolve("module-path"); + + Files.createDirectories(modulePath); + + for (char c : new char[] {'A', 'B'}) { + Path automaticSrc = base.resolve("automaticSrc" + c); + tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}"); + Path automaticClasses = base.resolve("automaticClasses" + c); + tb.createDirectories(automaticClasses); + + String automaticLog = new JavacTask(tb) + .outdir(automaticClasses) + .files(findJavaFiles(automaticSrc)) + .run() + .writeAll() + .getOutput(Task.OutputKind.DIRECT); + + if (!automaticLog.isEmpty()) + throw new Exception("expected output not found: " + automaticLog); + + Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar"); + + new JarTask(tb, automaticJar) + .baseDir(automaticClasses) + .files("api" + c + "/Api.class") + .run(); + } + + Path moduleSrc = base.resolve("module-src"); + + tb.writeJavaFiles(moduleSrc.resolve("m1"), + "module m1 { requires automaticA; }", + "package impl; public class Impl { apiA.Api a; apiB.Api b; m2.M2 m;}"); + + tb.writeJavaFiles(moduleSrc.resolve("m2"), + "module m2 { exports m2; }", + "package m2; public class M2 { }"); + + Path classes = base.resolve("classes"); + + Files.createDirectories(classes); + + List log = new JavacTask(tb) + .options("-modulesourcepath", moduleSrc.toString(), + "-modulepath", modulePath.toString(), + "-addmods", "automaticB", + "-XDrawDiagnostics") + .outdir(classes) + .files(findJavaFiles(moduleSrc)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expected = Arrays.asList("Impl.java:1:61: compiler.err.not.def.access.package.cant.access: m2.M2, m2", + "1 error"); + + if (!expected.equals(log)) { + throw new Exception("expected output not found: " + log); + } + + log = new JavacTask(tb) + .options("-modulesourcepath", moduleSrc.toString(), + "-modulepath", modulePath.toString(), + "-XDrawDiagnostics") + .outdir(classes) + .files(findJavaFiles(moduleSrc)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + expected = Arrays.asList("Impl.java:1:51: compiler.err.doesnt.exist: apiB", + "Impl.java:1:61: compiler.err.not.def.access.package.cant.access: m2.M2, m2", + "2 errors"); + + if (!expected.equals(log)) { + throw new Exception("expected output not found: " + log); + } + } } diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8159439 + * @summary javac throws NPE with Module attribute and super_class != 0 + * @build module-info + * @compile/fail/ref=NPEForModuleInfoWithNonZeroSuperClassTest.out -XDrawDiagnostics NPEForModuleInfoWithNonZeroSuperClassTest.java + */ + +class NPEForModuleInfoWithNonZeroSuperClassTest {} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/modules/T8159439/NPEForModuleInfoWithNonZeroSuperClassTest.out Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,2 @@ +- compiler.err.cant.access: mod.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.info.invalid.super.class)) +1 error diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/modules/T8159439/module-info.jcod --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/modules/T8159439/module-info.jcod Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,55 @@ +module mod { + 0xCAFEBABE; + 0; // minor version + 53; // version + [] { // Constant Pool + ; // first element is empty + Utf8 "mod/module-info"; // #1 + class #1; // #2 + Utf8 "java/lang/Object"; // #3 + class #3; // #4 + Utf8 "java.base"; // #5 + Utf8 "pkg"; // #6 + Utf8 "Module"; // #7 + Utf8 "Version"; // #8 + Utf8 "6.0"; // #9 + } // Constant Pool + + 0x8000; // access + #2;// this_cpx + #4;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + } // methods + + [] { // Attributes + Attr(#7) { // Module + [] { // requires + #5 0x8020; + } // requires + + [] { // exports + #6 + [] { // to + }; // end to + } // exports + + [] { // uses + } // uses + + [] { // provides + } // provides + + } // end Module + ; + Attr(#8) { // Version + 0x0009; + } // end Version + } // Attributes +} // end module mod diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/BoxingConversionTest.java --- a/langtools/test/tools/javac/types/BoxingConversionTest.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/types/BoxingConversionTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -26,17 +26,18 @@ * @bug 7006109 * @summary Add test library to simplify the task of writing automated type-system tests * @author mcimadamore - * @library . + * @library /tools/lib/types * @modules jdk.compiler/com.sun.tools.javac.code * jdk.compiler/com.sun.tools.javac.comp * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util + * jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.tree + * @build TypeHarness * @run main BoxingConversionTest */ import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.Type.*; -import com.sun.tools.javac.code.Symbol.*; import java.lang.reflect.Array; import java.util.EnumSet; diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/CastTest.java --- a/langtools/test/tools/javac/types/CastTest.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/types/CastTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -26,11 +26,14 @@ * @bug 7006109 * @summary Add test library to simplify the task of writing automated type-system tests * @author mcimadamore - * @library . + * @library /tools/lib/types * @modules jdk.compiler/com.sun.tools.javac.code * jdk.compiler/com.sun.tools.javac.comp * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util + * jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.tree + * @build TypeHarness * @run main CastTest */ diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/GenericTypeWellFormednessTest.java --- a/langtools/test/tools/javac/types/GenericTypeWellFormednessTest.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/types/GenericTypeWellFormednessTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -26,11 +26,14 @@ * @bug 7007432 7006109 * @summary Test generic types well-formedness * @author mcimadamore - * @library . + * @library /tools/lib/types * @modules jdk.compiler/com.sun.tools.javac.code * jdk.compiler/com.sun.tools.javac.comp * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util + * jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.tree + * @build TypeHarness * @run main GenericTypeWellFormednessTest */ diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/PrimitiveConversionTest.java --- a/langtools/test/tools/javac/types/PrimitiveConversionTest.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/types/PrimitiveConversionTest.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -26,17 +26,19 @@ * @bug 7006109 * @summary Add test library to simplify the task of writing automated type-system tests * @author mcimadamore - * @library . + * @library /tools/lib/types * @modules jdk.compiler/com.sun.tools.javac.code * jdk.compiler/com.sun.tools.javac.comp * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util + * jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.tree + * @build TypeHarness * @run main PrimitiveConversionTest */ import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.*; -import com.sun.tools.javac.code.Symbol.*; import java.lang.reflect.Array; import java.util.EnumSet; diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/TestComparisons.java --- a/langtools/test/tools/javac/types/TestComparisons.java Thu Jun 30 22:10:11 2016 +0000 +++ b/langtools/test/tools/javac/types/TestComparisons.java Thu Jun 30 22:39:09 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -29,8 +29,6 @@ */ import java.io.*; -import java.lang.reflect.Array; -import java.util.EnumSet; public class TestComparisons { diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/javac/types/TypeHarness.java --- a/langtools/test/tools/javac/types/TypeHarness.java Thu Jun 30 22:10:11 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,333 +0,0 @@ -/* - * Copyright (c) 2010, 2013, 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. - * - * 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. - */ - -import com.sun.tools.javac.code.BoundKind; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.code.Types; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.Type.*; -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.comp.Check; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.ListBuffer; -import com.sun.tools.javac.util.Name; -import com.sun.tools.javac.util.Names; -import com.sun.tools.javac.file.JavacFileManager; - -/** - * Test harness whose goal is to simplify the task of writing type-system - * regression test. It provides functionalities to build custom types as well - * as to access the underlying javac's symbol table in order to retrieve - * predefined types. Among the features supported by the harness are: type - * substitution, type containment, subtyping, cast-conversion, assigment - * conversion. - * - * This class is meant to be a common super class for all concrete type test - * classes. A subclass can access the type-factory and the test methods so as - * to write compact tests. An example is reported below: - * - *

- * Type X = fac.TypeVariable();
- * Type Y = fac.TypeVariable();
- * Type A_X_Y = fac.Class(0, X, Y);
- * Type A_Obj_Obj = fac.Class(0,
- *           predef.objectType,
- *           predef.objectType);
- * checkSameType(A_Obj_Obj, subst(A_X_Y,
- *           Mapping(X, predef.objectType),
- *           Mapping(Y, predef.objectType)));
- * 
- * - * The above code is used to create two class types, namely {@code A} and - * {@code A} where both {@code X} and {@code Y} are type-variables. - * The code then verifies that {@code [X:=Object,Y:=Object]A == A}. - * - * @author mcimadamore - */ -public class TypeHarness { - - protected Types types; - protected Check chk; - protected Symtab predef; - protected Names names; - protected Factory fac; - - protected TypeHarness() { - Context ctx = new Context(); - JavacFileManager.preRegister(ctx); - types = Types.instance(ctx); - chk = Check.instance(ctx); - predef = Symtab.instance(ctx); - names = Names.instance(ctx); - fac = new Factory(); - } - - // - - /** assert that 's' is a subtype of 't' */ - public void assertSubtype(Type s, Type t) { - assertSubtype(s, t, true); - } - - /** assert that 's' is/is not a subtype of 't' */ - public void assertSubtype(Type s, Type t, boolean expected) { - if (types.isSubtype(s, t) != expected) { - String msg = expected ? - " is not a subtype of " : - " is a subtype of "; - error(s + msg + t); - } - } - - /** assert that 's' is the same type as 't' */ - public void assertSameType(Type s, Type t) { - assertSameType(s, t, true); - } - - /** assert that 's' is/is not the same type as 't' */ - public void assertSameType(Type s, Type t, boolean expected) { - if (types.isSameType(s, t) != expected) { - String msg = expected ? - " is not the same type as " : - " is the same type as "; - error(s + msg + t); - } - } - - /** assert that 's' is castable to 't' */ - public void assertCastable(Type s, Type t) { - assertCastable(s, t, true); - } - - /** assert that 's' is/is not castable to 't' */ - public void assertCastable(Type s, Type t, boolean expected) { - if (types.isCastable(s, t) != expected) { - String msg = expected ? - " is not castable to " : - " is castable to "; - error(s + msg + t); - } - } - - /** assert that 's' is convertible (method invocation conversion) to 't' */ - public void assertConvertible(Type s, Type t) { - assertCastable(s, t, true); - } - - /** assert that 's' is/is not convertible (method invocation conversion) to 't' */ - public void assertConvertible(Type s, Type t, boolean expected) { - if (types.isConvertible(s, t) != expected) { - String msg = expected ? - " is not convertible to " : - " is convertible to "; - error(s + msg + t); - } - } - - /** assert that 's' is assignable to 't' */ - public void assertAssignable(Type s, Type t) { - assertCastable(s, t, true); - } - - /** assert that 's' is/is not assignable to 't' */ - public void assertAssignable(Type s, Type t, boolean expected) { - if (types.isAssignable(s, t) != expected) { - String msg = expected ? - " is not assignable to " : - " is assignable to "; - error(s + msg + t); - } - } - - /** assert that generic type 't' is well-formed */ - public void assertValidGenericType(Type t) { - assertValidGenericType(t, true); - } - - /** assert that 's' is/is not assignable to 't' */ - public void assertValidGenericType(Type t, boolean expected) { - if (chk.checkValidGenericType(t) != expected) { - String msg = expected ? - " is not a valid generic type" : - " is a valid generic type"; - error(t + msg + " " + t.tsym.type); - } - } - // - - private void error(String msg) { - throw new AssertionError("Unexpected result: " + msg); - } - - // - - /** compute the erasure of a type 't' */ - public Type erasure(Type t) { - return types.erasure(t); - } - - /** compute the capture of a type 't' */ - public Type capture(Type t) { - return types.capture(t); - } - - /** compute the boxed type associated with 't' */ - public Type box(Type t) { - if (!t.isPrimitive()) { - throw new AssertionError("Cannot box non-primitive type: " + t); - } - return types.boxedClass(t).type; - } - - /** compute the unboxed type associated with 't' */ - public Type unbox(Type t) { - Type u = types.unboxedType(t); - if (t == null) { - throw new AssertionError("Cannot unbox reference type: " + t); - } else { - return u; - } - } - - /** compute a type substitution on 't' given a list of type mappings */ - public Type subst(Type t, Mapping... maps) { - ListBuffer from = new ListBuffer<>(); - ListBuffer to = new ListBuffer<>(); - for (Mapping tm : maps) { - from.append(tm.from); - to.append(tm.to); - } - return types.subst(t, from.toList(), to.toList()); - } - - /** create a fresh type mapping from a type to another */ - public Mapping Mapping(Type from, Type to) { - return new Mapping(from, to); - } - - public static class Mapping { - Type from; - Type to; - private Mapping(Type from, Type to) { - this.from = from; - this.to = to; - } - } - // - - // - - /** - * This class is used to create Java types in a simple way. All main - * kinds of type are supported: primitive, reference, non-denotable. The - * factory also supports creation of constant types (used by the compiler - * to represent the type of a literal). - */ - public class Factory { - - private int synthNameCount = 0; - - private Name syntheticName() { - return names.fromString("A$" + synthNameCount++); - } - - public ClassType Class(long flags, Type... typeArgs) { - ClassSymbol csym = new ClassSymbol(flags, syntheticName(), predef.noSymbol); - csym.type = new ClassType(Type.noType, List.from(typeArgs), csym); - ((ClassType)csym.type).supertype_field = predef.objectType; - return (ClassType)csym.type; - } - - public ClassType Class(Type... typeArgs) { - return Class(0, typeArgs); - } - - public ClassType Interface(Type... typeArgs) { - return Class(Flags.INTERFACE, typeArgs); - } - - public ClassType Interface(long flags, Type... typeArgs) { - return Class(Flags.INTERFACE | flags, typeArgs); - } - - public Type Constant(byte b) { - return predef.byteType.constType(b); - } - - public Type Constant(short s) { - return predef.shortType.constType(s); - } - - public Type Constant(int i) { - return predef.intType.constType(i); - } - - public Type Constant(long l) { - return predef.longType.constType(l); - } - - public Type Constant(float f) { - return predef.floatType.constType(f); - } - - public Type Constant(double d) { - return predef.doubleType.constType(d); - } - - public Type Constant(char c) { - return predef.charType.constType(c + 0); - } - - public ArrayType Array(Type elemType) { - return new ArrayType(elemType, predef.arrayClass); - } - - public TypeVar TypeVariable() { - return TypeVariable(predef.objectType); - } - - public TypeVar TypeVariable(Type bound) { - TypeSymbol tvsym = new TypeVariableSymbol(0, syntheticName(), null, predef.noSymbol); - tvsym.type = new TypeVar(tvsym, bound, null); - return (TypeVar)tvsym.type; - } - - public WildcardType Wildcard(BoundKind bk, Type bound) { - return new WildcardType(bound, bk, predef.boundClass); - } - - public CapturedType CapturedVariable(Type upper, Type lower) { - return new CapturedType(syntheticName(), predef.noSymbol, upper, lower, null); - } - - public ClassType Intersection(Type classBound, Type... intfBounds) { - ClassType ct = Class(Flags.COMPOUND); - ct.supertype_field = classBound; - ct.interfaces_field = List.from(intfBounds); - return ct; - } - } - // -} diff -r f3c3b4447c63 -r 59320a0754e7 langtools/test/tools/lib/types/TypeHarness.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/lib/types/TypeHarness.java Thu Jun 30 22:39:09 2016 +0000 @@ -0,0 +1,540 @@ +/* + * Copyright (c) 2010, 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. + * + * 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. + */ + +import java.net.URI; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; + +import com.sun.tools.javac.code.BoundKind; +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.code.Symtab; +import com.sun.tools.javac.code.Type; +import com.sun.tools.javac.code.Type.*; +import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.comp.Attr; +import com.sun.tools.javac.comp.Check; +import com.sun.tools.javac.comp.Infer; +import com.sun.tools.javac.comp.InferenceContext; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Names; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.main.JavaCompiler; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.util.Abort; +import com.sun.tools.javac.util.Assert; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; + +import static com.sun.tools.javac.util.List.*; + +/** + * Test harness whose goal is to simplify the task of writing type-system + * regression test. It provides functionalities to build custom types as well + * as to access the underlying javac's symbol table in order to retrieve + * predefined types. Among the features supported by the harness are: type + * substitution, type containment, subtyping, cast-conversion, assigment + * conversion. + * + * This class is meant to be a common super class for all concrete type test + * classes. A subclass can access the type-factory and the test methods so as + * to write compact tests. An example is reported below: + * + *
+ * Type X = fac.TypeVariable();
+ * Type Y = fac.TypeVariable();
+ * Type A_X_Y = fac.Class(0, X, Y);
+ * Type A_Obj_Obj = fac.Class(0,
+ *           predef.objectType,
+ *           predef.objectType);
+ * checkSameType(A_Obj_Obj, subst(A_X_Y,
+ *           Mapping(X, predef.objectType),
+ *           Mapping(Y, predef.objectType)));
+ * 
+ * + * The above code is used to create two class types, namely {@code A} and + * {@code A} where both {@code X} and {@code Y} are type-variables. + * The code then verifies that {@code [X:=Object,Y:=Object]A == A}. + * + * @author mcimadamore + */ +public class TypeHarness { + + protected Types types; + protected Check chk; + protected Symtab predef; + protected Names names; + protected ReusableJavaCompiler tool; + protected Infer infer; + + protected Factory fac; + + protected TypeHarness() { + Context ctx = new Context(); + JavacFileManager.preRegister(ctx); + MyAttr.preRegister(ctx); + tool = new ReusableJavaCompiler(ctx); + types = Types.instance(ctx); + infer = Infer.instance(ctx); + chk = Check.instance(ctx); + predef = Symtab.instance(ctx); + names = Names.instance(ctx); + fac = new Factory(); + } + + // + + /** assert that 's' is a subtype of 't' */ + public void assertSubtype(Type s, Type t) { + assertSubtype(s, t, true); + } + + /** assert that 's' is/is not a subtype of 't' */ + public void assertSubtype(Type s, Type t, boolean expected) { + if (types.isSubtype(s, t) != expected) { + String msg = expected ? + " is not a subtype of " : + " is a subtype of "; + error(s + msg + t); + } + } + + /** assert that 's' is the same type as 't' */ + public void assertSameType(Type s, Type t) { + assertSameType(s, t, true); + } + + /** assert that 's' is/is not the same type as 't' */ + public void assertSameType(Type s, Type t, boolean expected) { + if (types.isSameType(s, t) != expected) { + String msg = expected ? + " is not the same type as " : + " is the same type as "; + error(s + msg + t); + } + } + + /** assert that 's' is castable to 't' */ + public void assertCastable(Type s, Type t) { + assertCastable(s, t, true); + } + + /** assert that 's' is/is not castable to 't' */ + public void assertCastable(Type s, Type t, boolean expected) { + if (types.isCastable(s, t) != expected) { + String msg = expected ? + " is not castable to " : + " is castable to "; + error(s + msg + t); + } + } + + /** assert that 's' is convertible (method invocation conversion) to 't' */ + public void assertConvertible(Type s, Type t) { + assertCastable(s, t, true); + } + + /** assert that 's' is/is not convertible (method invocation conversion) to 't' */ + public void assertConvertible(Type s, Type t, boolean expected) { + if (types.isConvertible(s, t) != expected) { + String msg = expected ? + " is not convertible to " : + " is convertible to "; + error(s + msg + t); + } + } + + /** assert that 's' is assignable to 't' */ + public void assertAssignable(Type s, Type t) { + assertCastable(s, t, true); + } + + /** assert that 's' is/is not assignable to 't' */ + public void assertAssignable(Type s, Type t, boolean expected) { + if (types.isAssignable(s, t) != expected) { + String msg = expected ? + " is not assignable to " : + " is assignable to "; + error(s + msg + t); + } + } + + /** assert that generic type 't' is well-formed */ + public void assertValidGenericType(Type t) { + assertValidGenericType(t, true); + } + + /** assert that 's' is/is not assignable to 't' */ + public void assertValidGenericType(Type t, boolean expected) { + if (chk.checkValidGenericType(t) != expected) { + String msg = expected ? + " is not a valid generic type" : + " is a valid generic type"; + error(t + msg + " " + t.tsym.type); + } + } + // + + /** Creates an inference context given a list of type variables and performs the given action on it. + * The intention is to provide a way to do unit testing on inference contexts. + * @param typeVars a list of type variables to create the inference context from + * @param consumer the action to be performed on the inference context + */ + protected void withInferenceContext(List typeVars, Consumer consumer) { + Assert.check(!typeVars.isEmpty(), "invalid parameter, empty type variables list"); + ListBuffer undetVarsBuffer = new ListBuffer(); + typeVars.stream().map((tv) -> new UndetVar((TypeVar)tv, null, types)).forEach((undetVar) -> { + undetVarsBuffer.add(undetVar); + }); + List undetVarsList = undetVarsBuffer.toList(); + InferenceContext inferenceContext = new InferenceContext(infer, nil(), undetVarsList); + inferenceContext.rollback(undetVarsList); + consumer.accept(inferenceContext); + } + + private void error(String msg) { + throw new AssertionError("Unexpected result: " + msg); + } + + // + + /** compute the erasure of a type 't' */ + public Type erasure(Type t) { + return types.erasure(t); + } + + /** compute the capture of a type 't' */ + public Type capture(Type t) { + return types.capture(t); + } + + /** compute the boxed type associated with 't' */ + public Type box(Type t) { + if (!t.isPrimitive()) { + throw new AssertionError("Cannot box non-primitive type: " + t); + } + return types.boxedClass(t).type; + } + + /** compute the unboxed type associated with 't' */ + public Type unbox(Type t) { + Type u = types.unboxedType(t); + if (t == null) { + throw new AssertionError("Cannot unbox reference type: " + t); + } else { + return u; + } + } + + /** compute a type substitution on 't' given a list of type mappings */ + public Type subst(Type t, Mapping... maps) { + ListBuffer from = new ListBuffer<>(); + ListBuffer to = new ListBuffer<>(); + for (Mapping tm : maps) { + from.append(tm.from); + to.append(tm.to); + } + return types.subst(t, from.toList(), to.toList()); + } + + /** create a fresh type mapping from a type to another */ + public Mapping Mapping(Type from, Type to) { + return new Mapping(from, to); + } + + public static class Mapping { + Type from; + Type to; + private Mapping(Type from, Type to) { + this.from = from; + this.to = to; + } + } + // + + // + + /** + * This class is used to create Java types in a simple way. All main + * kinds of type are supported: primitive, reference, non-denotable. The + * factory also supports creation of constant types (used by the compiler + * to represent the type of a literal). + */ + public class Factory { + + private int synthNameCount = 0; + + private Name syntheticName() { + return names.fromString("A$" + synthNameCount++); + } + + public ClassType Class(long flags, Type... typeArgs) { + ClassSymbol csym = new ClassSymbol(flags, syntheticName(), predef.noSymbol); + csym.type = new ClassType(Type.noType, List.from(typeArgs), csym); + ((ClassType)csym.type).supertype_field = predef.objectType; + return (ClassType)csym.type; + } + + public ClassType Class(Type... typeArgs) { + return Class(0, typeArgs); + } + + public ClassType Interface(Type... typeArgs) { + return Class(Flags.INTERFACE, typeArgs); + } + + public ClassType Interface(long flags, Type... typeArgs) { + return Class(Flags.INTERFACE | flags, typeArgs); + } + + public Type Constant(byte b) { + return predef.byteType.constType(b); + } + + public Type Constant(short s) { + return predef.shortType.constType(s); + } + + public Type Constant(int i) { + return predef.intType.constType(i); + } + + public Type Constant(long l) { + return predef.longType.constType(l); + } + + public Type Constant(float f) { + return predef.floatType.constType(f); + } + + public Type Constant(double d) { + return predef.doubleType.constType(d); + } + + public Type Constant(char c) { + return predef.charType.constType(c + 0); + } + + public ArrayType Array(Type elemType) { + return new ArrayType(elemType, predef.arrayClass); + } + + public TypeVar TypeVariable() { + return TypeVariable(predef.objectType); + } + + public TypeVar TypeVariable(Type bound) { + TypeSymbol tvsym = new TypeVariableSymbol(0, syntheticName(), null, predef.noSymbol); + tvsym.type = new TypeVar(tvsym, bound, null); + return (TypeVar)tvsym.type; + } + + public WildcardType Wildcard(BoundKind bk, Type bound) { + return new WildcardType(bound, bk, predef.boundClass); + } + + public CapturedType CapturedVariable(Type upper, Type lower) { + return new CapturedType(syntheticName(), predef.noSymbol, upper, lower, null); + } + + public ClassType Intersection(Type classBound, Type... intfBounds) { + ClassType ct = Class(Flags.COMPOUND); + ct.supertype_field = classBound; + ct.interfaces_field = List.from(intfBounds); + return ct; + } + } + // + + // + /** + * StrToTypeFactory is a class provided to ease the creation of complex types from Strings. + * The client code can specify a package, a list of imports and a list of type variables when + * creating an instance of StrToTypeFactory. Later types including, or not, these type variables + * can be created by the factory. All occurrences of the same type variable in a type defined + * using a String are guaranteed to refer to the same type variable in the created type. + * + * An example is reported below: + * + *
+     * List imports = new ArrayList<>();
+     * imports.add("java.util.*");
+     * List typeVars = new ArrayList<>();
+     * typeVars.add("T");
+     * strToTypeFactory = new StrToTypeFactory(null, imports, typeVars);
+     *
+     * Type freeType = strToTypeFactory.getType("List");
+     * Type aType = strToTypeFactory.getType("List");
+     *
+     * // method withInferenceContext() belongs to TypeHarness
+     * withInferenceContext(strToTypeFactory.getTypeVars(), inferenceContext -> {
+     *     assertSameType(inferenceContext.asUndetVar(freeType), aType);
+     *     UndetVar undetVarForT = (UndetVar)inferenceContext.undetVars().head;
+     *     com.sun.tools.javac.util.List equalBounds = undetVarForT.getBounds(InferenceBound.EQ);
+     *     Assert.check(!equalBounds.isEmpty() && equalBounds.length() == 1,
+     *          "undetVar must have only one equality bound");
+     * });
+     * 
+ */ + public class StrToTypeFactory { + int id = 0; + String pkg; + java.util.List imports; + public java.util.List typeVarDecls; + public List typeVariables; + + public StrToTypeFactory(String pkg, java.util.List imports, java.util.List typeVarDecls) { + this.pkg = pkg; + this.imports = imports; + this.typeVarDecls = typeVarDecls; + this.typeVariables = from(typeVarDecls.stream() + .map(this::typeVarName) + .map(this::getType) + .collect(Collectors.toList()) + ); + } + + TypeVar getTypeVarFromStr(String name) { + if (typeVarDecls == null) { + return null; + } + int index = typeVarDecls.indexOf(name); + if (index != -1) { + return (TypeVar)typeVariables.get(index); + } + return null; + } + + List getTypeVars() { + return typeVariables; + } + + String typeVarName(String typeVarDecl) { + String[] ss = typeVarDecl.split(" "); + return ss[0]; + } + + public final Type getType(String type) { + JavaSource source = new JavaSource(type); + MyAttr.theType = null; + MyAttr.typeParameters = List.nil(); + tool.clear(); + List inputs = of(source); + try { + tool.compile(inputs); + } catch (Throwable ex) { + throw new Abort(ex); + } + if (typeVariables != null) { + return types.subst(MyAttr.theType, MyAttr.typeParameters, typeVariables); + } + return MyAttr.theType; + } + + class JavaSource extends SimpleJavaFileObject { + + String id; + String type; + String template = "#Package;\n" + + "#Imports\n" + + "class G#Id#TypeVars {\n" + + " #FieldType var;" + + "}"; + + JavaSource(String type) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + this.id = String.valueOf(StrToTypeFactory.this.id++); + this.type = type; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + String impStmts = imports.size() > 0 ? + imports.stream().map(i -> "import " + i + ";").collect(Collectors.joining("\n")) : ""; + String tvars = typeVarDecls.size() > 0 ? + typeVarDecls.stream().collect(Collectors.joining(",", "<", ">")) : ""; + return template + .replace("#Package", (pkg == null) ? "" : "package " + pkg + ";") + .replace("#Imports", impStmts) + .replace("#Id", id) + .replace("#TypeVars", tvars) + .replace("#FieldType", type); + } + } + } + //
+ + // + static class MyAttr extends Attr { + + private static Type theType; + private static List typeParameters = List.nil(); + + static void preRegister(Context context) { + context.put(attrKey, (com.sun.tools.javac.util.Context.Factory) c -> new MyAttr(c)); + } + + MyAttr(Context context) { + super(context); + } + + @Override + public void visitVarDef(JCVariableDecl tree) { + super.visitVarDef(tree); + theType = tree.type; + } + + @Override + public void attribClass(DiagnosticPosition pos, ClassSymbol c) { + super.attribClass(pos, c); + ClassType ct = (ClassType)c.type; + typeParameters = ct.typarams_field; + } + } + + static class ReusableJavaCompiler extends JavaCompiler { + ReusableJavaCompiler(Context context) { + super(context); + } + + @Override + protected void checkReusable() { + // do nothing + } + + @Override + public void close() { + //do nothing + } + + void clear() { + newRound(); + } + } + // +}