-
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
ChangeType
should fully qualify type usage in the case of conflicting imports
#4458
Conversation
ce0dc2c
to
6285ed0
Compare
…qualifying references
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-java-test/src/test/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitorTest.java
- lines 464-464
@@ -505,6 +511,18 @@ private Expression updateOuterClassTypes(Expression typeTree) { | |||
private boolean isTargetFullyQualifiedType(JavaType.@Nullable FullyQualified fq) { | |||
return fq != null && TypeUtils.isOfClassType(fq, originalType.getFullyQualifiedName()) && targetType instanceof JavaType.FullyQualified; | |||
} | |||
|
|||
private boolean becomesAmbiguous(JavaSourceFile cu) { |
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.
JavaType.FullyQualified newType = TypeUtils.asFullyQualified(targetType); | ||
JavaType.FullyQualified oldType = TypeUtils.asFullyQualified(originalType); | ||
|
||
return newType != null && oldType != null && cu.getImports().stream().anyMatch(imprt -> { |
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.
Try to avoid using the streams API, even when convenient, but especially on paths that might get evaluated often; Adding imports is one of those hot paths where we really want to avoid these object allocations where we can.
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.
Great to see this case fixed! Thanks!
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-java-test/src/test/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitorTest.java
- lines 464-464
ChangeType
removes ambiguous import instead of fully qualifying itChangeType
should fully qualify type usage in the case of conflicting imports
We now see some failures downstream related to imports: |
While working on #4460 I noticed that I just wanted to mention this here, as the PR seems somewhat related and I think it would be great if we could fix that |
A situation where |
What's changed?
Detect when an import becomes ambiguous and once it does start fully qualifying references to the new type
What's your motivation?
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
@timtebeek
Checklist