Community
Participate
Working Groups
I am trying to pull out the method foo() from this: --- public class C { // public static void main(String[] args) { // new Clazz().m(); // } public void foo() { } } --- when i select foo and pull it out, it also deletes class C (and pulls out the comment)
It looks like this is caused by an inconsistency in the sourceranges of the IMethod and the AST node positions used by the NodeFinder. The IMethod source range includes the comment before the method as part of the method's source range. The AST node does not include the comment as part of its source range, unless it is a JavaDoc. The nodefinder uses these source ranges to find an AST node for a given IMethod and comes out with the wrong node because of this inconsistency in positions. This only happens when there is a comment that is not JavaDoc in front of the method declaration.
Created attachment 171987 [details] patch fixing this bug The fix essentially uses NodeFinder's getCoveredNode rather than the default behavior of getCoveringNode for cases whether the range is not exact. Additionally, a few more things had to be changed to also insert modifiers in the right place (i.e. after the comment, not in front of them) when these weird comments are pulled with methods. Some test cases added as well.
attempted to apply patch to Eclipse 3.6 AJDT but it leaves me unresolved type errors for FieldDeclaration and MethodDeclaration
The reason is, probably, because when I made this patch we were still on Eclipse 3.5, so it was made against the 3.5 stream's codebase. When I get setup in 3.6 (shortly), I'll attempt to port my patch to 3.6 codebase. In the mean time, it may be useful to apply this patch to the 3.5 stream?
The only problem with the patch appears to be that someone did organize imports, which conflicted with my two added import for FieldDeclaration and MethodDeclaration.
Created attachment 173488 [details] same patch now for E36 stream
Applied patch in the 36 stream.
fixed now.