Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In hasAnnotation, don't trigger completion for NullMarked. #4461

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
}
Loading