-
Notifications
You must be signed in to change notification settings - Fork 356
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
Update ChangeType
and ChangePackage
to work with SourceFileWithReference
#4648
Conversation
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeReference.java
Outdated
Show resolved
Hide resolved
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.
Looking good already!
I added some more review comments. Most of them probably apply to both recipes.
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeReference.java
Outdated
Show resolved
Hide resolved
rewrite-core/src/main/java/org/openrewrite/trait/TypeReference.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeReference.java
Outdated
Show resolved
Hide resolved
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 think we should consider renaming this to something more generic like SymbolReference or just Reference and then have a "kind" property, which would probably be an enum like Kind
with constants for Type
and Namespace
(or Package
) for now.
That "name" property will probably also have to be complemented by a structured "symbol" property at some point (so that the caller can query a method reference for name, declaring type, and parameters). But this can wait, I think.
Thoughts?
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 agree but I also feel like this is a creep of the scope, could we log it somewhere as future improvement?
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.
Agreed. It would just be good if we could get the API finalized before people try to start using it.
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeReference.java
Outdated
Show resolved
Hide resolved
boolean recursive = Boolean.TRUE.equals(ChangePackage.this.recursive); | ||
String recursivePackageNamePrefix = oldPackageName + "."; | ||
for (TypeReference ref : cu.getTypeReferences().getTypeReferences()) { | ||
if (ref.getName().equals(oldPackageName) || recursive && ref.getName().startsWith(recursivePackageNamePrefix)) { |
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.
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.
One example I keep thinking about here is when we have META-INF/services
files as we have them for the TypeReference.Provider
interface. In this case the name of a nested type looks like foo.Bar$Baz
. Now ChangeType
can't possibly know that it needs to call renameTo("foo.Bar$Baz")
and not renameTo("foo.Bar.Baz")
. The latter is probably correct for some other config files. Currently, the ChangeType
visitor would have to make sure to always pass in names like "foo.Bar$Baz"
and then the TypeReference
implementation would have to know if it should apply a heuristic (although Bar$Baz
could even be the name of the top-level class, but that would be highly unlikely). The question is just what should the API look like to cater for this?
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-core/src/main/java/org/openrewrite/trait/reference/Reference.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/main/java/org/openrewrite/xml/trait/SpringTypeOrPackageReference.java
Outdated
Show resolved
Hide resolved
rewrite-core/src/main/java/org/openrewrite/trait/reference/Reference.java
Outdated
Show resolved
Hide resolved
public Collection<Reference> findMatches(Reference.Matcher matcher, Reference.Kind kind) { | ||
return findMatchesInternal(matcher, kind); | ||
} |
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 think we might as well simplify the API by removing this method. As the caller supplies the matcher that matcher can filter on the kind.
public Collection<Reference> findMatches(Reference.Matcher matcher, Reference.Kind kind) { | |
return findMatchesInternal(matcher, kind); | |
} |
Instead, we might want to provide something like a containsMatches()
returning a boolean
. But this isn't high priority.
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
rewrite-xml/src/test/java/org/openrewrite/xml/trait/SpringReferenceTest.java
Outdated
Show resolved
Hide resolved
ChangeType
and ChangePackage
to work with SourceFileWithTypeReference
ChangeType
and ChangePackage
to work with SourceFileWithReference
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 might have missed some, but I added a comment regarding the preVisit() methods. I suggest you take a look at TreeVisitor#visit() so you understand how this mechanism works. When all you want to do is extract some information from the top-level node (or also some other node) using the preVisit() method, you should call stopAfterPreVisit() before returning.
rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java
Outdated
Show resolved
Hide resolved
If we can go through all visitors and make sure preVisit() is implemented as appropriate, I think we should merge the PR. |
…eference` (openrewrite#4648) * Apply SourceFileWithTypeReference to ChangePackage and ChangeType * Revert indent changes * Renaming and applying `supportsRename` * Apply bot feedback * Apply bot feedback * Apply review feedback * First batch of improvements * Another batch of improvements * Another batch of improvements * Another batch of improvements * Another batch of improvements * Another batch of improvements * Another batch of improvements * Another batch of improvements * Do not use streams to filter matches * Another batch of improvements * Fix tests * Another batch of improvements * Revert primitive * Update `preVisit`'s * Update `preVisit`'s * Update `preVisit` * Update `preVisit` --------- Co-authored-by: Tim te Beek <[email protected]>
What's changed?
Added implementation for
SourceFileWithTypeReference
inChangeType
andChangePackage
recipesAnything in particular you'd like reviewers to focus on?
Test coverage (edge cases)
Anyone you would like to review specifically?
@knutwannheden @timtebeek
Any additional context
TypeReference
trait to identify Java type references in XML #4587Checklist