Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8267126: javadoc should show "line and caret" for diagnostics.
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed May 25, 2021
1 parent 461a3fe commit b4d4884
Show file tree
Hide file tree
Showing 37 changed files with 832 additions and 306 deletions.
Expand Up @@ -60,6 +60,7 @@
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options;

import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import jdk.javadoc.internal.tool.ToolEnvironment;
Expand Down Expand Up @@ -536,4 +537,21 @@ public boolean isReflectivePreviewAPI(Element el) {
return (sym.flags() & Flags.PREVIEW_REFLECTIVE) != 0;
}

/**
* Returns whether or not to permit dynamically loaded components to access
* part of the javadoc internal API. The flag is the same (hidden) compiler
* option that allows javac plugins and annotation processors to access
* javac internal API.
*
* As with all workarounds, it is better to consider updating the public API,
* rather than relying on undocumented features like this, that may be withdrawn
* at any time, without notice.
*
* @return true if access is permitted to internal API
*/
public boolean accessInternalAPI() {
Options compilerOptions = Options.instance(toolEnv.context);
return compilerOptions.isSet("accessInternalAPI");
}

}
Expand Up @@ -185,6 +185,8 @@ public class TagletManager {

private final String tagletPath;

private final BaseConfiguration configuration;

/**
* Constructs a new {@code TagletManager}.
*
Expand All @@ -197,6 +199,7 @@ public TagletManager(BaseConfiguration configuration) {
standardTagsLowercase = new HashSet<>();
unseenCustomTags = new HashSet<>();
allTaglets = new LinkedHashMap<>();
this.configuration = configuration;
BaseOptions options = configuration.getOptions();
this.nosince = options.noSince();
this.showversion = options.showVersion();
Expand Down Expand Up @@ -250,6 +253,15 @@ public void addCustomTag(String classname, JavaFileManager fileManager) {
try {
ClassLoader tagClassLoader;
tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
if (configuration.workArounds.accessInternalAPI()) {
Module thisModule = getClass().getModule();
Module tagletLoaderUnnamedModule = tagClassLoader.getUnnamedModule();
List<String> pkgs = List.of(
"jdk.javadoc.doclet",
"jdk.javadoc.internal.doclets.toolkit",
"jdk.javadoc.internal.doclets.formats.html");
pkgs.forEach(p -> thisModule.addOpens(p, tagletLoaderUnnamedModule));
}
Class<? extends jdk.javadoc.doclet.Taglet> customTagClass =
tagClassLoader.loadClass(classname).asSubclass(jdk.javadoc.doclet.Taglet.class);
jdk.javadoc.doclet.Taglet instance = customTagClass.getConstructor().newInstance();
Expand Down
Expand Up @@ -93,6 +93,7 @@
import javax.tools.JavaFileManager.Location;
import javax.tools.StandardLocation;

import com.sun.source.doctree.BlockTagTree;
import com.sun.source.doctree.DeprecatedTree;
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
Expand Down Expand Up @@ -2632,10 +2633,10 @@ public List<? extends DocTree> getBlockTags(Element element, DocTree.Kind kind,

public List<? extends DocTree> getBlockTags(Element element, Taglet taglet) {
return getBlockTags(element, t -> {
if (taglet instanceof BaseTaglet bt) {
return bt.accepts(t);
} else if (t instanceof UnknownBlockTagTree tree) {
return tree.getTagName().equals(taglet.getName());
if (taglet instanceof BaseTaglet baseTaglet) {
return baseTaglet.accepts(t);
} else if (t instanceof BlockTagTree blockTagTree) {
return blockTagTree.getTagName().equals(taglet.getName());
} else {
return false;
}
Expand Down
Expand Up @@ -567,7 +567,7 @@ private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean onlyTra
if (!isMandated(mdle, rd) && onlyTransitive == rd.isTransitive()) {
if (!haveModuleSources(dep)) {
if (!warnedNoSources.contains(dep)) {
messager.printWarning(dep, "main.module_source_not_found", dep.getQualifiedName());
messager.printWarningUsingKey(dep, "main.module_source_not_found", dep.getQualifiedName());
warnedNoSources.add(dep);
}
}
Expand Down

1 comment on commit b4d4884

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.