Skip to content

Commit

Permalink
Don't mark every file a duplicate. Oops
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Sep 29, 2023
1 parent 2793b2b commit 0aa44a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/openrewrite/FindDuplicateSourceFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ public Collection<? extends SourceFile> generate(Map<Path, List<String>> acc, Ex

@Override
public TreeVisitor<?, ExecutionContext> getVisitor(Map<Path, List<String>> acc) {
if(acc.isEmpty()) {
return TreeVisitor.noop();
}
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree visit(@Nullable Tree tree, ExecutionContext executionContext) {
assert tree instanceof SourceFile;
SourceFile s = (SourceFile) tree;
if(acc.containsKey(s.getSourcePath())) {
if(acc.containsKey(s.getSourcePath()) && acc.get(s.getSourcePath()).size() > 1) {
s = SearchResult.found(s);
}
return s;
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/openrewrite/FindDuplicateSourceFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ void findDuplicates() {
)
);
}

@Test
void noDupes() {
rewriteRun(
spec -> spec.recipe(new FindDuplicateSourceFiles()),
text(
"hello=world",
spec -> spec.path("hello.properties")
)
);
}
}

0 comments on commit 0aa44a7

Please sign in to comment.