use of com.google.errorprone.bugpatterns.threadsafety.ThreadSafety.Violation in project error-prone by google.
the class ImmutableChecker method matchClass.
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
ImmutableAnalysis analysis = new ImmutableAnalysis(this, state, wellKnownMutability);
if (tree.getSimpleName().length() == 0) {
// TODO(cushon): once Java 8 happens, require @Immutable on anonymous classes
return handleAnonymousClass(tree, state, analysis);
}
AnnotationInfo annotation = analysis.getImmutableAnnotation(tree, state);
if (annotation == null) {
// report an error if it extends/implements any @Immutable-annotated types.
return checkSubtype(tree, state);
}
// of the annotation are "trusted".
if (wellKnownMutability.getKnownImmutableClasses().containsValue(annotation)) {
return NO_MATCH;
}
// Check that the types in containerOf actually exist
Map<String, TypeVariableSymbol> typarams = new HashMap<>();
for (TypeParameterTree typaram : tree.getTypeParameters()) {
typarams.put(typaram.getName().toString(), (TypeVariableSymbol) ASTHelpers.getSymbol(typaram));
}
SetView<String> difference = Sets.difference(annotation.containerOf(), typarams.keySet());
if (!difference.isEmpty()) {
return buildDescription(tree).setMessage(String.format("could not find type(s) referenced by containerOf: %s", Joiner.on("', '").join(difference))).build();
}
ImmutableSet<String> immutableAndContainer = typarams.entrySet().stream().filter(e -> annotation.containerOf().contains(e.getKey()) && analysis.isImmutableTypeParameter(e.getValue())).map(Entry::getKey).collect(toImmutableSet());
if (!immutableAndContainer.isEmpty()) {
return buildDescription(tree).setMessage(String.format("using both @ImmutableTypeParameter and containerOf is redundant: %s", Joiner.on("', '").join(immutableAndContainer))).build();
}
// Main path for @Immutable-annotated types:
//
// Check that the fields (including inherited fields) are immutable, and
// validate the type hierarchy superclass.
ClassSymbol sym = ASTHelpers.getSymbol(tree);
Violation info = analysis.checkForImmutability(Optional.of(tree), immutableTypeParametersInScope(ASTHelpers.getSymbol(tree), state, analysis), ASTHelpers.getType(tree), (Tree matched, Violation violation) -> describeClass(matched, sym, annotation, violation));
if (!info.isPresent()) {
return NO_MATCH;
}
return describeClass(tree, sym, annotation, info).build();
}
Aggregations