Skip to content

Commit

Permalink
Fix package-info.java identification on Windows; alternative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Jun 22, 2021
1 parent 5af2b42 commit df69d37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Expand Up @@ -23,8 +23,8 @@
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.CompilationUnitTree;
import java.io.File;

/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
Expand All @@ -37,8 +37,8 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
if (tree.getSourceFile() == null) {
return NO_MATCH;
}
String name = tree.getSourceFile().getName();
int idx = name.lastIndexOf(File.separatorChar);
String name = ASTHelpers.getFileName(tree);
int idx = name.lastIndexOf('/');
if (idx != -1) {
name = name.substring(idx + 1);
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.ImportTree;
Expand All @@ -44,7 +45,6 @@
import com.sun.tools.javac.code.Symbol.PackageSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.util.Position;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -189,8 +189,8 @@ public Void visitIdentifier(IdentifierTree identifierTree, Void aVoid) {
}

private static boolean isPackageInfo(CompilationUnitTree tree) {
String name = tree.getSourceFile().getName();
int idx = name.lastIndexOf(File.separatorChar);
String name = ASTHelpers.getFileName(tree);
int idx = name.lastIndexOf('/');
if (idx != -1) {
name = name.substring(idx + 1);
}
Expand Down

0 comments on commit df69d37

Please sign in to comment.