Skip to content

Commit

Permalink
Don't make UnnecessarilyFullyQualified suggestions in package-infos
Browse files Browse the repository at this point in the history
Fixes #1652

PiperOrigin-RevId: 350601073
  • Loading branch information
cushon authored and Error Prone Team committed Jan 8, 2021
1 parent 886ed1c commit 50bff04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -71,6 +71,9 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
t -> getSymbol(tree) != null && !getGeneratedBy(getSymbol(tree), state).isEmpty())) {
return NO_MATCH;
}
if (isPackageInfo(tree)) {
return NO_MATCH;
}
Table<Name, TypeSymbol, List<TreePath>> table = HashBasedTable.create();
Set<Name> identifiersSeen = new HashSet<>();
new SuppressibleTreePathScanner<Void, Void>() {
Expand Down Expand Up @@ -183,4 +186,13 @@ public Void visitIdentifier(IdentifierTree identifierTree, Void aVoid) {
}
return NO_MATCH;
}

private boolean isPackageInfo(CompilationUnitTree tree) {
String name = tree.getSourceFile().getName();
int idx = name.lastIndexOf('/');
if (idx != -1) {
name = name.substring(idx + 1);
}
return name.equals("package-info.java");
}
}
Expand Up @@ -16,6 +16,7 @@
package com.google.errorprone.bugpatterns;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.CompilationTestHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -130,4 +131,18 @@ public void builder() {
"}")
.doTest();
}

@Test
public void packageInfo() {
CompilationTestHelper.newInstance(UnnecessarilyFullyQualified.class, getClass())
.addSourceLines(
"a/A.java", //
"package a;",
"public @interface A {}")
.addSourceLines(
"b/package-info.java", //
"@a.A",
"package b;")
.doTest();
}
}

0 comments on commit 50bff04

Please sign in to comment.