Bug 542815 - [content assist] Completion that includes qualifier or import may miss conflict with imports
Summary: [content assist] Completion that includes qualifier or import may miss confli...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-14 12:03 EST by Eric Milles CLA
Modified: 2022-12-21 17:39 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Milles CLA 2018-12-14 12:03:32 EST
Consider the following:
    package foo;
    enum Color { RED, BLACK }


    package bar;
    import java.awt.Color;
    class Test {
      void meth(foo.Color c) {}
      void main() { meth(BL|) }
    }


Code assist (Ctrl+Space) at '|' includes a proposal for BLACK from foo.Color.  Accepting this proposal replaces "BL" with "Color.BLACK", which is in conflict with the import of Color from another package.
Comment 1 Eric Milles CLA 2018-12-14 12:05:37 EST
I think org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext is the component that handles the conflict determination.
Comment 2 Eclipse Genie CLA 2020-12-11 07:06:46 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.

If you have further information on the current state of the bug, please add it. 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.
Comment 3 Mauro Molinari CLA 2020-12-11 07:25:39 EST
The problem still stands in 2020-09 and I think there are two problems (or probably three).

To make it even clearer, change the enum like this:

public enum Color { FOOBAR, RED, BLACK }

Please note "public" *is needed*, we'll later see what happens when you remove it.

First of all, when you invoke code assist at  BL|, JDT simply suggests a single "Color.BLACK", but it's not clear what "Color" it is meant to add. I would expect two different suggestions, one for java.awt.Color.BLACK and one for foo.Color.BLACK. If you choose the only "Color.BLACK" suggestion, it completes with "Color.BLACK" and this compiles fine because java.awt.Color.BLACK exists, but it may not be the actual BLACK you wanted.

If you then try to complete FOO| instead of BL|, you'll get Color.FOOBAR, because JDT finds foo.Color.FOOBAR, but no import is added and the code does not compile because java.awt.Color.FOOBAR does not exist.

As a final note, if you remove the "public" modifier from the enum declaration, than having an only "Color.BLACK" suggestion would be fine (only constants in java.awt.Color are visible), however if you try to complete FOO|, you'll get "Color.FOOBAR" as a suggestion, which is wrong, because foo.Color.FOOBAR is not visible and hence it should not be proposed at all. In fact, if you accept the proposal, you'll get a compilation error.
Comment 4 Eclipse Genie CLA 2022-12-21 17:39:45 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.

If you have further information on the current state of the bug, please add it. 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.