use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class NullnessAnnotatedTypeFactory method adaptGetClassReturnTypeToReceiver.
@Override
public void adaptGetClassReturnTypeToReceiver(final AnnotatedExecutableType getClassType, final AnnotatedTypeMirror receiverType) {
super.adaptGetClassReturnTypeToReceiver(getClassType, receiverType);
// Make the wildcard always @NonNull, regardless of the declared type.
final AnnotatedDeclaredType returnAdt = (AnnotatedDeclaredType) getClassType.getReturnType();
final List<AnnotatedTypeMirror> typeArgs = returnAdt.getTypeArguments();
final AnnotatedWildcardType classWildcardArg = (AnnotatedWildcardType) typeArgs.get(0);
classWildcardArg.getExtendsBoundField().replaceAnnotation(NONNULL);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class NullnessVisitor method checkForRedundantTests.
/**
* Reports an error if a comparison of a @NonNull expression with the null literal is performed.
*/
protected void checkForRedundantTests(BinaryTree node) {
final ExpressionTree leftOp = node.getLeftOperand();
final ExpressionTree rightOp = node.getRightOperand();
// respect command-line option
if (!checker.getLintOption(AbstractNullnessChecker.LINT_REDUNDANTNULLCOMPARISON, AbstractNullnessChecker.LINT_DEFAULT_REDUNDANTNULLCOMPARISON)) {
return;
}
// equality tests
if ((node.getKind() == Tree.Kind.EQUAL_TO || node.getKind() == Tree.Kind.NOT_EQUAL_TO)) {
AnnotatedTypeMirror left = atypeFactory.getAnnotatedType(leftOp);
AnnotatedTypeMirror right = atypeFactory.getAnnotatedType(rightOp);
if (leftOp.getKind() == Tree.Kind.NULL_LITERAL && right.hasEffectiveAnnotation(NONNULL))
checker.report(Result.warning(KNOWN_NONNULL, rightOp.toString()), node);
else if (rightOp.getKind() == Tree.Kind.NULL_LITERAL && left.hasEffectiveAnnotation(NONNULL))
checker.report(Result.warning(KNOWN_NONNULL, leftOp.toString()), node);
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class NullnessVisitor method checkMethodInvocability.
@Override
protected void checkMethodInvocability(AnnotatedExecutableType method, MethodInvocationTree node) {
if (!TreeUtils.isSelfAccess(node) && // Static methods don't have a receiver
method.getReceiverType() != null) {
// TODO: should all or some constructors be excluded?
// method.getElement().getKind() != ElementKind.CONSTRUCTOR) {
Set<AnnotationMirror> recvAnnos = atypeFactory.getReceiverType(node).getAnnotations();
AnnotatedTypeMirror methodReceiver = method.getReceiverType().getErased();
AnnotatedTypeMirror treeReceiver = methodReceiver.shallowCopy(false);
AnnotatedTypeMirror rcv = atypeFactory.getReceiverType(node);
treeReceiver.addAnnotations(rcv.getEffectiveAnnotations());
// "dereference.of.nullable" message).
if (treeReceiver.hasAnnotation(NULLABLE) || recvAnnos.contains(MONOTONIC_NONNULL)) {
return;
}
}
super.checkMethodInvocability(method, node);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class SystemGetPropertyHandler method handle.
public void handle(MethodInvocationTree tree, AnnotatedExecutableType method) {
if (TreeUtils.isMethodInvocation(tree, systemGetProperty, env)) {
List<? extends ExpressionTree> args = tree.getArguments();
assert args.size() == 1;
ExpressionTree arg = args.get(0);
if (arg.getKind() == Tree.Kind.STRING_LITERAL) {
String literal = (String) ((LiteralTree) arg).getValue();
if (systemProperties.contains(literal)) {
AnnotatedTypeMirror type = method.getReturnType();
type.replaceAnnotation(factory.NONNULL);
}
}
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class UnitsRelationsTools method removePrefix.
/**
* Removes the Prefix value from an Annotated Type, by constructing and returning a copy of the
* Annotated Type without the prefix
*
* @param elements the Element Utilities from a checker's processing environment, typically
* obtained by calling env.getElementUtils() in init() of a Units Relations implementation
* @param annoType an AnnotatedTypeMirror representing a Units Annotated Type
* @return a copy of the Annotated Type without the prefix
*/
public static AnnotatedTypeMirror removePrefix(@Nullable final Elements elements, @Nullable final AnnotatedTypeMirror annoType) {
// deep copy the Annotated Type Mirror without any of the Annotations
AnnotatedTypeMirror result = annoType.deepCopy(false);
// get all of the original Annotations in the Annotated Type
Set<AnnotationMirror> annos = annoType.getAnnotations();
// does
for (AnnotationMirror anno : annos) {
// try to clean the Annotation Mirror of the Prefix
AnnotationMirror cleanedMirror = removePrefix(elements, anno);
// if successful, add the cleaned annotation to the deep copy
if (cleanedMirror != null) {
result.addAnnotation(cleanedMirror);
} else // if unsuccessful, add the original annotation
{
result.addAnnotation(anno);
}
}
return result;
}
Aggregations