use of org.checkerframework.framework.type.AnnotatedTypeFactory.ParameterizedExecutableType 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}
* @return the resolved type of the call
*/
private ParameterizedExecutableType resolveConstructorCall(AnnotatedTypeFactory factory, MethodInvocationTree tree, ParameterizedExecutableType origResult) {
debugReflection("Try to resolve reflective constructor call: " + tree);
List<JCNewClass> possibleConstructors = resolveReflectiveConstructor(tree, factory);
// Reflective constructor could not be resolved
if (possibleConstructors.isEmpty()) {
return origResult;
}
Set<? extends AnnotationMirror> returnLub = null;
Set<? extends AnnotationMirror> paramsGlb = null;
// Iterate over all possible constructors: lub return types and glb parameter types
for (JCNewClass resolvedTree : possibleConstructors) {
debugReflection("Resolved constructor invocation: " + resolvedTree);
if (!checkNewClassArguments(resolvedTree)) {
debugReflection("Spoofed tree's arguments did not match declaration" + resolvedTree);
// QualifierPolymorphism.PolyCollector.visitArray(...)
continue;
}
ParameterizedExecutableType resolvedResult = factory.constructorFromUse(resolvedTree);
// Lub return types
returnLub = lub(returnLub, resolvedResult.executableType.getReturnType().getAnnotations(), factory);
// Glb parameter types
for (AnnotatedTypeMirror mirror : resolvedResult.executableType.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.executableType.getReturnType().clearPrimaryAnnotations();
origResult.executableType.getReturnType().addAnnotations(returnLub);
// parameter types
if (paramsGlb != null) {
AnnotatedArrayType origArrayType = (AnnotatedArrayType) origResult.executableType.getParameterTypes().get(0);
origArrayType.getComponentType().clearPrimaryAnnotations();
origArrayType.getComponentType().addAnnotations(paramsGlb);
}
debugReflection("Resolved annotations: " + origResult.executableType);
return origResult;
}
Aggregations