-
Notifications
You must be signed in to change notification settings - Fork 359
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
Static import is removed and leaves ambiguous reference behind #4450
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-test/src/test/java/org/openrewrite/test/internal/RewriteTestTest.java
- lines 107-107
Capturing the failure here:
package org.test;
import static org.a.ABC.*;
import static org.b.DEF.*;
import static org.a.ABC.ALL;
public class Test {
private String abc = ALL;
private String a = A;
private String b = B;
private String c = C;
private String d = D;
private String e = E;
private String f = F;
}
package org.test;
import static org.a.ABC.*;
import static org.b.DEF.*;
public class Test {
private String abc = ALL;
private String a = A;
private String b = B;
private String c = C;
private String d = D;
private String e = E;
private String f = F;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-test/src/test/java/org/openrewrite/test/internal/RewriteTestTest.java
- lines 107-107
This indeed seems to match the case reported, thanks! Lets look at what we can do to fix the issue. |
Perhaps good to briefly evaluate if we can fold in a fix for this issue as well |
… ambiguous references
rewrite-java/src/test/java/org/openrewrite/java/search/NotUsesTypeTest.java
Outdated
Show resolved
Hide resolved
209ce4d
to
27fd9a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted the earlier change to TypesInUse, as in reality it's not that type that's used, but the variables that were already part of TypesInUse. Using just the imports, the variables, and the owner of those variables I was able to do a change local to RemoveUnusedImports to detect ambiguous member references from wildcards, and not make changes in those cases. At the same time I covered an additional case where we can clear out one explicit import due to wildcards imports while keeping another explicit import.
This should ensure there's minimal impact from the change, as we don't want to incorrectly assign types as used, and risk those being left over as imports elsewhere when in reality not used.
Thanks for getting this started!
What's your motivation?
RemoveUnusedImports
recipe should not remove static import when this leaves an ambiguous reference behindAnyone you would like to review specifically?
@timtebeek
Have you considered any alternatives or workarounds?
Any additional context
static types were not being added to the typesInUse object on a CompilationUnit
Checklist