Search in sources :

Example 11 with MustCallAnnotatedTypeFactory

use of org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory in project checker-framework by typetools.

the class ResourceLeakTransfer method visitMethodInvocation.

@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(final MethodInvocationNode node, final TransferInput<CFValue, CFStore> input) {
    TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, input);
    handleCreatesMustCallFor(node, result);
    updateStoreWithTempVar(result, node);
    // If there is a temporary variable for the receiver, update its type.
    Node receiver = node.getTarget().getReceiver();
    MustCallAnnotatedTypeFactory mcAtf = rlTypeFactory.getTypeFactoryOfSubchecker(MustCallChecker.class);
    Node accumulationTarget = mcAtf.getTempVar(receiver);
    if (accumulationTarget != null) {
        String methodName = node.getTarget().getMethod().getSimpleName().toString();
        methodName = rlTypeFactory.adjustMethodNameUsingValueChecker(methodName, node.getTree());
        accumulate(accumulationTarget, result, methodName);
    }
    return result;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFStore(org.checkerframework.framework.flow.CFStore) TernaryExpressionNode(org.checkerframework.dataflow.cfg.node.TernaryExpressionNode) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) SwitchExpressionNode(org.checkerframework.dataflow.cfg.node.SwitchExpressionNode) Node(org.checkerframework.dataflow.cfg.node.Node) MustCallAnnotatedTypeFactory(org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory)

Example 12 with MustCallAnnotatedTypeFactory

use of org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory in project checker-framework by typetools.

the class ResourceLeakVisitor method isMustCallMethod.

/**
 * Returns true iff the {@code MustCall} annotation of the class that encloses the methodTree
 * names this method.
 *
 * @param methodTree the declaration of a method
 * @return whether that method is one of the must-call methods for its enclosing class
 */
private boolean isMustCallMethod(MethodTree methodTree) {
    ExecutableElement elt = TreeUtils.elementFromDeclaration(methodTree);
    TypeElement containingClass = ElementUtils.enclosingTypeElement(elt);
    MustCallAnnotatedTypeFactory mustCallAnnotatedTypeFactory = rlTypeFactory.getTypeFactoryOfSubchecker(MustCallChecker.class);
    AnnotationMirror mcAnno = mustCallAnnotatedTypeFactory.getAnnotatedType(containingClass).getAnnotationInHierarchy(mustCallAnnotatedTypeFactory.TOP);
    List<String> mcValues = AnnotationUtils.getElementValueArray(mcAnno, mustCallAnnotatedTypeFactory.getMustCallValueElement(), String.class);
    String methodName = elt.getSimpleName().toString();
    return mcValues.contains(methodName);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) MustCallAnnotatedTypeFactory(org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory)

Aggregations

MustCallAnnotatedTypeFactory (org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory)12 AnnotationMirror (javax.lang.model.element.AnnotationMirror)6 LocalVariableNode (org.checkerframework.dataflow.cfg.node.LocalVariableNode)6 ExecutableElement (javax.lang.model.element.ExecutableElement)5 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)4 Node (org.checkerframework.dataflow.cfg.node.Node)4 ObjectCreationNode (org.checkerframework.dataflow.cfg.node.ObjectCreationNode)4 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)4 MethodTree (com.sun.source.tree.MethodTree)3 TypeElement (javax.lang.model.element.TypeElement)3 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)3 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)3 NullLiteralNode (org.checkerframework.dataflow.cfg.node.NullLiteralNode)3 ReturnNode (org.checkerframework.dataflow.cfg.node.ReturnNode)3 ThisNode (org.checkerframework.dataflow.cfg.node.ThisNode)3 TypeCastNode (org.checkerframework.dataflow.cfg.node.TypeCastNode)3 CFStore (org.checkerframework.framework.flow.CFStore)3 Element (javax.lang.model.element.Element)2 VariableElement (javax.lang.model.element.VariableElement)2 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)2