Skip to content
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

Wrong insertion of guessed argument when "Completion overwrites" is chosen #500

Closed
mauromol opened this issue Feb 26, 2018 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@mauromol
Copy link

Found while verifying #367.

Consider the following Java enum:

package b;
public enum MyEnum {
	VAL1, VAL2, VAL3;
}

the following Java class:

package b;
public class Utility {
	public static void doSomething(MyEnum enumValue) {
	}
}

and the following Groovy class:

package b 

class Test4 { 
	void doSomething() { 
		Utility.doSom|
	} 
}

Consider these options in Java | Editor | Content assist:

  • Completion overwrites CHECKED
  • Use static imports UNCHECKED
  • Fill method arguments and show guessed arguments CHECKED
  • Insert best guessed arguments CHECKED

Invoke code assist at "|": you'll get Utility.doSomething(VAL3) (VAL3 highlighted) and then choose VAL1. The result is: Utility.doSomething(MyEnum.VAL3VAL1).

If "Use static imports" is CHECKED, the result, instead, is: Utility.doSomething(VAL3VAL1) (the added static import is correct, though).

The problem doesn't happen if you check "Completion inserts" instead of "Completion overwrites".

@eric-milles
Copy link
Member

org.codehaus.groovy.eclipse.codeassist.completions.ParameterGuesserDelegate#newEnumProposal is where enum value arguments are created with supporting import or qualifier.

@eric-milles
Copy link
Member

Ready to test

@mauromol
Copy link
Author

mauromol commented Aug 21, 2018

With 3.1.0.xx-201808210011-e47 it works as expected.
Although I was wondering why the "insert best guessed arguments" with Groovy Editor suggests VAL3. The Java editor suggests null, because there's no hint in that context that suggests anything different.

@eric-milles
Copy link
Member

The list of proposals for each parameter is built up in: https://github.com/groovy/groovy-eclipse/blob/master/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/completions/ParameterGuesserDelegate.java#L52

The array of enum elements is iterated from end to beginning. Not sure why it is done that way. Iterating in the natural order would probably give the result you expect.

@mauromol
Copy link
Author

Not yet, I would expect null, because nothing in the surrounding context suggests any concrete enum value (in the form of a local variable, parameter, field or anything else) to be suggested. See how JDT behaves. It's not a big deal, though, if you agree with this point of view I can open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants