use of com.google.errorprone.matchers.Description.Builder 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();
}
use of com.google.errorprone.matchers.Description.Builder in project error-prone by google.
the class HidingField method checkForHiddenFields.
private void checkForHiddenFields(List<VariableTree> originalClassMembers, Map<Name, VarSymbol> parentMembers, Name parentClassName, ClassTree classTree, VisitorState visitorState) {
Iterator<VariableTree> origVariableIterator = originalClassMembers.iterator();
VariableTree origVariable = null;
while (origVariableIterator.hasNext()) {
origVariable = origVariableIterator.next();
if (parentMembers.containsKey(origVariable.getName())) {
if (isPackagePrivateAndInDiffPackage(parentMembers.get(origVariable.getName()), classTree)) {
continue;
}
Builder matchDesc = buildDescription(origVariable);
matchDesc.setMessage("Hiding fields of superclasses may cause confusion and errors. " + "This field is hiding a field of the same name in superclass: " + parentClassName);
visitorState.reportMatch(matchDesc.build());
origVariableIterator.remove();
}
}
}
Aggregations