Skip to content

Commit

Permalink
In hasAnnotation, don't trigger completion for NullMarked.
Browse files Browse the repository at this point in the history
Completion can fail under `--release 8`, leading to `warning: unknown enum constant ElementType.MODULE`.

This CL is one of a variety of ways that I'll be addressing google/truth#1320. It alone should be sufficient (unless there are other problems that I'm unaware of), but I'll do more for people who might not upgrade Error Prone immediately, and I'll do something cleaner for the `NullArgumentForNonNullParameter` check that makes the known-problematic call to `hasAnnotation`.

PiperOrigin-RevId: 651801869
  • Loading branch information
cpovirk authored and Error Prone Team committed Jul 12, 2024
1 parent 8c1a828 commit c41ee92
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Streams.stream;
import static com.google.errorprone.VisitorState.memoize;
import static com.google.errorprone.matchers.JUnitMatchers.JUNIT4_RUN_WITH_ANNOTATION;
import static com.google.errorprone.matchers.Matchers.isSubtypeOf;
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
Expand Down Expand Up @@ -913,6 +914,14 @@ private static boolean isInherited(VisitorState state, Name annotationName) {
.get(
annotationName,
name -> {
if (name.equals(NULL_MARKED_NAME.get(state))) {
/*
* We avoid searching for @Inherited on NullMarked not just because we already know
* the answer but also because the search would cause issues under --release 8 on
* account of NullMarked's use of @Target(MODULE, ...).
*/
return false;
}
Symbol annotationSym = state.getSymbolFromName(annotationName);
if (annotationSym == null) {
return false;
Expand Down Expand Up @@ -2830,5 +2839,8 @@ public static Stream<? extends ExpressionTree> getCaseExpressions(CaseTree caseT
}
}

private static final Supplier<Name> NULL_MARKED_NAME =
memoize(state -> state.getName("org.jspecify.annotations.NullMarked"));

private ASTHelpers() {}
}

0 comments on commit c41ee92

Please sign in to comment.