Project: JDT
Bug 285137 [content assist] Completing method from unresolved variable removes code in case of * import
Reported: 2009-07-30 06:51:17 | Status: verified fixed

Hello, apologies if this is filed in the wrong place. I use content assist extensively; I also use the Java -> Code Style -> Organize Imports "Number of imports needed for .*" feature with value of 2. I'm constantly running into an interaction between the two - when I use the completion of content assist (as in the following example), it deletes code after the insertion point (it deletes the number of characters saved by optimising the import). I can avoid this interaction by changing the "Number of imports needed for .*" to 9999 In my example I'm talking about KeyPair, which is in com.amazonaws.ec2.model; I don't have an import for it but I do have an import for "TerminatingInstance", also in that package (I have Number of imports needed for .* set to 2) import com.amazonaws.ec2.model.TerminatingInstance; public class Test { public static void main(String[] args) { KeyPair kp = null; kp.toStr } public void bufferMethodToBeEatenByBug() { } } When I press control+space at "kp.toStr" to get the completion for toString and accept the default, the code changes to the following (which, as you can see, has toString() but has deleted a lot of code following it) import com.amazonaws.ec2.model.*; public class Test { public static void main(String[] args) { KeyPair kp = null; kp.toString() bufferMethodToBeEatenByBug() { } } ---- Another thing I noticed while producing this simple testcase: If the number of characters that would be deleted is greater than the number of characters left in the file then I get some odd behaviour: the import is made and optimised but the method name completion fails, leaving me with "kp.toStr" again but "import com.amazonaws.ec2.model.*;" (to accomplish this I simply deleted bufferMethodToBeEatenByBug in my testcase): import com.amazonaws.ec2.model.TerminatingInstance; public class Test { public static void main(String[] args) { KeyPair kp = null; kp.toStr } } Which, after content assist, became... import com.amazonaws.ec2.model.*; public class Test { public static void main(String[] args) { KeyPair kp = null; kp.toStr } }

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java