use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenes method updateInferredMethodParameterTypes.
/**
* Updates the parameter types of the method methodElt in the Scene of the receiverTree's
* enclosing class based on the arguments to the method.
*
* <p>For each method parameter in methodElt:
*
* <ul>
* <li>If the Scene does not contain an annotated type for that parameter, then the type of
* the respective value passed as argument in the method call methodInvNode will be added
* to the parameter in the Scene.
* <li>If the Scene previously contained an annotated type for that parameter, then its new
* type will be the LUB between the previous type and the type of the respective value
* passed as argument in the method call.
* </ul>
*
* <p>
*
* @param methodInvNode the node representing a method invocation
* @param receiverTree the Tree of the class that contains the method being invoked
* @param methodElt the element of the method being invoked
* @param atf the annotated type factory of a given type system, whose type hierarchy will be
* used to update the method parameters' types
*/
@Override
public void updateInferredMethodParameterTypes(MethodInvocationNode methodInvNode, Tree receiverTree, ExecutableElement methodElt, AnnotatedTypeFactory atf) {
if (receiverTree == null) {
// https://github.com/typetools/checker-framework/issues/682
return;
}
ClassSymbol classSymbol = getEnclosingClassSymbol(receiverTree);
if (classSymbol == null) {
// https://github.com/typetools/checker-framework/issues/682
return;
}
// https://github.com/typetools/checker-framework/issues/682
if (!classSymbol.getEnclosedElements().contains((Symbol) methodElt)) {
return;
}
String className = classSymbol.flatname.toString();
String jaifPath = helper.getJaifPath(className);
AClass clazz = helper.getAClass(className, jaifPath);
String methodName = JVMNames.getJVMMethodName(methodElt);
AMethod method = clazz.methods.vivify(methodName);
List<Node> arguments = methodInvNode.getArguments();
updateInferredExecutableParameterTypes(methodElt, atf, jaifPath, method, arguments);
}
use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method removeIgnoredAnnosFromScene.
/**
* Removes all annotations that should be ignored from an AScene. (See {@link #shouldIgnore}).
*/
private void removeIgnoredAnnosFromScene(AScene scene) {
for (AClass aclass : scene.classes.values()) {
for (AField field : aclass.fields.values()) {
removeIgnoredAnnosFromATypeElement(field.type, TypeUseLocation.FIELD);
}
for (AMethod method : aclass.methods.values()) {
// Return type
removeIgnoredAnnosFromATypeElement(method.returnType, TypeUseLocation.RETURN);
// Receiver type
removeIgnoredAnnosFromATypeElement(method.receiver.type, TypeUseLocation.RECEIVER);
// Parameter type
for (AField param : method.parameters.values()) {
removeIgnoredAnnosFromATypeElement(param.type, TypeUseLocation.PARAMETER);
}
}
}
}
use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenesStorage method getMethodAnnos.
/**
* Get the annotations for a method or constructor.
*
* @param methodElt the method or constructor
* @return the annotations for a method or constructor
*/
private AMethod getMethodAnnos(ExecutableElement methodElt) {
String className = ElementUtils.getEnclosingClassName(methodElt);
String file = getFileForElement(methodElt);
AClass classAnnos = getClassAnnos(className, file, ((MethodSymbol) methodElt).enclClass());
AMethod methodAnnos = classAnnos.methods.getVivify(JVMNames.getJVMMethodSignature(methodElt));
methodAnnos.setFieldsFromMethodElement(methodElt);
return methodAnnos;
}
use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenesStorage method addMethodDeclarationAnnotation.
@Override
public boolean addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno) {
// Do not infer types for library code, only for type-checked source code.
if (!ElementUtils.isElementFromSourceCode(methodElt)) {
return false;
}
AMethod methodAnnos = getMethodAnnos(methodElt);
scenelib.annotations.Annotation sceneAnno = AnnotationConverter.annotationMirrorToAnnotation(anno);
boolean isNewAnnotation = methodAnnos.tlAnnotationsHere.add(sceneAnno);
return isNewAnnotation;
}
use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenesStorage method getPreconditionsForExpression.
/**
* Returns the precondition annotations for a Java expression.
*
* @param methodElement the method
* @param expression the expression
* @param declaredType the declared type of the expression
* @return the precondition annotations for a Java expression
*/
private ATypeElement getPreconditionsForExpression(ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType) {
AMethod methodAnnos = getMethodAnnos(methodElement);
preconditionsToDeclaredTypes.put(methodAnnos.methodSignature + expression, declaredType);
return methodAnnos.vivifyAndAddTypeMirrorToPrecondition(expression, declaredType.getUnderlyingType()).type;
}
Aggregations