In creating a software application, I'm creating a doclet to be plugged into Javdoc. One problem I'm having with the use of Javadoc and the RootDoc that is created is that it includes nullary constructors created by the compiler. Is there a way to prevent this from happening or identifying them via the RootDoc provided to my doclet? I thought I made headway on this last night when I discovered the isSynthetic method, but nullary constructors are apparently not synthetic.
Asked
Active
Viewed 255 times
3
-
What about some heuristics: It is the only constructor, has no arguments, and no documentation? – Paŭlo Ebermann May 26 '12 at 23:47
-
It may not be the only constructor. I can author a class with other constructors and it will be added in as well. Heuristics are a start, but I can't be sure it's the nullary one. My module(s) process student input (source code) and provide metrics and feedback on a student's comments. There is no way to determine with any certainty that the student did not author it and also provide no documentation (a common occurrence). – docSquale May 28 '12 at 01:10
-
1No, a no-arg constructor will only be generated if there is no one at all there. But you are right, there is no way to distinguish this auto-generated one from one written by your students without also looking at the source code. – Paŭlo Ebermann May 28 '12 at 15:20
-
1Interestingly, the Doc.position() method reports file/line/column information about source code contents. The documentation **claims** that _A default constructor returns null because it has no location in the source file._ Sadly, it does not seem to actually work that way... This would have solved the problem as well. – docSquale May 29 '12 at 03:57
1 Answers
2
Further investigation indicates that SourcePosition returned for the enclosing ClassDoc has the same line and column numbers as the SourcePosition returned for the generated default constructor (an undocumented feature!). I'm successfully using this as a discriminator.

ChrisSweeney
- 36
- 2
-
Great call here. I've implemented this 'test' in my program and it works well to identify the nullary constructor. Seems a bit hack-ish, but I'll take it. – docSquale Jul 12 '12 at 04:20