use of com.google.errorprone.bugpatterns.threadsafety.ImmutableAnalysis.ViolationReporter in project error-prone by google.
the class ImmutableChecker method handleAnonymousClass.
// Anonymous classes
/**
* Check anonymous implementations of {@code @Immutable} types.
*/
private Description handleAnonymousClass(ClassTree tree, VisitorState state, ImmutableAnalysis analysis) {
ClassSymbol sym = ASTHelpers.getSymbol(tree);
if (sym == null) {
return NO_MATCH;
}
Type superType = immutableSupertype(sym, state);
if (superType == null) {
return NO_MATCH;
}
// We don't need to check that the superclass has an immutable instantiation.
// The anonymous instance can only be referred to using a superclass type, so
// the type arguments will be validated at any type use site where we care about
// the instance's immutability.
//
// Also, we have no way to express something like:
//
// public static <@Immutable T> ImmutableBox<T> create(T t) {
// return new ImmutableBox<>(t);
// }
ImmutableSet<String> typarams = immutableTypeParametersInScope(sym, state, analysis);
Violation info = analysis.areFieldsImmutable(Optional.of(tree), typarams, ASTHelpers.getType(tree), new ViolationReporter() {
@Override
public Builder describe(Tree tree, Violation info) {
return describeAnonymous(tree, superType, info);
}
});
if (!info.isPresent()) {
return NO_MATCH;
}
return describeAnonymous(tree, superType, info).build();
}
Aggregations