Skip to content

Commit

Permalink
Don't flag module-info.java for not having default package
Browse files Browse the repository at this point in the history
RELNOTES: Don't flag module-info.java for not having default package

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=311760553
  • Loading branch information
sumitbhagwani authored and kluever committed May 16, 2020
1 parent 40f1cae commit 7be2c43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;

import com.google.common.io.Files;
import com.google.errorprone.BugPattern;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher;
Expand Down Expand Up @@ -53,6 +54,10 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
if (tree.getPackageName() != null) {
return Description.NO_MATCH;
}
// module-info.* is a special file name so whitelisting it.
if (Files.getNameWithoutExtension(ASTHelpers.getFileName(tree)).equals("module-info")) {
return Description.NO_MATCH;
}
return describeMatch(tree);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.errorprone.bugpatterns;

import static org.junit.Assume.assumeTrue;

import com.google.errorprone.CompilationTestHelper;
import com.google.errorprone.util.RuntimeVersion;
import org.junit.Test;
Expand Down Expand Up @@ -89,4 +91,16 @@ public void trailingComma() {
"class T {};")
.doTest();
}

@Test
public void moduleInfo() {
assumeTrue(RuntimeVersion.isAtLeast9());

compilationHelper
.addSourceLines(
"module-info.java", //
"module testmodule {",
"}")
.doTest();
}
}

0 comments on commit 7be2c43

Please sign in to comment.