-
Notifications
You must be signed in to change notification settings - Fork 366
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
138c3fa
Apply SourceFileWithTypeReference to ChangePackage and ChangeType
Laurens-W a2d9983
Revert indent changes
Laurens-W 6ec8490
Renaming and applying `supportsRename`
Laurens-W d49040e
Apply bot feedback
Laurens-W 1085bde
Apply bot feedback
Laurens-W 122438e
Apply review feedback
Laurens-W 12432ce
First batch of improvements
Laurens-W 4675e65
Another batch of improvements
Laurens-W 9e6eafd
Another batch of improvements
Laurens-W 112cc2b
Another batch of improvements
Laurens-W a388a03
Another batch of improvements
Laurens-W dbcae71
Another batch of improvements
Laurens-W 6cd26b7
Another batch of improvements
Laurens-W 56221b8
Merge branch 'main' into implements-xml-typrefs-in-changetype
Laurens-W da2a719
Another batch of improvements
Laurens-W 53226cd
Do not use streams to filter matches
timtebeek 830d915
Another batch of improvements
Laurens-W b36375b
Fix tests
Laurens-W 9db1867
Another batch of improvements
Laurens-W 8a13c49
Revert primitive
Laurens-W b84950e
Update `preVisit`'s
Laurens-W 6ad31cd
Update `preVisit`'s
Laurens-W d31607b
Update `preVisit`
Laurens-W 7197966
Update `preVisit`
Laurens-W File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.jspecify.annotations.Nullable; | ||
import org.openrewrite.trait.Reference; | ||
|
||
import java.util.*; | ||
|
||
@Incubating(since = "8.39.0") | ||
public interface SourceFileWithReferences extends SourceFile { | ||
|
||
References getReferences(); | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
class References { | ||
private final SourceFile sourceFile; | ||
private final Set<Reference> references; | ||
|
||
public Collection<Reference> findMatches(Reference.Matcher matcher) { | ||
return findMatchesInternal(matcher, null); | ||
} | ||
|
||
public Collection<Reference> findMatches(Reference.Matcher matcher, Reference.Kind kind) { | ||
return findMatchesInternal(matcher, kind); | ||
} | ||
|
||
private List<Reference> findMatchesInternal(Reference.Matcher matcher, Reference.@Nullable Kind kind) { | ||
List<Reference> list = new ArrayList<>(); | ||
for (Reference ref : references) { | ||
if ((kind == null || ref.getKind().equals(kind)) && ref.matches(matcher) ) { | ||
list.add(ref); | ||
} | ||
} | ||
return list; | ||
} | ||
|
||
public static References build(SourceFile sourceFile) { | ||
Set<Reference> references = new HashSet<>(); | ||
ServiceLoader<Reference.Provider> loader = ServiceLoader.load(Reference.Provider.class); | ||
loader.forEach(provider -> { | ||
if (provider.isAcceptable(sourceFile)) { | ||
references.addAll(provider.getReferences(sourceFile)); | ||
} | ||
}); | ||
return new References(sourceFile, references); | ||
} | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
rewrite-core/src/main/java/org/openrewrite/SourceFileWithTypeReferences.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
rewrite-core/src/main/java/org/openrewrite/TypeReferenceProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead, we might want to provide something like a
containsMatches()
returning aboolean
. But this isn't high priority.