Community
Participate
Working Groups
Build 20020212 1) Start with following classes: public class A { public A(String s) {} public void foo() {} } public class B {} 2) Open an editor on class B 3) In the content outline, select Override Methods -> foo 4) Now select "Add Constructors From Superclass" The result is below. The constructor gets inserted between the method comment and the method body. This is probably because "Override Methods" creates non-javadoc method comments. /* * @see A#foo() */ /** * Constructor for B. * @param s */ public B(String s) { super(s); } public void foo() { super.foo(); } }
JavaCore should extend the source range of the method to include preceding non-javadoc comments.
If using the new DOM ASTs, then this problem will go away.
A non-javadoc comment is never part of the method declaration. So I don't want to include it.
*** Bug 11056 has been marked as a duplicate of this bug. ***
Olivier - couldn't we simply include comments to Source methods (as consumed by the source element parser) ? This wouldn't affect the compiler behavior, only source element parsed code (i.e. java elements).
I can see how to locally change this behavior.
Do we want to do the same thing for line comments? I guess we want the declaration of a method to include only multiple line comments and javadoc comments.
While you're looking at this, here's another method declaration that shows up incorrectly in the method-level editor. The convention of adding /*package*/ for default visibility does not work when there is also a javadoc comment: /** * Sets the project for which this builder operates. * @see #getProject */ /* package */ final void setProject(IProject value) { Assert.isTrue(project == null); project = value; }
The javadoc comment has to be the last one before the method declaration if you want to be able to use tags such as @deprecated. If you want to add /* package */ in front of your method declaration, then you lose the feature of javadoc tags. Is this ok for you? Where did you find this convention using /* package */?
I don't know where/when the convention started, but it seems to be fairly common. A quick look through the Eclipse src showed this convention is sometimes used in platform core, platform ui, jdt core and jdt ui. I didn't know that non-javadoc comments could have any effect on the behaviour of the compiler! If that behaviour is specified for javadoc, I guess people should really stop using this convention then.
For me this comment /* package */ add nothing. It is simply useless and can lead to bugs related to the fact that javadoc tags used in the javadoc comment preceeding this comment are ignored. I will fix the fact that non-javadoc comments are ignored before body declarations, but I won't change the fact that javadoc tags are considered only if the javadoc comment is located immediately before the body declaration (method, field, type, initializer).
Now we can properly delete methods and theirs comments even if the comment are not javadoc comments. Inserting new methods is done at the right location. All problems related to this seem fixed. If you notice strange behavior, don't hesitate to reopen this PR. Fixed and released in HEAD.
*** Bug 12710 has been marked as a duplicate of this bug. ***