use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class ReportVisitor method visitMethodInvocation.
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
ExecutableElement method = TreeUtils.elementFromUse(node);
checkReportUse(node, method);
boolean report = this.atypeFactory.getDeclAnnotation(method, ReportCall.class) != null;
if (!report) {
// Find all methods that are overridden by the called method
Map<AnnotatedDeclaredType, ExecutableElement> overriddenMethods = AnnotatedTypes.overriddenMethods(elements, atypeFactory, method);
for (Map.Entry<AnnotatedDeclaredType, ExecutableElement> pair : overriddenMethods.entrySet()) {
// AnnotatedDeclaredType overriddenType = pair.getKey();
ExecutableElement exe = pair.getValue();
report = this.atypeFactory.getDeclAnnotation(exe, ReportCall.class) != null;
if (report) {
// Always report the element that has the annotation.
// Alternative would be to always report the initial element.
method = exe;
break;
}
}
}
if (report) {
checker.report(Result.failure("methodcall", node, ElementUtils.getVerboseName(method)), node);
}
return super.visitMethodInvocation(node, p);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class GenericAnnotatedTypeFactory method getResultingTypeOfConstructorMemberReference.
/**
* Gets the type of the resulting constructor call of a MemberReferenceTree.
*
* @param memberReferenceTree MemberReferenceTree where the member is a constructor
* @param constructorType AnnotatedExecutableType of the declaration of the constructor
* @return AnnotatedTypeMirror of the resulting type of the constructor
*/
public AnnotatedTypeMirror getResultingTypeOfConstructorMemberReference(MemberReferenceTree memberReferenceTree, AnnotatedExecutableType constructorType) {
assert memberReferenceTree.getMode() == MemberReferenceTree.ReferenceMode.NEW;
// The return type for constructors should only have explicit annotations from the
// constructor. Recreate some of the logic from TypeFromTree.visitNewClass here.
// The return type of the constructor will be the type of the expression of the member
// reference tree.
AnnotatedDeclaredType constructorReturnType = (AnnotatedDeclaredType) fromTypeTree(memberReferenceTree.getQualifierExpression());
// Keep only explicit annotations and those from @Poly
AnnotatedTypes.copyOnlyExplicitConstructorAnnotations(this, constructorReturnType, constructorType);
// Now add back defaulting.
addComputedTypeAnnotations(memberReferenceTree.getQualifierExpression(), constructorReturnType);
return constructorReturnType;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class TypeFromExpressionVisitor method visitNewClass.
/**
* Creates an AnnotatedDeclaredType for the NewClassTree and adds, for each hierarchy, one of:
*
* <ul>
* <li>an explicit annotation on the new class expression ({@code new @HERE MyClass()}), or
* <li>an explicit annotation on the declaration of the class ({@code @HERE class MyClass
* {}}), or
* <li>an explicit annotation on the declaration of the constructor ({@code @HERE public
* MyClass() {}}), or
* <li>no annotation for this hierarchy.
* </ul>
*
* @param node NewClassTree
* @param f the type factory
* @return AnnotatedDeclaredType of {@code node}
*/
@Override
public AnnotatedTypeMirror visitNewClass(NewClassTree node, AnnotatedTypeFactory f) {
// constructorFromUse return type has implicits
// so use fromNewClass which does diamond inference and only
// contains explicit annotations and those inherited from the class declaration
AnnotatedDeclaredType type = f.fromNewClass(node);
// TODO: is there more to check? Can one annotate them?
if (isNewEnum(type)) {
return type;
}
// Add annotations that are on the constructor declaration.
// constructorFromUse gives us resolution of polymorphic qualifiers.
// However, it also applies defaulting, so we might apply too many qualifiers.
// Therefore, ensure to only add the qualifiers that are explicitly on
// the constructor, but then take the possibly substituted qualifier.
AnnotatedExecutableType ex = f.constructorFromUse(node).first;
AnnotatedTypes.copyOnlyExplicitConstructorAnnotations(f, type, ex);
return type;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class AnnotatedTypes method overriddenMethods.
/**
* A utility method that takes a Method element and returns a set of all elements that this
* method overrides (as {@link ExecutableElement}s)
*
* @param method the overriding method
* @return an unmodifiable set of {@link ExecutableElement}s representing the elements that
* method overrides
*/
public static Map<AnnotatedDeclaredType, ExecutableElement> overriddenMethods(Elements elements, AnnotatedTypeFactory atypeFactory, ExecutableElement method) {
final TypeElement elem = (TypeElement) method.getEnclosingElement();
final AnnotatedDeclaredType type = atypeFactory.getAnnotatedType(elem);
final Collection<AnnotatedDeclaredType> supertypes = getSuperTypes(type);
return overriddenMethods(elements, method, supertypes);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.
the class AnnotatedTypes method asOuterSuper.
/**
* Return the base type of type or any of its outer types that starts with the given type. If
* none exists, return null.
*
* @param type a type
* @param superType a type
*/
private static AnnotatedTypeMirror asOuterSuper(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type, AnnotatedTypeMirror superType) {
if (type.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType dt = (AnnotatedDeclaredType) type;
AnnotatedDeclaredType enclosingType = dt;
TypeMirror superTypeMirror = types.erasure(superType.getUnderlyingType());
while (enclosingType != null) {
TypeMirror enclosingTypeMirror = types.erasure(enclosingType.getUnderlyingType());
if (types.isSubtype(enclosingTypeMirror, superTypeMirror)) {
dt = enclosingType;
break;
}
enclosingType = enclosingType.getEnclosingType();
}
if (enclosingType == null) {
// checker.message(Kind.WARNING, msg);
return superType;
}
return asSuper(atypeFactory, dt, superType);
}
return asSuper(atypeFactory, type, superType);
}
Aggregations