Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...