Skip to content

Commit

Permalink
Enforce that @element is only used on @ThreadSafe-annotated classes i…
Browse files Browse the repository at this point in the history
…n the same way as @TypeParameter.

And fix the diagnostic message.

I think this will have minimal hits, but I'll flag if that turns out to be wrong.

PiperOrigin-RevId: 526084157
  • Loading branch information
graememorgan authored and Error Prone Team committed Apr 25, 2023
1 parent f6ad840 commit 38f2d66
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,22 @@ public Violation visitType(Type type, Void s) {
}

/**
* Returns true if the given type parameter's declaration is annotated with {@link
* #typeParameterAnnotation} indicated it will only ever be instantiated with thread-safe types.
* Returns whether the given type parameter's declaration is annotated with {@link
* #typeParameterAnnotation} indicating it will only ever be instantiated with thread-safe types.
*/
public boolean hasThreadSafeTypeParameterAnnotation(TypeVariableSymbol symbol) {
return typeParameterAnnotation != null
&& symbol.getAnnotationMirrors().stream()
.anyMatch(t -> typeParameterAnnotation.contains(t.type.tsym.flatName().toString()));
return symbol.getAnnotationMirrors().stream()
.anyMatch(t -> typeParameterAnnotation.contains(t.type.tsym.flatName().toString()));
}

/**
* Returns whether the given type parameter's declaration is annotated with {@link
* #containerOfAnnotation} indicating its type-safety determines the type-safety of the outer
* class.
*/
public boolean hasThreadSafeElementAnnotation(TypeVariableSymbol symbol) {
return symbol.getAnnotationMirrors().stream()
.anyMatch(t -> containerOfAnnotation.contains(t.type.tsym.flatName().toString()));
}

/**
Expand Down

0 comments on commit 38f2d66

Please sign in to comment.