Search in sources :

Example 31 with AnnotatedExecutableType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.

the class LockVisitor method reportFailure.

private void reportFailure(@CompilerMessageKey String messageKey, MethodTree overriderTree, AnnotatedDeclaredType enclosingType, AnnotatedExecutableType overridden, AnnotatedDeclaredType overriddenType, List<String> overriderLocks, List<String> overriddenLocks) {
    // Get the type of the overriding method.
    AnnotatedExecutableType overrider = atypeFactory.getAnnotatedType(overriderTree);
    if (overrider.getTypeVariables().isEmpty() && !overridden.getTypeVariables().isEmpty()) {
        overridden = overridden.getErased();
    }
    String overriderMeth = overrider.toString();
    String overriderTyp = enclosingType.getUnderlyingType().asElement().toString();
    String overriddenMeth = overridden.toString();
    String overriddenTyp = overriddenType.getUnderlyingType().asElement().toString();
    if (overriderLocks == null || overriddenLocks == null) {
        checker.report(Result.failure(messageKey, overriderMeth, overriderTyp, overriddenMeth, overriddenTyp), overriderTree);
    } else {
        checker.report(Result.failure(messageKey, overriderMeth, overriderTyp, overriddenMeth, overriddenTyp, overriderLocks, overriddenLocks), overriderTree);
    }
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)

Example 32 with AnnotatedExecutableType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.

the class NullnessAnnotatedTypeFactory method methodFromUse.

@Override
public Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> methodFromUse(MethodInvocationTree tree) {
    Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> mfuPair = super.methodFromUse(tree);
    AnnotatedExecutableType method = mfuPair.first;
    systemGetPropertyHandler.handle(tree, method);
    collectionToArrayHeuristics.handle(tree, method);
    return mfuPair;
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 33 with AnnotatedExecutableType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.

the class NullnessTransfer method visitMethodInvocation.

/*
     * Provided that m is of a type that implements interface java.util.Map:
     * <ul>
     * <li>Given a call m.get(k), if k is @KeyFor("m"), ensures that the result is @NonNull in the thenStore and elseStore of the transfer result.
     * </ul>
     */
@Override
public TransferResult<NullnessValue, NullnessStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<NullnessValue, NullnessStore> in) {
    TransferResult<NullnessValue, NullnessStore> result = super.visitMethodInvocation(n, in);
    // Make receiver non-null.
    makeNonNull(result, n.getTarget().getReceiver());
    // For all formal parameters with a non-null annotation, make the actual
    // argument non-null.
    MethodInvocationTree tree = n.getTree();
    ExecutableElement method = TreeUtils.elementFromUse(tree);
    AnnotatedExecutableType methodType = analysis.getTypeFactory().getAnnotatedType(method);
    List<AnnotatedTypeMirror> methodParams = methodType.getParameterTypes();
    List<? extends ExpressionTree> methodArgs = tree.getArguments();
    for (int i = 0; i < methodParams.size() && i < methodArgs.size(); ++i) {
        if (methodParams.get(i).hasAnnotation(NONNULL)) {
            makeNonNull(result, n.getArgument(i));
        }
    }
    // the map.
    if (keyForTypeFactory != null && keyForTypeFactory.isInvocationOfMapMethod(n, "get")) {
        Node receiver = n.getTarget().getReceiver();
        String mapName = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiver).toString();
        if (keyForTypeFactory.isKeyForMap(mapName, methodArgs.get(0))) {
            makeNonNull(result, n);
            NullnessValue oldResultValue = result.getResultValue();
            NullnessValue refinedResultValue = analysis.createSingleAnnotationValue(NONNULL, oldResultValue.getUnderlyingType());
            NullnessValue newResultValue = refinedResultValue.mostSpecific(oldResultValue, null);
            result.setResultValue(newResultValue);
        }
    }
    return result;
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ExecutableElement(javax.lang.model.element.ExecutableElement) InstanceOfNode(org.checkerframework.dataflow.cfg.node.InstanceOfNode) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) NullLiteralNode(org.checkerframework.dataflow.cfg.node.NullLiteralNode) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ArrayAccessNode(org.checkerframework.dataflow.cfg.node.ArrayAccessNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ThrowNode(org.checkerframework.dataflow.cfg.node.ThrowNode) Node(org.checkerframework.dataflow.cfg.node.Node) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 34 with AnnotatedExecutableType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.

the class GuiEffectVisitor method visitMethodInvocation.

// Check that the invoked effect is <= permitted effect (effStack.peek())
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    if (debugSpew) {
        System.err.println("For invocation " + node + " in " + currentMethods.peek().getName());
    }
    // Target method annotations
    ExecutableElement methodElt = TreeUtils.elementFromUse(node);
    if (debugSpew) {
        System.err.println("methodElt found");
    }
    Tree callerTree = TreeUtils.enclosingMethodOrLambda(getCurrentPath());
    if (callerTree == null) {
        // Static initializer; let's assume this is safe to have the UI effect
        if (debugSpew) {
            System.err.println("No enclosing method: likely static initializer");
        }
        return super.visitMethodInvocation(node, p);
    }
    if (debugSpew) {
        System.err.println("callerTree found: " + callerTree.getKind());
    }
    Effect targetEffect = atypeFactory.getComputedEffectAtCallsite(node, visitorState.getMethodReceiver(), methodElt);
    Effect callerEffect = null;
    if (callerTree.getKind() == Tree.Kind.METHOD) {
        ExecutableElement callerElt = TreeUtils.elementFromDeclaration((MethodTree) callerTree);
        if (debugSpew) {
            System.err.println("callerElt found");
        }
        callerEffect = atypeFactory.getDeclaredEffect(callerElt);
        // the traversal goes straight from the class to the initializer.
        assert (currentMethods.peek() == null || callerEffect.equals(effStack.peek()));
    } else if (callerTree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
        callerEffect = atypeFactory.getInferedEffectForLambdaExpression((LambdaExpressionTree) callerTree);
        // Perform lambda polymorphic effect inference: @PolyUI lambda, calling @UIEffect => @UI lambda
        if (targetEffect.isUI() && callerEffect.isPoly()) {
            atypeFactory.constrainLambdaToUI((LambdaExpressionTree) callerTree);
            callerEffect = new Effect(UIEffect.class);
        }
    }
    assert callerEffect != null;
    if (!Effect.LE(targetEffect, callerEffect)) {
        checker.report(Result.failure("call.invalid.ui", targetEffect, callerEffect), node);
        if (debugSpew) {
            System.err.println("Issuing error for node: " + node);
        }
    }
    if (debugSpew) {
        System.err.println("Successfully finished main non-recursive checkinv of invocation " + node);
    }
    Void result = super.visitMethodInvocation(node, p);
    // Check arguments to this method invocation for UI-lambdas, this must be re-checked after visiting the lambda
    // body due to inference.
    List<? extends ExpressionTree> args = node.getArguments();
    Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> mfuPair = atypeFactory.methodFromUse(node);
    AnnotatedExecutableType invokedMethod = mfuPair.first;
    List<AnnotatedTypeMirror> argsTypes = AnnotatedTypes.expandVarArgs(atypeFactory, invokedMethod, node.getArguments());
    for (int i = 0; i < args.size(); ++i) {
        if (args.get(i).getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
            lambdaAssignmentCheck(argsTypes.get(i), (LambdaExpressionTree) args.get(i), "argument.type.incompatible");
        }
    }
    return result;
}
Also used : LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) ExecutableElement(javax.lang.model.element.ExecutableElement) ReturnTree(com.sun.source.tree.ReturnTree) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) SafeEffect(org.checkerframework.checker.guieffect.qual.SafeEffect) PolyUIEffect(org.checkerframework.checker.guieffect.qual.PolyUIEffect) UIEffect(org.checkerframework.checker.guieffect.qual.UIEffect) List(java.util.List) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 35 with AnnotatedExecutableType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.

the class I18nFormatterTreeUtil method createFormatForCall.

/**
 * Returns an I18nFormatCall instance, only if FormatFor is called. Otherwise, returns null.
 */
public I18nFormatCall createFormatForCall(MethodInvocationTree tree, MethodInvocationNode node, I18nFormatterAnnotatedTypeFactory atypeFactory) {
    ExecutableElement method = TreeUtils.elementFromUse(tree);
    AnnotatedExecutableType methodAnno = atypeFactory.getAnnotatedType(method);
    for (AnnotatedTypeMirror paramType : methodAnno.getParameterTypes()) {
        // find @FormatFor
        if (paramType.getAnnotation(I18nFormatFor.class) != null) {
            return atypeFactory.treeUtil.new I18nFormatCall(tree, node, atypeFactory);
        }
    }
    return null;
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) ExecutableElement(javax.lang.model.element.ExecutableElement) I18nFormatFor(org.checkerframework.checker.i18nformatter.qual.I18nFormatFor) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)42 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)19 ExecutableElement (javax.lang.model.element.ExecutableElement)17 ArrayList (java.util.ArrayList)15 AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)15 ExpressionTree (com.sun.source.tree.ExpressionTree)13 MethodTree (com.sun.source.tree.MethodTree)13 List (java.util.List)13 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)12 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)12 Tree (com.sun.source.tree.Tree)12 VariableTree (com.sun.source.tree.VariableTree)12 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)9 AssignmentTree (com.sun.source.tree.AssignmentTree)7 ClassTree (com.sun.source.tree.ClassTree)7 NewArrayTree (com.sun.source.tree.NewArrayTree)7 ReturnTree (com.sun.source.tree.ReturnTree)7 NewClassTree (com.sun.source.tree.NewClassTree)6 VariableElement (javax.lang.model.element.VariableElement)6 AnnotationTree (com.sun.source.tree.AnnotationTree)5