use of com.sun.source.tree.AnnotationTree in project error-prone by google.
the class AssistedInjectScoping method matchClass.
@Override
public final Description matchClass(ClassTree classTree, VisitorState state) {
MultiMatchResult<AnnotationTree> hasScopeAnnotations = CLASS_TO_SCOPE_ANNOTATIONS.multiMatchResult(classTree, state);
if (!hasScopeAnnotations.matches() || !HAS_ASSISTED_CONSTRUCTOR.matches(classTree, state)) {
return Description.NO_MATCH;
}
AnnotationTree annotationWithScopeAnnotation = hasScopeAnnotations.matchingNodes().get(0);
if (annotationWithScopeAnnotation == null) {
throw new IllegalStateException("Expected to find an annotation that was annotated with @ScopeAnnotation");
}
return describeMatch(annotationWithScopeAnnotation, SuggestedFix.delete(annotationWithScopeAnnotation));
}
use of com.sun.source.tree.AnnotationTree in project error-prone by google.
the class ParameterNotNullable method matchDereference.
private Description matchDereference(ExpressionTree dereferencedExpression, VisitorState state) {
Symbol dereferenced = ASTHelpers.getSymbol(dereferencedExpression);
if (dereferenced == null || dereferenced.getKind() != ElementKind.PARAMETER || dereferenced.type.isPrimitive()) {
// not a parameter dereference
return Description.NO_MATCH;
}
if (!TrustingNullnessAnalysis.hasNullableAnnotation(dereferenced)) {
return Description.NO_MATCH;
}
Nullness nullness = TrustingNullnessAnalysis.instance(state.context).getNullness(new TreePath(state.getPath(), dereferencedExpression), state.context);
if (nullness != Nullness.NULLABLE) {
return Description.NO_MATCH;
}
for (AnnotationTree anno : findDeclaration(state, dereferenced).getModifiers().getAnnotations()) {
if (ASTHelpers.getSymbol(anno).type.toString().endsWith(".Nullable")) {
return buildDescription(dereferencedExpression).setMessage("Nullable parameter not checked for null").addFix(SuggestedFix.delete(anno)).build();
}
}
// Shouldn't get here
return Description.NO_MATCH;
}
use of com.sun.source.tree.AnnotationTree in project error-prone by google.
the class QualifierOnMethodWithoutProvides method matchMethod.
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
MultiMatchResult<AnnotationTree> qualifierAnnotations = QUALIFIER_ANNOTATION_FINDER.multiMatchResult(tree, state);
if (qualifierAnnotations.matches() && NOT_ABSTRACT.matches(tree, state) && NOT_PROVIDES_METHOD.matches(tree, state)) {
// Otherwise, suggest removing the qualifier annotation
if (not(methodReturns(anyOf(isSameType(Suppliers.VOID_TYPE), isSameType(Suppliers.JAVA_LANG_VOID_TYPE)))).matches(tree, state)) {
if (INSIDE_GUICE_MODULE.matches(tree, state)) {
// Guice Module
SuggestedFix fix = SuggestedFix.builder().addStaticImport(GUICE_PROVIDES_ANNOTATION).prefixWith(tree, "@Provides ").build();
return describeMatch(tree, fix);
}
if (enclosingClass(IS_DAGGER_COMPONENT_OR_MODULE).matches(tree, state)) {
// Dagger component
SuggestedFix fix = SuggestedFix.builder().addStaticImport(DAGGER_PROVIDES_ANNOTATION).prefixWith(tree, "@Provides ").build();
return describeMatch(tree, fix);
}
}
List<AnnotationTree> matchingNodes = qualifierAnnotations.matchingNodes();
Builder fixBuilder = SuggestedFix.builder();
matchingNodes.forEach(fixBuilder::delete);
return describeMatch(matchingNodes.get(0), fixBuilder.build());
}
return Description.NO_MATCH;
}
use of com.sun.source.tree.AnnotationTree in project error-prone by google.
the class QualifierWithTypeUse method matchClass.
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
if (IS_QUALIFIER_WITH_TARGET.matches(tree, state)) {
MultiMatchResult<AnnotationTree> targetAnnotation = HAS_TARGET_ANNOTATION.multiMatchResult(tree, state);
if (targetAnnotation.matches()) {
AnnotationTree annotationTree = targetAnnotation.onlyMatchingNode();
Target target = ASTHelpers.getAnnotation(tree, Target.class);
if (hasTypeUseOrTypeParameter(target)) {
return describeMatch(annotationTree, removeTypeUse(target, annotationTree));
}
}
}
return Description.NO_MATCH;
}
use of com.sun.source.tree.AnnotationTree in project checker-framework by typetools.
the class DependentTypesHelper method checkType.
/**
* Checks all expression in the given annotated type to see if the expression string is an error
* string as specified by {@link DependentTypesError#isExpressionError}. If the annotated type
* has any errors, a flowexpr.parse.error is issued at the errorTree.
*
* @param atm annotated type to check for expression errors
* @param errorTree the tree at which to report any found errors
*/
public void checkType(AnnotatedTypeMirror atm, Tree errorTree) {
List<DependentTypesError> errors = new ExpressionErrorChecker().visit(atm);
if (errors == null || errors.isEmpty()) {
return;
}
if (errorTree.getKind() == Kind.VARIABLE) {
ModifiersTree modifiers = ((VariableTree) errorTree).getModifiers();
errorTree = ((VariableTree) errorTree).getType();
for (AnnotationTree annoTree : modifiers.getAnnotations()) {
for (Class<?> annoClazz : annoToElements.keySet()) {
if (annoTree.toString().contains(annoClazz.getSimpleName())) {
errorTree = annoTree;
break;
}
}
}
}
reportErrors(errorTree, errors);
}
Aggregations