Skip to content

Commit

Permalink
NonApiType: prefer using Module instead of AbstractModule.
Browse files Browse the repository at this point in the history
AbstractModule is an implementation detail; a type that shouldn't really be referred to.

PiperOrigin-RevId: 713715344
  • Loading branch information
graememorgan authored and Error Prone Team committed Jan 9, 2025
1 parent 91ff1af commit 195988f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ public final class NonApiType extends BugChecker implements MethodTreeMatcher {
"Prefer accepting an Iterable or Collection instead. " + STREAM_LINK,
ApiElementType.PARAMETER),

// Guice
withAnyVisibility(
isExactType("com.google.inject.AbstractModule"),
"Prefer using Module instead.",
ApiElementType.ANY),

// ProtoTime
withPublicVisibility(
isExactType("com.google.protobuf.Duration"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,28 @@ public record RecordWithImmutableSet(ImmutableSet<String> ids) {
""")
.doTest();
}

@Test
public void guiceModules() {
helper
.addSourceLines(
"Test.java",
"""
import com.google.inject.AbstractModule;
import com.google.inject.Module;
public class Test extends AbstractModule {
// BUG: Diagnostic contains: NonApiType
public AbstractModule test() {
return new AbstractModule() {};
}
// Exact type, no finding.
public Test test2() {
return new Test();
}
}
""")
.doTest();
}
}

0 comments on commit 195988f

Please sign in to comment.