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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations