Search in sources :

Example 1 with AnnotationFileElementTypes

use of org.checkerframework.framework.stub.AnnotationFileElementTypes in project checker-framework by typetools.

the class AnnotatedTypeFactory method applyFakeOverrides.

/**
 * Given a member and its type, returns the type with fake overrides applied to it.
 *
 * @param receiverType the type of the class that contains member (or a subtype of it)
 * @param member a type member, such as a method or field
 * @param memberType the type of {@code member}
 * @return {@code memberType}, adjusted according to fake overrides
 */
private AnnotatedExecutableType applyFakeOverrides(AnnotatedTypeMirror receiverType, Element member, AnnotatedExecutableType memberType) {
    // Currently, handle only methods, not fields.  TODO: Handle fields.
    if (memberType.getKind() != TypeKind.EXECUTABLE) {
        return memberType;
    }
    AnnotationFileElementTypes afet = stubTypes;
    AnnotatedExecutableType methodType = afet.getFakeOverride(member, receiverType);
    if (methodType == null) {
        methodType = memberType;
    }
    return methodType;
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) AnnotationFileElementTypes(org.checkerframework.framework.stub.AnnotationFileElementTypes)

Example 2 with AnnotationFileElementTypes

use of org.checkerframework.framework.stub.AnnotationFileElementTypes in project checker-framework by typetools.

the class AnnotatedTypeFactory method setRoot.

/**
 * Set the CompilationUnitTree that should be used.
 *
 * @param root the new compilation unit to use
 */
public void setRoot(@Nullable CompilationUnitTree root) {
    if (root != null && wholeProgramInference != null) {
        for (Tree typeDecl : root.getTypeDecls()) {
            if (typeDecl.getKind() == Tree.Kind.CLASS) {
                ClassTree classTree = (ClassTree) typeDecl;
                wholeProgramInference.preprocessClassTree(classTree);
            }
        }
    }
    this.root = root;
    // if this isn't a GenericATF, then it must clear it itself.
    if (!(this instanceof GenericAnnotatedTypeFactory)) {
        artificialTreeToEnclosingElementMap.clear();
    }
    if (shouldCache) {
        // Clear the caches with trees because once the compilation unit changes,
        // the trees may be modified and lose type arguments.
        elementToTreeCache.clear();
        fromExpressionTreeCache.clear();
        fromMemberTreeCache.clear();
        fromTypeTreeCache.clear();
        classAndMethodTreeCache.clear();
    // There is no need to clear the following cache, it is limited by cache size and it
    // contents won't change between compilation units.
    // elementCache.clear();
    }
    if (root != null && checker.hasOption("ajava")) {
        // Search for an ajava file with annotations for the current source file and the current
        // checker. It will be in a directory specified by the "ajava" option in a subdirectory
        // corresponding to this file's package. For example, a file in package a.b would be in a
        // subdirectory a/b. The filename is ClassName-checker.qualified.name.ajava. If such a file
        // exists, read its detailed annotation data, including annotations on private elements.
        String packagePrefix = root.getPackageName() != null ? TreeUtils.nameExpressionToString(root.getPackageName()) + "." : "";
        // The method getName() returns a path.
        String className = root.getSourceFile().getName();
        // Extract the basename.
        int lastSeparator = className.lastIndexOf(File.separator);
        if (lastSeparator != -1) {
            className = className.substring(lastSeparator + 1);
        }
        // Drop the ".java" extension.
        if (className.endsWith(".java")) {
            className = className.substring(0, className.length() - ".java".length());
        }
        String qualifiedName = packagePrefix + className;
        for (String ajavaLocation : checker.getOption("ajava").split(File.pathSeparator)) {
            String ajavaPath = ajavaLocation + File.separator + qualifiedName.replaceAll("\\.", "/") + "-" + checker.getClass().getCanonicalName() + ".ajava";
            File ajavaFile = new File(ajavaPath);
            if (ajavaFile.exists()) {
                currentFileAjavaTypes = new AnnotationFileElementTypes(this);
                currentFileAjavaTypes.parseAjavaFileWithTree(ajavaPath, root);
                break;
            }
        }
    } else {
        currentFileAjavaTypes = null;
    }
}
Also used : AnnotationFileElementTypes(org.checkerframework.framework.stub.AnnotationFileElementTypes) NewClassTree(com.sun.source.tree.NewClassTree) ClassTree(com.sun.source.tree.ClassTree) CompoundAssignmentTree(com.sun.source.tree.CompoundAssignmentTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) TypeCastTree(com.sun.source.tree.TypeCastTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) ReturnTree(com.sun.source.tree.ReturnTree) VariableTree(com.sun.source.tree.VariableTree) NewClassTree(com.sun.source.tree.NewClassTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) NewArrayTree(com.sun.source.tree.NewArrayTree) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) BinaryTree(com.sun.source.tree.BinaryTree) ClassTree(com.sun.source.tree.ClassTree) MemberReferenceTree(com.sun.source.tree.MemberReferenceTree) File(java.io.File) FromStubFile(org.checkerframework.framework.qual.FromStubFile)

Aggregations

AnnotationFileElementTypes (org.checkerframework.framework.stub.AnnotationFileElementTypes)2 AnnotationTree (com.sun.source.tree.AnnotationTree)1 AssignmentTree (com.sun.source.tree.AssignmentTree)1 BinaryTree (com.sun.source.tree.BinaryTree)1 ClassTree (com.sun.source.tree.ClassTree)1 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 CompoundAssignmentTree (com.sun.source.tree.CompoundAssignmentTree)1 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)1 ExpressionTree (com.sun.source.tree.ExpressionTree)1 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)1 MemberReferenceTree (com.sun.source.tree.MemberReferenceTree)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 MethodTree (com.sun.source.tree.MethodTree)1 NewArrayTree (com.sun.source.tree.NewArrayTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1 ReturnTree (com.sun.source.tree.ReturnTree)1 Tree (com.sun.source.tree.Tree)1 TypeCastTree (com.sun.source.tree.TypeCastTree)1 VariableTree (com.sun.source.tree.VariableTree)1 File (java.io.File)1