0

In my (OpenGL!) Java program, I need 3 types of Objects: Textures, Framebuffers, Screens. All three have some common characteristics (width, height, unique ID) but are also different in 1 fundamental way:

  • Screens are only for output (render)
  • Framebuffers can be read from and set up as surfaces for output
  • Textures can only be read from (for the nitpickers: I know one can 'render to Texture' but only by attaching it first to an FBO, in which case my program treats it as an instance of a Framebuffer)

Were it C++ with its multiple inheritance, I'd have a base class 'Surface', then two derived classes 'InputSurface' and 'OutputSurface' , and have the Texture class extend InputSurface, the Screen OutputSurface, and the Framebuffer both.

Down to Earth- its Java, so I came up with the following monstrosity:

interface InputSurface
  {
  /**
   * Return the width of this Surface.
   */
  int getWidth();
  /**
   * Return the height of this Surface.
   */
  int getHeight();
  /**
   * Take the underlying rectangle of pixels and bind this texture to OpenGL.
   */
  boolean setAsInput();
  }

abstract class Surface
  {
  /**
   * Return the width of this Surface.
   *
   * @return width of the Object, in pixels.
   */
  public int getWidth() {...}
  /**
   * Return the height of this Surface.
   *
   * @return height of the Object, in pixels.
   */
  public int getHeight() {...}
  }

public class Texture extends Surface implements InputSurface
  {
  /**
   * Bind the underlying rectangle of pixels as a OpenGL Texture.
   */
  public boolean setAsInput() {...}
  }

abstract class OutputSurface extends Surface
  {
  abstract void setAsOutput();
  }

public class Screen extends OutputSurface
  {
  setAsOutput() {...}
  }

public class Framebuffer extends OutputSurface implements InputSurface
  {
  setAsInput() {...}
  setAsOutput() {...}
  }

(I need the InputSurface interface because later on I need to be able to accept both a Framebuffer and a Texture as inputs to generic methods like this

void renderFrom(InputSurface surface)
  {
  (...)
  }

The above works, the only problem is it introduces a mess in the Javadoc-produced documentation. In its Texture and Framebuffer docs Javadoc essentially duplicates the 'getWidth/Height' metods, because it thinks there's one in Surface class and another in the InputSurface interface.

Here's the documentation it comes up with:

http://distorted.org/javadoc-library/org/distorted/library/DistortedTexture.html

Any advice?

Leszek
  • 1,181
  • 1
  • 10
  • 21
  • When your question is about javadoc, you should add your javadoc comments to the snippet. – SME_Dev Feb 17 '17 at 14:27
  • When it is true that there are getWidth and getHeight methods in InputSurface and Surface, what's wrong with javadoc generating it? – James Jithin Feb 17 '17 at 14:32
  • @James: it looks like shit :) Take a look at http://distorted.org/javadoc-library/org/distorted/library/DistortedTexture.html – Leszek Feb 17 '17 at 14:33
  • 1
    @Leszek, you may look at http://stackoverflow.com/questions/3061387/should-javadoc-comments-be-added-to-the-implementation if this is what you are pointing to – James Jithin Feb 17 '17 at 14:37
  • According to that javadoc, `DistortedTexture` extends Object and implements no interfaces. So where is it getting those duplicate getWidth and getHeight methods from? – VGR Feb 17 '17 at 14:51
  • 1
    @VGR: InputSurface and Surface are package-local. That's why you don't see them in Javadoc.I am sure the duplicate methods come from there, as when I change the comments above those methods in InputSurface and Surface, the documatation changes accordingly. – Leszek Feb 17 '17 at 15:08
  • @Leszek the problem is `InputSurface` and `Surface` are package-private. When you change them to public the duplicates go away. This is because Javadoc only documents the public API. As you noticed the two methods can have different Javadoc and so both method documentations need to be provided when they are package-private. – DragonAssassin Feb 17 '17 at 15:14
  • @Dragon: yes, I noticed that - actually the standard ArrayList faces the same problem: it extends AbstractList and implements List, inheriting 'equals()' form both of them. But AbstractList and List are public so no double documentation. Here however, Surface and InputSurface are really purely internal constructs (even though one is an interface!) Making them public will make them appear in Javadoc documentation even though they are NOT part of public API. – Leszek Feb 17 '17 at 15:20

1 Answers1

0

I have settled for a Javadoc-based hack: use a custom Doclet that lets me mark certain public classes, methods and fields to be excluded from the documentation it produces.

Leszek
  • 1,181
  • 1
  • 10
  • 21