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

Bug 428704

Summary: [move method] Move method within the same CU results in compiler error when the method parameter type name is qualified
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: Martin Mathew <manju656>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: manju656, markus.kell.r
Version: 4.4   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Patch + Tests none

Description Noopur Gupta CLA 2014-02-21 01:13:57 EST
Example from bug 409596 comment #0:
-----------------------------------------------------------
package p1;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class Snippet {
	public void foo(java.io.@NonNull FileNotFoundException arg, AnnotatedType type)
				throws java.io.@NonNull EOFException {
	}
}

@Target(ElementType.TYPE_USE)
@interface NonNull {
}

class AnnotatedType {
	
}
-----------------------------------------------------------

Move #foo, the result is:

class AnnotatedType {

	public void foo(@NonNull FileNotFoundException arg)
				throws java.io.@NonNull EOFException {
	}
	
}
-----------------------------------------------------------

FileNotFoundException is not moved as a NQT and also no import is added which results in compilation error.
Comment 1 Martin Mathew CLA 2014-03-20 02:22:59 EDT
This issue is not particular to Java 8. Consider the below code snippet:

package p1;

public class Snippet {
	public void foo(java.io.FileNotFoundException arg, AnnotatedType type)
				throws java.io.EOFException {
	}
}

class AnnotatedType {
	
}

Moving #foo results in compiler error as neither the import is added nor the move preserves the qualified name of the method parameter.

In the finally block of MoveInstanceMethodProcessor#createMethodCopy, the call to  rewriter.clearImportRewrites() is the culprit.
Comment 2 Martin Mathew CLA 2014-03-21 01:13:18 EDT
Created attachment 241085 [details]
Patch + Tests

ImportRewrite#addImport takes care of handling the imports, UI need not add/remove import separately.
Comment 3 Eclipse Genie CLA 2020-02-23 14:13:33 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.