Search in sources :

Example 11 with AMethod

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

the class WholeProgramInferenceScenes method updateInferredMethodParameterTypes.

/**
 * Updates the parameter types of the method methodElt in the Scene of the receiverTree's
 * enclosing class based on the arguments to the method.
 *
 * <p>For each method parameter in methodElt:
 *
 * <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 methodInvNode the node representing a method invocation
 * @param receiverTree the Tree of the class that contains the method being invoked
 * @param methodElt the element of the method being invoked
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the method parameters' types
 */
@Override
public void updateInferredMethodParameterTypes(MethodInvocationNode methodInvNode, Tree receiverTree, ExecutableElement methodElt, AnnotatedTypeFactory atf) {
    if (receiverTree == null) {
        // https://github.com/typetools/checker-framework/issues/682
        return;
    }
    ClassSymbol classSymbol = getEnclosingClassSymbol(receiverTree);
    if (classSymbol == null) {
        // https://github.com/typetools/checker-framework/issues/682
        return;
    }
    // https://github.com/typetools/checker-framework/issues/682
    if (!classSymbol.getEnclosedElements().contains((Symbol) methodElt)) {
        return;
    }
    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);
    List<Node> arguments = methodInvNode.getArguments();
    updateInferredExecutableParameterTypes(methodElt, atf, jaifPath, method, arguments);
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) 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) AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod)

Example 12 with AMethod

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

the class WholeProgramInferenceScenesHelper method removeIgnoredAnnosFromScene.

/**
 * Removes all annotations that should be ignored from an AScene. (See {@link #shouldIgnore}).
 */
private void removeIgnoredAnnosFromScene(AScene scene) {
    for (AClass aclass : scene.classes.values()) {
        for (AField field : aclass.fields.values()) {
            removeIgnoredAnnosFromATypeElement(field.type, TypeUseLocation.FIELD);
        }
        for (AMethod method : aclass.methods.values()) {
            // Return type
            removeIgnoredAnnosFromATypeElement(method.returnType, TypeUseLocation.RETURN);
            // Receiver type
            removeIgnoredAnnosFromATypeElement(method.receiver.type, TypeUseLocation.RECEIVER);
            // Parameter type
            for (AField param : method.parameters.values()) {
                removeIgnoredAnnosFromATypeElement(param.type, TypeUseLocation.PARAMETER);
            }
        }
    }
}
Also used : AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod) AField(scenelib.annotations.el.AField)

Example 13 with AMethod

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

the class WholeProgramInferenceScenesStorage method getMethodAnnos.

/**
 * Get the annotations for a method or constructor.
 *
 * @param methodElt the method or constructor
 * @return the annotations for a method or constructor
 */
private AMethod getMethodAnnos(ExecutableElement methodElt) {
    String className = ElementUtils.getEnclosingClassName(methodElt);
    String file = getFileForElement(methodElt);
    AClass classAnnos = getClassAnnos(className, file, ((MethodSymbol) methodElt).enclClass());
    AMethod methodAnnos = classAnnos.methods.getVivify(JVMNames.getJVMMethodSignature(methodElt));
    methodAnnos.setFieldsFromMethodElement(methodElt);
    return methodAnnos;
}
Also used : AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod)

Example 14 with AMethod

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

the class WholeProgramInferenceScenesStorage method addMethodDeclarationAnnotation.

@Override
public boolean addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno) {
    // Do not infer types for library code, only for type-checked source code.
    if (!ElementUtils.isElementFromSourceCode(methodElt)) {
        return false;
    }
    AMethod methodAnnos = getMethodAnnos(methodElt);
    scenelib.annotations.Annotation sceneAnno = AnnotationConverter.annotationMirrorToAnnotation(anno);
    boolean isNewAnnotation = methodAnnos.tlAnnotationsHere.add(sceneAnno);
    return isNewAnnotation;
}
Also used : Annotation(scenelib.annotations.Annotation) AMethod(scenelib.annotations.el.AMethod)

Example 15 with AMethod

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

the class WholeProgramInferenceScenesStorage method getPreconditionsForExpression.

/**
 * Returns the precondition annotations for a Java expression.
 *
 * @param methodElement the method
 * @param expression the expression
 * @param declaredType the declared type of the expression
 * @return the precondition annotations for a Java expression
 */
private ATypeElement getPreconditionsForExpression(ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType) {
    AMethod methodAnnos = getMethodAnnos(methodElement);
    preconditionsToDeclaredTypes.put(methodAnnos.methodSignature + expression, declaredType);
    return methodAnnos.vivifyAndAddTypeMirrorToPrecondition(expression, declaredType.getUnderlyingType()).type;
}
Also used : AMethod(scenelib.annotations.el.AMethod)

Aggregations

AMethod (scenelib.annotations.el.AMethod)19 AClass (scenelib.annotations.el.AClass)13 AField (scenelib.annotations.el.AField)9 Annotation (scenelib.annotations.Annotation)6 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)5 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)4 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)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 Map (java.util.Map)2 VariableElement (javax.lang.model.element.VariableElement)2