Skip to content

Commit

Permalink
Fix duplicate data table entries.
Browse files Browse the repository at this point in the history
A while ago we changed how search results work, which inadvertently led to duplicate results in data tables like this one.
  • Loading branch information
sambsnyd committed Dec 12, 2024
1 parent fdc042b commit ceb3dab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static void stat() {}
@Test
void simpleName() {
rewriteRun(
spec -> spec.dataTable(TypeUses.Row.class, rows -> assertThat(rows)
.containsExactly(
new TypeUses.Row("B.java", "A1", "a.A1")
)),
java(
"""
import a.A1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@ public J visitFieldAccess(J.FieldAccess fieldAccess, ExecutionContext ctx) {

private <J2 extends TypedTree> J2 found(J2 j, ExecutionContext ctx) {
JavaType.FullyQualified fqn = TypeUtils.asFullyQualified(j.getType());
typeUses.insertRow(ctx, new TypeUses.Row(
getCursor().firstEnclosingOrThrow(SourceFile.class).getSourcePath().toString(),
j.printTrimmed(getCursor().getParentTreeCursor()),
fqn == null ? j.getType().toString() : fqn.getFullyQualifiedName()
));
if (!j.getMarkers().findFirst(SearchResult.class).isPresent()) {
// Avoid double-counting results in the data table
typeUses.insertRow(ctx, new TypeUses.Row(
getCursor().firstEnclosingOrThrow(SourceFile.class).getSourcePath().toString(),
j.printTrimmed(getCursor().getParentTreeCursor()),
fqn == null ? j.getType().toString() : fqn.getFullyQualifiedName()
));
}
return SearchResult.found(j);
}
}
Expand Down

0 comments on commit ceb3dab

Please sign in to comment.