Search in sources :

Example 1 with NotOwning

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

the class MustCallConsistencyAnalyzer method hasNotOwningReturnType.

/**
 * Does the method being invoked have a not-owning return type?
 *
 * @param node a method invocation
 * @return true iff the checker is not in no-lightweight-ownership mode and (1) the method has a
 *     void return type, or (2) a NotOwning annotation is present on the method declaration
 */
private boolean hasNotOwningReturnType(MethodInvocationNode node) {
    if (checker.hasOption(MustCallChecker.NO_LIGHTWEIGHT_OWNERSHIP)) {
        // Default to always transferring at return if not using LO, just like Eclipse does.
        return false;
    }
    MethodInvocationTree methodInvocationTree = node.getTree();
    ExecutableElement executableElement = TreeUtils.elementFromUse(methodInvocationTree);
    // void methods are "not owning" by construction
    return (ElementUtils.getType(executableElement).getKind() == TypeKind.VOID) || (typeFactory.getDeclAnnotation(executableElement, NotOwning.class) != null);
}
Also used : NotOwning(org.checkerframework.checker.mustcall.qual.NotOwning) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 2 with NotOwning

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

the class MustCallConsistencyAnalyzer method isTransferOwnershipAtReturn.

/**
 * Should ownership be transferred to the return type of the method corresponding to a CFG?
 * Returns true when there is no {@link NotOwning} annotation on the return type.
 *
 * @param cfg the CFG of the method
 * @return true iff ownership should be transferred to the return type of the method corresponding
 *     to a CFG
 */
private boolean isTransferOwnershipAtReturn(ControlFlowGraph cfg) {
    if (checker.hasOption(MustCallChecker.NO_LIGHTWEIGHT_OWNERSHIP)) {
        // If not using LO, default to always transfer at return, just like Eclipse does.
        return true;
    }
    UnderlyingAST underlyingAST = cfg.getUnderlyingAST();
    if (underlyingAST instanceof UnderlyingAST.CFGMethod) {
        // TODO: lambdas? In that case false is returned below, which means that ownership will
        // not be transferred.
        MethodTree method = ((UnderlyingAST.CFGMethod) underlyingAST).getMethod();
        ExecutableElement executableElement = TreeUtils.elementFromDeclaration(method);
        return typeFactory.getDeclAnnotation(executableElement, NotOwning.class) == null;
    }
    return false;
}
Also used : NotOwning(org.checkerframework.checker.mustcall.qual.NotOwning) MethodTree(com.sun.source.tree.MethodTree) ExecutableElement(javax.lang.model.element.ExecutableElement) UnderlyingAST(org.checkerframework.dataflow.cfg.UnderlyingAST)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)2 NotOwning (org.checkerframework.checker.mustcall.qual.NotOwning)2 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 MethodTree (com.sun.source.tree.MethodTree)1 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)1