Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316945

Summary: [plan] [refactoring] pull out problem when comments near pulled out member
Product: [Tools] AJDT Reporter: Andrew Clement <aclement>
Component: UIAssignee: AJDT-inbox <AJDT-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andrew.eisenberg, kdevolder
Version: 2.0.2   
Target Milestone: 2.1.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
patch fixing this bug
andrew.eisenberg: iplog+
same patch now for E36 stream andrew.eisenberg: iplog+

Description Andrew Clement CLA 2010-06-15 13:09:11 EDT
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)
Comment 1 Kris De Volder CLA 2010-06-15 16:01:44 EDT
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.
Comment 2 Kris De Volder CLA 2010-06-15 16:16:48 EDT
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.
Comment 3 Andrew Clement CLA 2010-07-05 16:54:40 EDT
attempted to apply patch to Eclipse 3.6 AJDT but it leaves me unresolved type errors for FieldDeclaration and MethodDeclaration
Comment 4 Kris De Volder CLA 2010-07-05 19:18:28 EDT
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?
Comment 5 Kris De Volder CLA 2010-07-05 20:06:43 EDT
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.
Comment 6 Kris De Volder CLA 2010-07-05 20:07:52 EDT
Created attachment 173488 [details]
same patch now for E36 stream
Comment 7 Andrew Eisenberg CLA 2010-07-12 14:10:52 EDT
Applied patch in the 36 stream.
Comment 8 Andrew Eisenberg CLA 2010-07-23 18:42:26 EDT
fixed now.