Search in sources :

Example 1 with AField

use of scenelib.annotations.el.AField in project checker-framework by typetools.

the class WholeProgramInferenceScenes method updateInferredMethodReceiverType.

/**
 * Updates the receiver type of the method {@code methodElt} in the Scene of the method's
 * enclosing class based on the overridden method {@code overriddenMethod} receiver type.
 *
 * <p>For the receiver in methodElt:
 *
 * <ul>
 *   <li>If the Scene does not contain an annotated type for the receiver, then the type of the
 *       receiver on the overridden method will be added to the receiver in the Scene.
 *   <li>If the Scene previously contained an annotated type for the receiver, then its new type
 *       will be the LUB between the previous type and the type of the receiver on the
 *       overridden method.
 * </ul>
 *
 * <p>
 *
 * @param methodTree the tree of the method that contains the receiver
 * @param methodElt the element of the method
 * @param overriddenMethod the overridden method
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the receiver type
 */
@Override
public void updateInferredMethodReceiverType(MethodTree methodTree, ExecutableElement methodElt, AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf) {
    ClassSymbol classSymbol = getEnclosingClassSymbol(methodTree);
    String className = classSymbol.flatname.toString();
    String jaifPath = helper.getJaifPath(className);
    AClass clazz = helper.getAClass(className, jaifPath);
    String methodName = JVMNames.getJVMMethodName(methodElt);
    AMethod method = clazz.methods.vivify(methodName);
    AnnotatedDeclaredType argADT = overriddenMethod.getReceiverType();
    if (argADT != null) {
        AnnotatedTypeMirror paramATM = atf.getAnnotatedType(methodTree).getReceiverType();
        if (paramATM != null) {
            AField receiver = method.receiver;
            helper.updateAnnotationSetInScene(receiver.type, atf, jaifPath, argADT, paramATM, TypeUseLocation.RECEIVER);
        }
    }
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) AField(scenelib.annotations.el.AField)

Example 2 with AField

use of scenelib.annotations.el.AField in project checker-framework by typetools.

the class WholeProgramInferenceScenes method updateInferredExecutableParameterTypes.

/**
 * Helper method for updating parameter types based on calls to a method or constructor.
 */
private void updateInferredExecutableParameterTypes(ExecutableElement methodElt, AnnotatedTypeFactory atf, String jaifPath, AMethod method, List<Node> arguments) {
    for (int i = 0; i < arguments.size(); i++) {
        VariableElement ve = methodElt.getParameters().get(i);
        AnnotatedTypeMirror paramATM = atf.getAnnotatedType(ve);
        Node arg = arguments.get(i);
        Tree treeNode = arg.getTree();
        if (treeNode == null) {
            // https://github.com/typetools/checker-framework/issues/682
            continue;
        }
        AnnotatedTypeMirror argATM = atf.getAnnotatedType(treeNode);
        AField param = method.parameters.vivify(i);
        helper.updateAnnotationSetInScene(param.type, atf, jaifPath, argATM, paramATM, TypeUseLocation.PARAMETER);
    }
}
Also used : FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ImplicitThisLiteralNode(org.checkerframework.dataflow.cfg.node.ImplicitThisLiteralNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) Node(org.checkerframework.dataflow.cfg.node.Node) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) VariableElement(javax.lang.model.element.VariableElement) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) AField(scenelib.annotations.el.AField)

Example 3 with AField

use of scenelib.annotations.el.AField in project checker-framework by typetools.

the class WholeProgramInferenceScenes method updateInferredParameterType.

/**
 * Updates the parameter type represented by lhs of the method methodTree in the Scene of the
 * receiverTree's enclosing class based on assignments to the parameter inside the method body.
 *
 * <ul>
 *   <li>If the Scene does not contain an annotated type for that parameter, then the type of
 *       the respective value passed as argument in the method call methodInvNode will be added
 *       to the parameter in the Scene.
 *   <li>If the Scene previously contained an annotated type for that parameter, then its new
 *       type will be the LUB between the previous type and the type of the respective value
 *       passed as argument in the method call.
 * </ul>
 *
 * <p>
 *
 * @param lhs the node representing the parameter
 * @param rhs the node being assigned to the parameter
 * @param classTree the tree of the class that contains the parameter
 * @param methodTree the tree of the method that contains the parameter
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the parameter type
 */
@Override
public void updateInferredParameterType(LocalVariableNode lhs, Node rhs, ClassTree classTree, MethodTree methodTree, AnnotatedTypeFactory atf) {
    ClassSymbol classSymbol = getEnclosingClassSymbol(classTree, lhs);
    // https://github.com/typetools/checker-framework/issues/682
    if (classSymbol == null)
        return;
    String className = classSymbol.flatname.toString();
    String jaifPath = helper.getJaifPath(className);
    AClass clazz = helper.getAClass(className, jaifPath);
    String methodName = JVMNames.getJVMMethodName(methodTree);
    AMethod method = clazz.methods.vivify(methodName);
    List<? extends VariableTree> params = methodTree.getParameters();
    // Look-up parameter by name:
    for (int i = 0; i < params.size(); i++) {
        VariableTree vt = params.get(i);
        if (vt.getName().contentEquals(lhs.getName())) {
            Tree treeNode = rhs.getTree();
            if (treeNode == null) {
                // https://github.com/typetools/checker-framework/issues/682
                continue;
            }
            AnnotatedTypeMirror paramATM = atf.getAnnotatedType(vt);
            AnnotatedTypeMirror argATM = atf.getAnnotatedType(treeNode);
            AField param = method.parameters.vivify(i);
            helper.updateAnnotationSetInScene(param.type, atf, jaifPath, argATM, paramATM, TypeUseLocation.PARAMETER);
            break;
        }
    }
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) VariableTree(com.sun.source.tree.VariableTree) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) AField(scenelib.annotations.el.AField)

Example 4 with AField

use of scenelib.annotations.el.AField in project checker-framework by typetools.

the class ToIndexFileConverter method visit.

@Override
public Void visit(FieldDeclaration decl, AElement elem) {
    for (VariableDeclarator v : decl.getVariables()) {
        AClass clazz = (AClass) elem;
        AField field = clazz.fields.vivify(v.getNameAsString());
        visitDecl(decl, field);
        visitType(decl.getCommonType(), field.type);
    }
    return null;
}
Also used : AClass(scenelib.annotations.el.AClass) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) AField(scenelib.annotations.el.AField)

Example 5 with AField

use of scenelib.annotations.el.AField in project checker-framework by typetools.

the class ToIndexFileConverter method visit.

@Override
public Void visit(VariableDeclarationExpr expr, AElement elem) {
    List<AnnotationExpr> annos = expr.getAnnotations();
    AMethod method = (AMethod) elem;
    List<VariableDeclarator> varDecls = expr.getVariables();
    for (int i = 0; i < varDecls.size(); i++) {
        VariableDeclarator decl = varDecls.get(i);
        LocalLocation loc = new LocalLocation(decl.getNameAsString(), i);
        AField field = method.body.locals.vivify(loc);
        visitType(expr.getCommonType(), field.type);
        if (annos != null) {
            for (AnnotationExpr annoExpr : annos) {
                Annotation anno = extractAnnotation(annoExpr);
                field.tlAnnotationsHere.add(anno);
            }
        }
    }
    return null;
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) LocalLocation(scenelib.annotations.el.LocalLocation) AMethod(scenelib.annotations.el.AMethod) Annotation(scenelib.annotations.Annotation) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) AField(scenelib.annotations.el.AField)

Aggregations

AField (scenelib.annotations.el.AField)11 AClass (scenelib.annotations.el.AClass)8 AMethod (scenelib.annotations.el.AMethod)7 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)5 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)4 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)3 VariableElement (javax.lang.model.element.VariableElement)3 Annotation (scenelib.annotations.Annotation)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)2 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 ArrayType (com.github.javaparser.ast.type.ArrayType)2 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)2 PrimitiveType (com.github.javaparser.ast.type.PrimitiveType)2 ReferenceType (com.github.javaparser.ast.type.ReferenceType)2 Type (com.github.javaparser.ast.type.Type)2 TypeParameter (com.github.javaparser.ast.type.TypeParameter)2 VoidType (com.github.javaparser.ast.type.VoidType)2 WildcardType (com.github.javaparser.ast.type.WildcardType)2