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

Search for references: potential matches? #935

Closed
mauromol opened this issue Aug 9, 2019 · 7 comments
Closed

Search for references: potential matches? #935

mauromol opened this issue Aug 9, 2019 · 7 comments
Assignees
Labels
Milestone

Comments

@mauromol
Copy link

mauromol commented Aug 9, 2019

Consider this:

package test53
import groovy.transform.CompileStatic
@CompileStatic
class MyBean {
	String foo	
}

and this:

package test53
import groovy.transform.CompileStatic
@CompileStatic
class Test53 {
	
	void doSomething() {
		def b = new MyBean()
		b.foo = 'foo'
	}
}

Go to MyBean.foo and hit Ctrl+Shift+G (search for references). Greclipse finds b.foo in b.foo = 'foo' in Test53, but marks it as a potential match: why potential?

@eric-milles
Copy link
Member

eric-milles commented Aug 9, 2019

why potential?

This search result is marked as a potential match because the search is for a field and the occurrence is actually a method call. If the match was exact, then a rename of the method from "getFoo" to "getWhatever" would change this reference to "getWhatever" instead of the expected "whatever". It is a bit of a balancing act to support find occurrences, call hierarchy, and rename refactoring for Groovy properties.

@mauromol
Copy link
Author

mauromol commented Aug 9, 2019

This search result is marked as a potential match because the search is for a field and the occurrence is actually a method call. If the match was exact, then a rename of the method from "getFoo" to "getWhatever" would change this reference to "getWhatever" instead of the expected "whatever". It is a bit of a balancing act to support find occurrences, call hierarchy, and rename refactoring for Groovy properties.

I understand the fact that this match is actually a method call, but I can't follow you on the rename example. getFoo() is not explicitly defined, so I can't rename it to getWhatever(): what I can do, instead, is to rename foo to whatever and in this case I would expect that reference to be changed to whatever indeed.

I think it's a bit confusing the fact that references are marked as "potential". Maybe this is a limitation that needs to be in place to make other things (like refactorings) work in the right way... but, from a user point of view and without any knowledge of the internals, in this example I would expect Eclipse to treat the match as exact, especially because I'm using static compilation, so I would say it's certain that I'm referring to that property and not potentially to something else.

@eric-milles
Copy link
Member

Here is one difference:

void meth(Bean b) {
  b.foo // ConstantExpression[foo]
    = 'foo'
}
@groovy.transform.CompileStatic
void meth(Bean b) {
  b.foo // ConstantExpression[setFoo]
    = 'foo'
}

This is causing the switch from exact to potential.

@mauromol
Copy link
Author

mauromol commented Aug 9, 2019

And again, from an ignorant like me point of view, I would say the first case is more likely to be "potential" due to the dynamic nature of Groovy, while the second one is more likely to be "exact" due to the fact that the call is statically compiled in. That is, the opposite of what happens right now :-)

@eric-milles
Copy link
Member

This will get sorted out. I just discovered this difference upon investigating your issue. I think in the end, both the dynamic and static case can be shown as exact matches.

@eric-milles
Copy link
Member

ready to test

@mauromol
Copy link
Author

This use case works well with 3.5.0.v201908101728-e1906: no "exact"/"potential" match indication is shown, hence the match must be exact, which is what I expect. Thank you!

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