XJC ConstField generates empty javadoc comment blocks
patrodyne opened this issue · 0 comments
As of v4.0.4, the ConstField class generates empty Javadoc comment blocks when no <javadoc>text</javadoc>
is explicitly provided in the XML schema.
Example: Empty Javadoc for a Constant Field
/**
*
*
*/
@XmlAttribute(name = "fa_long")
public static final boolean FA_LONG = 7L;
A fix is to conditionally append the prop.javadoc
only when it has content:
--- a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/generator/bean/field/ConstField.java
+++ b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/generator/bean/field/ConstField.java
@@ -54,8 +54,11 @@ final class ConstField extends AbstractField {
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
- $ref.javadoc().append(prop.javadoc);
+ // Do not append empty javadoc.
+ if ( (prop.javadoc != null) && (prop.javadoc.length() > 0) )
+ $ref.javadoc().append(prop.javadoc);
+
annotate($ref);
}
Rationale
Currently, when $ref.javadoc()
is invoked by ConstField
, the jdoc
field of JFieldVar
is initialized to a non-null value. Later, the declare
method is invoked and the JFormatter.g(jdoc)
method is triggered whenever jdoc
is not null. This leads to a call to JDocComment.generate(JFormatter)
which includes blank lines when @param
, @return
, @throws
, etc. are not applicable.
The proposed fix is to prevent an unnecessary initialization of the jdoc
field of JFieldVar
; thus, avoiding a call to JDocComment.generate(JFormatter)
. I will submit a pull request with the fix and a unit test.
ConstField: Call Sequence
com.sun.codemodel.JFieldVar.javadoc()
...
public JDocComment javadoc()
{
if( jdoc == null )
jdoc = new JDocComment(owner.owner());
return jdoc;
}
...
com.sun.codemodel.JDefinedClass.declareBody(JFormatter)
com.sun.codemodel.JFormatter.d(JDeclaration)
com.sun.codemodel.JFieldVar.declare(JFormatter)
...
public void declare(JFormatter f)
{
if( jdoc != null )
f.g( jdoc );
super.declare( f );
}
...
com.sun.codemodel.JFormatter.g(JGenerable)
com.sun.codemodel.JDocComment.generate(JFormatter)