Skip to content

Commit

Permalink
Mark duplicate source files in addition to adding them to the data table
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Sep 29, 2023
1 parent 8308232 commit 2793b2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/openrewrite/FindDuplicateSourceFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite;

import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.marker.SearchResult;
import org.openrewrite.table.DuplicateSourceFiles;

import java.nio.file.Path;
Expand Down Expand Up @@ -66,4 +67,22 @@ public Collection<? extends SourceFile> generate(Map<Path, List<String>> acc, Ex
}
return Collections.emptyList();
}

@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())) {
s = SearchResult.found(s);
}
return s;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ void findDuplicates() {
assertThat(rows).hasSize(1)),
text(
"hello=world",
"~~>hello=world",
spec -> spec.path("hello.properties")
),
properties(
"hello=world",
"~~>hello=world",
spec -> spec.path("hello.properties")
)
);
Expand Down

0 comments on commit 2793b2b

Please sign in to comment.