Search in sources :

Example 71 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class TypeOutputtingChecker method printClassType.

/**
 * Prints the types of the class and all of its enclosing fields, methods, and inner classes
 */
protected static void printClassType(TypeElement typeElt, AnnotatedTypeFactory atypeFactory) {
    assert typeElt != null;
    String simpleName = typeElt.getSimpleName().toString();
    // Output class info
    AnnotatedDeclaredType type = atypeFactory.fromElement(typeElt);
    System.out.println(simpleName + "\t" + type + "\t" + type.directSuperTypes());
    // output fields and methods
    for (Element enclosedElt : typeElt.getEnclosedElements()) {
        if (enclosedElt instanceof TypeElement) {
            printClassType((TypeElement) enclosedElt, atypeFactory);
        }
        if (!enclosedElt.getKind().isField() && !(enclosedElt instanceof ExecutableElement))
            continue;
        AnnotatedTypeMirror memberType = atypeFactory.fromElement(enclosedElt);
        System.out.println(simpleName + "." + enclosedElt + "\t\t" + memberType);
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 72 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class ReportVisitor method visitMethod.

@Override
public Void visitMethod(MethodTree node, Void p) {
    ExecutableElement method = TreeUtils.elementFromDeclaration(node);
    boolean report = false;
    // Check all overridden methods.
    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, ReportOverride.class) != null;
        if (report) {
            // Set method to report the right method, if found.
            method = exe;
            break;
        }
    }
    if (report) {
        checker.report(Result.failure("override", node, ElementUtils.getVerboseName(method)), node);
    }
    return super.visitMethod(node, p);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) Map(java.util.Map) ReportOverride(org.checkerframework.common.util.report.qual.ReportOverride)

Aggregations

AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)72 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)26 ArrayList (java.util.ArrayList)19 ExpressionTree (com.sun.source.tree.ExpressionTree)18 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)18 MethodTree (com.sun.source.tree.MethodTree)17 Tree (com.sun.source.tree.Tree)16 ClassTree (com.sun.source.tree.ClassTree)14 VariableTree (com.sun.source.tree.VariableTree)14 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)13 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)12 NewClassTree (com.sun.source.tree.NewClassTree)12 ExecutableElement (javax.lang.model.element.ExecutableElement)11 IdentifierTree (com.sun.source.tree.IdentifierTree)10 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)10 NewArrayTree (com.sun.source.tree.NewArrayTree)9 ReturnTree (com.sun.source.tree.ReturnTree)9 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)9 AnnotatedWildcardType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType)9 AssignmentTree (com.sun.source.tree.AssignmentTree)8