use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class BaseTypeVisitor method checkTypecastSafety.
/**
* Issues a warning if the given explicitly-written typecast is unsafe. Does nothing if the lint
* option "cast:unsafe" is not set. Only primary qualifiers are checked unless the command line
* option "checkCastElementType" is supplied.
*
* @param typeCastTree an explicitly-written typecast
*/
protected void checkTypecastSafety(TypeCastTree typeCastTree) {
if (!checker.getLintOption("cast:unsafe", true)) {
return;
}
AnnotatedTypeMirror castType = atypeFactory.getAnnotatedType(typeCastTree);
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(typeCastTree.getExpression());
boolean calledOnce = false;
for (AnnotationMirror top : atypeFactory.getQualifierParameterHierarchies(castType)) {
if (!isInvariantTypeCastSafe(castType, exprType, top)) {
checker.reportError(typeCastTree, "invariant.cast.unsafe", exprType.toString(true), castType.toString(true));
}
// don't issue cast unsafe warning.
calledOnce = true;
}
// the input types to be subtypes according to Java.
if (!calledOnce && !isTypeCastSafe(castType, exprType)) {
checker.reportWarning(typeCastTree, "cast.unsafe", exprType.toString(true), castType.toString(true));
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class BaseTypeVisitor method checkThisOrSuperConstructorCall.
/**
* Checks that the following rule is satisfied: The type on a constructor declaration must be a
* supertype of the return type of "this()" or "super()" invocation within that constructor.
*
* @param call the AST node for the constructor call
* @param errorKey the error message key to use if the check fails
*/
protected void checkThisOrSuperConstructorCall(MethodInvocationTree call, @CompilerMessageKey String errorKey) {
TreePath path = atypeFactory.getPath(call);
MethodTree enclosingMethod = TreePathUtil.enclosingMethod(path);
AnnotatedTypeMirror superType = atypeFactory.getAnnotatedType(call);
AnnotatedExecutableType constructorType = atypeFactory.getAnnotatedType(enclosingMethod);
Set<? extends AnnotationMirror> topAnnotations = atypeFactory.getQualifierHierarchy().getTopAnnotations();
for (AnnotationMirror topAnno : topAnnotations) {
AnnotationMirror superTypeMirror = superType.getAnnotationInHierarchy(topAnno);
AnnotationMirror constructorTypeMirror = constructorType.getReturnType().getAnnotationInHierarchy(topAnno);
if (!atypeFactory.getQualifierHierarchy().isSubtype(superTypeMirror, constructorTypeMirror)) {
checker.reportError(call, errorKey, constructorTypeMirror, call, superTypeMirror);
}
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class MethodSignature method getMethodNamesFromStringArg.
/**
* Returns the string values for the argument passed. The String Values are estimated using the
* Value Checker.
*
* @param arg ExpressionTree whose string values are sought
* @return string values of arg or the empty list if no values were found
*/
private List<String> getMethodNamesFromStringArg(ExpressionTree arg) {
ValueAnnotatedTypeFactory valueATF = getTypeFactoryOfSubchecker(ValueChecker.class);
AnnotatedTypeMirror valueAnno = valueATF.getAnnotatedType(arg);
AnnotationMirror annotation = valueAnno.getAnnotation(StringVal.class);
if (annotation != null) {
return AnnotationUtils.getElementValueArray(annotation, stringValValueElement, String.class);
} else {
return EMPTY_STRING_LIST;
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method getToValueFromIntRange.
/**
* Finds the appropriate value for the {@code to} value of an annotated type mirror containing an
* {@code IntRange} annotation.
*
* @param atm an annotated type mirror that contains an {@code IntRange} annotation
* @return either the to value from the passed int range annotation, or the maximum value of the
* domain of the underlying type (i.e. Integer.MAX_VALUE if the underlying type is int)
*/
public long getToValueFromIntRange(AnnotatedTypeMirror atm) {
TypeMirror type = atm.getUnderlyingType();
long defaultValue = TypeKindUtils.maxValue(toPrimitiveIntegralTypeKind(type));
AnnotationMirror intRangeAnno = atm.getAnnotation(IntRange.class);
return getIntRangeToValue(intRangeAnno, defaultValue);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method getDummyAssignedTo.
/**
* Returns the annotation type mirror for the type of {@code expressionTree} with default
* annotations applied.
*/
@Override
public AnnotatedTypeMirror getDummyAssignedTo(ExpressionTree expressionTree) {
TypeMirror type = TreeUtils.typeOf(expressionTree);
if (type.getKind() != TypeKind.VOID) {
AnnotatedTypeMirror atm = type(expressionTree);
addDefaultAnnotations(atm);
return atm;
}
return null;
}
Aggregations