-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guessed enum values proposed without qualification when invoking a method #367
Comments
I just saw #365, I don't know whether this might be somewhat related. |
Here is the relevant code in public ICompletionProposal[] parameterProposals(String parameterType, String paramName, Position position, IJavaElement[] assignable, boolean fillBestGuess) {
try {
ICompletionProposal[] allCompletions = guesser.parameterProposals(parameterType, paramName, position, assignable, fillBestGuess, false);
// ensure enum proposals insert the declaring type as part of the name
if (allCompletions != null && allCompletions.length > 0 && assignable != null && assignable.length > 0) {
IType declaring = (IType) assignable[0].getAncestor(IJavaElement.TYPE);
if (declaring != null && declaring.isEnum()) {
// each enum is proposed twice; the first with the qualified name and the second with the simple name
boolean useFull = true;
for (int i = 0; i < assignable.length && i < allCompletions.length; i += 1) {
if (assignable[i].getElementType() == IJavaElement.FIELD) {
if (useFull) {
String newReplacement = declaring.getElementName() + '.' + assignable[i].getElementName();
ReflectionUtils.setPrivateField(PositionBasedCompletionProposal.class, "fDisplayString", allCompletions[i], newReplacement);
ReflectionUtils.setPrivateField(PositionBasedCompletionProposal.class, "fReplacementString", allCompletions[i], newReplacement);
useFull = false;
} else {
useFull = true;
}
}
}
}
}
return addExtras(allCompletions, parameterType, position);
} catch (Exception e) {
GroovyContentAssist.logError("Exception trying to reflectively invoke 'parameterProposals' method.", e);
return ProposalUtils.NO_COMPLETIONS;
}
} |
respect Content Assist preferences: - Add import instead of qualified name - Use static imports (only 1.5 or higher)
I'm testing with 3.0.0.xx-201801241910-e47. Case 1: "Use static imports" unchecked.
Case 2: "Use static imports" checked.
On the other hand, please note that I observe the original problem if I am in this situation: package test4
class Test4 {
void doSomething() {
Utility.doSomething(VA|)
}
} Invoke code assist and choose I have some concerns, though with regards to the use of "Use static imports" option. If you consider an equivalent Java Class: package test4;
public class Test4J {
public void doSomething() {
Utility.doSomething(VA|
}
} If you invoke code assist there, and choose, for instance, |
Also consider this risk. Suppose you have the following enumeration besides package b;
public enum MyEnum2 {
VAL1, VAL2, VAL3;
} And change package test4;
public class Utility {
public static void doSomething(MyEnum enumValue) {
}
public static void doOther(MyEnum2 enumValue) {
}
} Then repeat the original steps to repro to complete package b
import static b.MyEnum.VAL3
import static b.MyEnum2.VAL3
class Test4 {
void doSomething() {
Utility.doSomething(VAL3)
Utility.doOther(VAL3)
}
} which of course is wrong. In other words, if you plan to respect "Use static imports" option in this scenario, you should ensure that a static import for a class/enum with the same name does not already exist, otherwise you should fall back to qualified insertion anyway. |
I can't seem to recreate the improper insertions you mentioned -- "a mistyped |
This is what I see now with 3.0.0.xx-201801252143-e47:
|
I have opened a separate issue to resolve the introduction of conflicting imports. The qualifiers missing will be worked on as part of this issue, but are a lower priority to me as I use the staic imports and I think it is the default setting for a new workspace.
|
Preferences > Java > Editor > Content Assist > Insertion [ ] "Add import instead of qualified name" [ ] "Use static imports (only 1.5 or higher)"
ready for retest against the 3 states of import/qualifier insertion |
Tested with 3.0.0.xx-201802242107-e47.
Conclusion
What do you think? |
I tested these cases and everything was inserting correctly. I'm not sure what the difference is between our two editors.
Never gave this much thought because the ticket has always referred to argument guessing. |
I just saw this is not the case for JDT either, so let's ignore this. |
Regarding this, I just found that the problem occurs only if "Completion overwrites" in Java | Content Assist settings is checked, instead of "Completion inserts". |
This was the old GRECLIPSE-1705
Consider the following Java enumeration:
The following Java class:
And the following Groovy class:
Ensure that the option Groovy | Editor | Content Assist | "Use guessed arguments for method calls" is checked.
Invoke code assist at "|". As you can see,
MyEnum.VAL1
,MyEnum.VAL2
andMyEnum.VAL3
are correctly proposed, however alongside them there are also the unqualifiedVAL1
,VAL2
andVAL3
. If you choose one of the unqualified choices, they are inserted "as-is", which is quite useless, unless you also add a corresponding static import toTest4
class.IMHO, Greclipse should just propose the qualified enumeration values.
The text was updated successfully, but these errors were encountered: