use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class DependentTypesHelper method checkTypeVariables.
private void checkTypeVariables(MethodTree node, AnnotatedExecutableType methodType) {
Element ele = TreeUtils.elementFromDeclaration(node);
TypeMirror enclosingType = ElementUtils.enclosingClass(ele).asType();
FlowExpressionContext context = FlowExpressionContext.buildContextForMethodDeclaration(node, enclosingType, factory.getContext());
for (int i = 0; i < methodType.getTypeVariables().size(); i++) {
AnnotatedTypeMirror atm = methodType.getTypeVariables().get(i);
standardizeDoNotUseLocals(context, factory.getPath(node), atm);
checkType(atm, node.getTypeParameters().get(i));
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class DependentTypesHelper method checkMethod.
/**
* Checks all expressions in the method declaration AnnotatedTypeMirror to see if the expression
* string is an error string as specified by DependentTypesError#isExpressionError. If the
* annotated type has any errors, a flowexpr.parse.error is issued.
*
* @param methodTree method to check
* @param type annotated type of the method
*/
public void checkMethod(MethodTree methodTree, AnnotatedExecutableType type) {
// Parameters and receivers are checked by visitVariable
// So only type parameters and return type need to be checked here.
checkTypeVariables(methodTree, type);
// Check return type
if (type.getReturnType().getKind() != TypeKind.VOID) {
AnnotatedTypeMirror returnType = factory.getMethodReturnType(methodTree);
checkType(returnType, methodTree.getReturnType());
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class ElementAnnotationUtil method getLocationTypeADT.
/**
* Given a TypePath into a declared type, return the component type that is located at the end
* of the TypePath
*
* @param type a type containing the type specified by location
* @param location a type path into type
* @return the type specified by location
*/
private static AnnotatedTypeMirror getLocationTypeADT(AnnotatedDeclaredType type, List<TypeAnnotationPosition.TypePathEntry> location) {
// List order by outer most type to inner most type.
ArrayDeque<AnnotatedDeclaredType> outerToInner = new ArrayDeque<>();
AnnotatedDeclaredType enclosing = type;
while (enclosing != null) {
outerToInner.addFirst(enclosing);
enclosing = enclosing.getEnclosingType();
}
// Create a linked list of the location, so removing the first element is easier.
// Also, the `tail` operation wouldn't work with a Deque.
@SuppressWarnings("JdkObsolete") LinkedList<TypePathEntry> tailOfLocations = new LinkedList<>(location);
boolean error = false;
while (!tailOfLocations.isEmpty()) {
TypePathEntry currentLocation = tailOfLocations.removeFirst();
switch(currentLocation.tag) {
case INNER_TYPE:
outerToInner.removeFirst();
break;
case TYPE_ARGUMENT:
AnnotatedDeclaredType innerType = outerToInner.getFirst();
if (currentLocation.arg < innerType.getTypeArguments().size()) {
AnnotatedTypeMirror typeArg = innerType.getTypeArguments().get(currentLocation.arg);
return getTypeAtLocation(typeArg, tailOfLocations);
} else {
error = true;
break;
}
default:
error = true;
}
if (error) {
break;
}
}
if (outerToInner.isEmpty() || error) {
ErrorReporter.errorAbort("ElementAnnotationUtil.getLocationTypeADT: invalid location %s for type: %s", location, type);
}
return outerToInner.getFirst();
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class TypeVarUseApplier method extractAndApply.
/**
* Applies the bound annotations from the declaration of the type parameter and then applies the
* explicit annotations written on the type variable
*/
public void extractAndApply() {
ElementAnnotationUtil.addAnnotationsFromElement(typeVariable, useElem.getAnnotationMirrors());
// apply declaration annotations
ElementAnnotationApplier.apply(typeVariable, declarationElem, typeFactory);
final List<Attribute.TypeCompound> annotations = getAnnotations(useElem, declarationElem);
final List<Attribute.TypeCompound> typeVarAnnotations;
if (arrayType != null) {
// if the outer-most type is an array type then we want to ensure the outer annotations
// are not applied as the type variables primary annotation
typeVarAnnotations = removeComponentAnnotations(arrayType, annotations);
ElementAnnotationUtil.annotateViaTypeAnnoPosition(arrayType, annotations);
} else {
typeVarAnnotations = annotations;
}
for (final Attribute.TypeCompound annotation : typeVarAnnotations) {
typeVariable.removeAnnotationInHierarchy(annotation);
typeVariable.addAnnotation(annotation);
final List<? extends AnnotatedTypeMirror> upperBounds;
if (typeVariable.getUpperBound() instanceof AnnotatedIntersectionType) {
upperBounds = typeVariable.getUpperBound().directSuperTypes();
} else {
upperBounds = Arrays.asList(typeVariable.getUpperBound());
}
// TODO: to all of them? Que dealio? What should we do?
for (final AnnotatedTypeMirror bound : upperBounds) {
bound.removeAnnotationInHierarchy(annotation);
bound.addAnnotation(annotation);
}
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class BaseTypeVisitor method checkTypecastRedundancy.
protected void checkTypecastRedundancy(TypeCastTree node, Void p) {
if (!checker.getLintOption("cast:redundant", false)) {
return;
}
AnnotatedTypeMirror castType = atypeFactory.getAnnotatedType(node);
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(node.getExpression());
if (castType.equals(exprType)) {
checker.report(Result.warning("cast.redundant", castType), node);
}
}
Aggregations