Skip to content

Commit 3727748

Browse files
committed
Refactorings
- Extracted method - extracted variable decl
1 parent 840dfb6 commit 3727748

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/java/refactoring/JavaGlobalRefactoringImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public List<RewriteSourceFileHolder<J.CompilationUnit>> find(Recipe recipe) {
8585

8686
@NotNull
8787
protected List<RewriteSourceFileHolder<J.CompilationUnit>> findInternal(List<RewriteSourceFileHolder<J.CompilationUnit>> resourceWrappers, Recipe recipe) {
88-
List<Result> results = executeRecipe(getAllCompilationUnits().stream().map(RewriteSourceFileHolder::getSourceFile).collect(Collectors.toList()), recipe);
88+
List<J.CompilationUnit> compilationUnits = resourceWrappers.stream().map(RewriteSourceFileHolder::getSourceFile).collect(Collectors.toList());
89+
List<Result> results = executeRecipe(compilationUnits, recipe);
8990
return results.stream()
9091
.map(r -> r.getAfter())
9192
.filter(r -> J.CompilationUnit.class.isAssignableFrom(r.getClass()))

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/filter/SpringDataJpaAnalyzer.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,21 @@ public List<MatchingMethod> getJpaRepositoriesWithGetByIdMethod(ProjectContext c
3434
List<JavaSourceAndType> jpaRepositories = context.getProjectJavaSources().findTypesImplementing(jpaRepositoryInterface);
3535
// FIXME: type of PK must be retrieved, moves to rewrite when these migrations are provided as OpenRewrite recipes
3636
String methodPattern = "getById(java.lang.Long)";
37-
return jpaRepositories.stream()
38-
.filter(jat -> jat.getType().hasMethod(methodPattern))
39-
.map(jat -> {
40-
return new MatchingMethod(jat, methodPattern, jat.getType().getMethod(methodPattern));
41-
})
42-
.collect(Collectors.toList());
43-
//return findRepositoriesDeclaring(jpaRepositories, methodPattern);
37+
return findRepositoriesDeclaring(jpaRepositories, methodPattern);
4438
}
4539

4640
private List<MatchingMethod> findRepositoriesDeclaring(List<JavaSourceAndType> jpaRepositories, String methodPattern) {
4741
return jpaRepositories.stream()
4842
.filter(jat -> jat.getType().hasMethod(methodPattern))
49-
.map(jat -> {
50-
return new MatchingMethod(jat, methodPattern, jat.getType().getMethod(methodPattern));
51-
})
43+
.map(jat -> new MatchingMethod(jat, methodPattern, jat.getType().getMethod(methodPattern)))
5244
.collect(Collectors.toList());
5345
}
5446

5547
@Value
56-
public class MatchingMethod {
57-
private final JavaSourceAndType jat;
58-
private final String methodPattern;
59-
private final Method method;
48+
public static class MatchingMethod {
49+
JavaSourceAndType jat;
50+
String methodPattern;
51+
Method method;
6052

6153
public MatchingMethod(JavaSourceAndType jat, String methodPattern, Method method) {
6254
this.jat = jat;

0 commit comments

Comments
 (0)