Community
Participate
Working Groups
Build ID: I20080617-2000 Steps To Reproduce: 1. Create a Java Project. 2. Create a package foo. 3. Create a class named Test in the default package. 4. Create a class named Test2 in package foo 5. Type the following in class Test: --- import Test2.Foo public class Test { } --- 6. Place the cursor exactly after the word "Test2" and request autocomplete (ctrl+space). I get a popup saying ""Content Assist" did not complete normally. Please see the log for more information." And here's the error log: org.eclipse.core.runtime.AssertionFailedException: assertion failed: at org.eclipse.core.runtime.Assert.isTrue(Assert.java:111) at org.eclipse.core.runtime.Assert.isTrue(Assert.java:97) at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.setCursorPosition(AbstractJavaCompletionProposal.java:280) at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.setCursorPosition(LazyJavaCompletionProposal.java:176) at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:419) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:923) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$21(CompletionProposalPopup.java:887) at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:492) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:479) at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1664) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:177) at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:82) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:80) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185) at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109) at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476) at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508) at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:471) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:822) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:880) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:569) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:511) at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:126) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1184) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1002) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1040) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1036) at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1352) at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3894) at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:341) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3787) at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2370) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) More information:
Move to JDT/Text
Back to JDT Core: org.eclipse.jdt.core.CompletionProposal.getReplaceStart() gives a wrong (to big) value.
Note that it's even questionable to propose "p . T e s t 2 ;]" here as this results in a compiler error.
I'd like the proposal "foo.Test2", to replace "Test2". In my original scenario, I had something like this: public class Test2 { public static enum Operator { And, Or } } So I typed in another class, in the imports section (I had "Test2.Operator" in the clipboard): import static Test2.Operator.*; Then I noticed a compiler error, because Test2 wasn't found because it isn't qualified. So I put the cursor after Test2, requested autocomplete and got the problem. That's why I was expecting the proposal to replace "Test2" with "foo.Test2", which in this case doesn't result in a compiler error.
By all means, we live in 2008: don't hack imports by hand. Simply use Organize Imports (Ctrl+Shift+O) or even better, let the Save actions do it for you ;-)
I use organize imports all the time, but see my original scenario. I want "And" or "Or" to remain in my code, not "Operator.And" or "Test2.Operator.And". But organize imports doesn't add an "import static Test2.Operator.*" if it encounters "And" or "Or". Suppose I have a method in another class that accepts an Operator. In the caller, I only want to type "And" or "Or", so the import for "Test2.Operator" is not present already. And organize imports doesn't work for that. That's what I mean. That's the only situation where I need to add an import by hand: if it's static.
Makes sense. If you use that Operator often you can add it to the Content Assist > Favorites. If you do so, you can then type A + code assist and it inserts 'And' plus import for you.
Wow! Thanks! I didn't know that. That is new in 3.4, right?
Nope, that's already in 3.3.x.
Hi, this bug also occurs if the programmer places the cursor between characters 't' and 'h', import java.lang.Mat|h.PI; or 'h' and '.', import java.lang.Math|.PI; and then presses CTRL+SPACE. Note that this occurs whether there is the keyword "static" or not. Hope this helps somehow. Regards, Mário
Created attachment 127648 [details] Proposed fix
Released for 3.5M6. Tests added CompletionTests#testCompletionImportedType7() -> testCompletionImportedType8()
Verified for 3.5M6 using I20090310-0100.
*** Bug 273206 has been marked as a duplicate of this bug. ***