29

I have an inner class which declares a constant and want to display its value in Javadoc of the enclosing top-level class using the @value annotation. For example:

/**
 * {@value #FOO_CONS} // this displays well
 * {@value #BAR_CONS} // this does not work (checked in the latest Eclipse)
 * {@value Bar#BAR_CONS} // this does not work, either
 */
public Foo {
  public static final int FOO_CONS = 1;
  static class Bar {
    public static final int BAR_CONS = 42;
  }
}

Any ideas how to display the value of BAR_CONS in Javadoc of the Foo class (or any other class, in general)?

eold
  • 5,972
  • 11
  • 56
  • 75
  • 4
    Did you try using `@value Foo.Bar#BAR_CONS` as stated [here][1], it takes the same form as the @see argument, and as stated [here][2] `Nested classes must be specified as outer.inner, not simply inner, for all forms.` I don't have eclipse here so I'm not able to test further. Otherwise the fully qualified path should work `com.pkg.Foo.Bar#BAR_CONS` [1]: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javadoc.html#%7B@value%7D [2]: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javadoc.html#package.class – Alex Jul 11 '12 at 06:54
  • Yes, that does not work, at least it is not displayed correctly in Eclipse. What's more I cannot even get FOO_CONS displayed correctly with {@value Foo#FOO_CONS}. – eold Jul 11 '12 at 06:55
  • What version of eclipse are you using ? I can remember the `@value` annotation not showing correctly prior to Helios. – Alex Jul 11 '12 at 06:57
  • Indigo (3.7.2). Does the above example work fine in your Eclipse (if you use @value as you described)? – eold Jul 11 '12 at 07:03
  • My Indigo gives the same results as OP stated in his comments. – brimborium Jul 11 '12 at 07:28
  • After further tests it does not work in Juno either. If using `Bar#BAR_CONS` when moving the cursor on it in the javadoc, eclipse correctly highlight the instance in the inner class, the java doc eclipse view does not correctly show it. I don't know why. – Alex Jul 11 '12 at 16:47
  • 2
    @Alex has hit on something useful. I tested the fully qualified path and had success. Foo was in package "org.oyrm.javadoc" and the annotation reads `{@value org.oyrm.javadoc.Foo.Bar#BAR_CONS}` – OYRM May 02 '13 at 21:08

2 Answers2

15

Javadoc format for constant defined in another package should be:
{@value package.class#field}

However, it potentially not rendering is a known issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342194

Scott
  • 158
  • 1
  • 4
2

if create javadoc for members with visibility "package" (which is the visibility for your Bar class) i get the constant in the javadoc under Foo.Bar

user2340612
  • 10,053
  • 4
  • 41
  • 66