开发者

JavaDoc method signature indentation

开发者 https://www.devze.com 2023-03-21 14:29 出处:网络
I tend to use a lot of line breaks in my code to keep things mostly within the 80-character line width. While some might find this utterly useless, I like to edit code on a vertically rotated screen a

I tend to use a lot of line breaks in my code to keep things mostly within the 80-character line width. While some might find this utterly useless, I like to edit code on a vertically rotated screen and also like this narrow layout when doing diffs. Regardless of preference, this did give me an unexpected result when generating JavaDoc, more specifically开发者_JS百科 the method signatures.

Suppose I have the following:

public static 
        <C extends AcmeConstants, 
        B extends AcmeBundle<C>, 
        R extends AcmeBundleProvider<C, B>> //Type params
        R //Return type
        newInstance(final Class<R> spiClass, final String implementationClassName) 
        throws AcmeException {

    return newInstance(spiClass, 
                       implementationClassName, 
                       Thread.currentThread().getContextClassLoader());
}

Crazy type parameters aside, as you can see I'm aligning the type params, return type, method declaration and throws clause to keep things somewhat distinct. Again, you may find this charming or downright retarded, but the problem occurs when generating JavaDoc. What I get is documentation where the method arguments are each on a new line and aligned, even though I didn't do that. Not really a problem, although oddly it turns the type parameter declaration into one line. The real kicker, however, is that it then puts the throws clause on a new line as well, with original indentation!

Have a look to see what I mean:

public static <C extends AcmeConstants,B extends AcmeBundle<C>,R extends AcmeBundleProvider<C,B>> R newInstance(Class<R> spiClass,
                                                                                                                 String implementationClassName)
                                                               throws AcmeException

That's pretty much exactly as it looks in the generated JavaDoc. Is there any way to make it stop doing this and normalize white space or something? Right now I have to choose between changing my code formatting or having weird JavaDoc.

By the way, I'm generating with the Maven JavaDoc plugin, but the result was the same when using different methods.


The Javadoc is generated by a Doclet, which only gets to see a parsed version of your code. That it aligns the throws clause similarly to your original source is coincidence. The signature you see is actually generated from a MethodDoc handed by the framework to the Doclet. Short of changing the Doclet code, you can not change the output format. Nothing prevents you from post-processing it, but I doubt it will be worth the effort.

BTW, alternative doclets are available on the internet, which may be more suitable to customization.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号