Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

classloader - How to customize Javadoc output for the Java 9+

I want to modify the Javadoc output, for this purpose I create a custom Doclet that reuse the default one and wrap DocletEnvironment in my proxy class that contains my custom filtering logic.

NOTE: java 11 javadoc API used

My Doclet class:

public class MyDoclet implements Doclet {
    private final HtmlDoclet htmlDoclet;

    public MyDoclet() {
        htmlDoclet = new HtmlDoclet(this);
    }

    @Override
    public boolean run(DocletEnvironment docEnv) {
        var proxy = new DocletEnvironmentProxy(docEnv);
        return htmlDoclet.run(proxy);
    }

//other code...
}

My DocletEnvironment proxy class:

public class DocletEnvironmentProxy implements DocletEnvironment  {
    public static final String TAG = "peek_me";
    private final DocletEnvironment environment;
    private Set<? extends Element> filteredElements;

    public DocletEnvironmentProxy(DocletEnvironment environment) {
        this.environment = environment;
    }

    @Override
    public Set<? extends Element> getIncludedElements() {
        if (filteredElements == null) {
            filteredElements = filterElements(environment.getIncludedElements());
        }
        return filteredElements;
    }
//other code...
}

But when I try to run it I get: java.lang.ClassCastException: class mypackage.DocletEnvironmentProxy cannot be cast to class jdk.javadoc.internal.tool. DocEnvImpl (mypackage.DocletEnvironmentProxy is in unnamed module of loader java.net.URLClassLoader @3dfc5fb8; jdk.javadoc.internal.tool.DocEnvImpl is in module jdk.javadoc of loader 'app')

I found the bug related to it and interesting comment for it, which says "this is not a recognized way to perform customization"

I spent a lot of time looking for the "correct" description of the customization approach but did not find anything related to it. Only some guides from Oracle on the basic Doclet API usages.

Maybe someone knows where I can find the "correct" approach or already solved the Doclet customization issue?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...