use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.
the class TypeArgInferenceUtil method assignedToExecutable.
private static AnnotatedTypeMirror assignedToExecutable(AnnotatedTypeFactory atypeFactory, TreePath path, ExecutableElement methodElt, AnnotatedTypeMirror receiver, List<? extends ExpressionTree> arguments) {
AnnotatedExecutableType method = AnnotatedTypes.asMemberOf(atypeFactory.getContext().getTypeUtils(), atypeFactory, receiver, methodElt);
int treeIndex = -1;
for (int i = 0; i < arguments.size(); ++i) {
ExpressionTree argumentTree = arguments.get(i);
if (isArgument(path, argumentTree)) {
treeIndex = i;
break;
}
}
final AnnotatedTypeMirror paramType;
if (treeIndex == -1) {
// The tree wasn't found as an argument, so it has to be the receiver.
// This can happen for inner class constructors that take an outer class argument.
paramType = method.getReceiverType();
} else if (treeIndex >= method.getParameterTypes().size() && methodElt.isVarArgs()) {
paramType = method.getParameterTypes().get(method.getParameterTypes().size() - 1);
} else {
paramType = method.getParameterTypes().get(treeIndex);
}
// would require solving the constraints for both type argument inferences simultaneously
if (paramType == null || containsUninferredTypeParameter(paramType, method)) {
return null;
}
return paramType;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType in project checker-framework by typetools.
the class DefaultReflectionResolver method resolveConstructorCall.
/**
* Resolves a call to {@link Constructor#newInstance(Object...)}.
*
* @param factory the {@link AnnotatedTypeFactory} of the underlying type system
* @param tree the method invocation tree (representing a constructor call) that has to be
* resolved
* @param origResult the original result from {@code factory.methodFromUse}.
*/
private Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> resolveConstructorCall(AnnotatedTypeFactory factory, MethodInvocationTree tree, Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> origResult) {
debugReflection("Try to resolve reflective constructor call: " + tree);
List<JCNewClass> possibleConstructors = resolveReflectiveConstructor(tree, factory);
// Reflective constructor could not be resolved
if (possibleConstructors.size() == 0) {
return origResult;
}
Set<? extends AnnotationMirror> returnLub = null;
Set<? extends AnnotationMirror> paramsGlb = null;
// parameter types
for (JCNewClass resolvedTree : possibleConstructors) {
debugReflection("Resolved constructor invocation: " + resolvedTree);
if (!checkNewClassArguments(resolvedTree)) {
debugReflection("Spoofed tree's arguments did not match declaration" + resolvedTree.toString());
// in QualifierPolymorphism.PolyCollector.visitArray(...)
continue;
}
Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> resolvedResult = factory.constructorFromUse(resolvedTree);
// Lub return types
returnLub = lub(returnLub, resolvedResult.first.getReturnType().getAnnotations(), factory);
// Glb parameter types
for (AnnotatedTypeMirror mirror : resolvedResult.first.getParameterTypes()) {
paramsGlb = glb(paramsGlb, mirror.getAnnotations(), factory);
}
}
if (returnLub == null) {
// None of the spoofed tree's arguments matched the declared method
return origResult;
}
/*
* Clear all original (return, parameter type) annotations and set
* lub/glb annotations from resolved constructors.
*/
// return value
origResult.first.getReturnType().clearAnnotations();
origResult.first.getReturnType().addAnnotations(returnLub);
// parameter types
if (paramsGlb != null) {
AnnotatedArrayType origArrayType = (AnnotatedArrayType) origResult.first.getParameterTypes().get(0);
origArrayType.getComponentType().clearAnnotations();
origArrayType.getComponentType().addAnnotations(paramsGlb);
}
debugReflection("Resolved annotations: " + origResult.first);
return origResult;
}
Aggregations