use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(MethodDeclaration decl, AElement elem) {
Type type = decl.getType();
List<Parameter> params = decl.getParameters();
List<TypeParameter> typeParams = decl.getTypeParameters();
Optional<ReceiverParameter> rcvrParam = decl.getReceiverParameter();
BlockStmt body = decl.getBody().orElse(null);
StringBuilder sb = new StringBuilder(decl.getNameAsString()).append('(');
AClass clazz = (AClass) elem;
AMethod method;
if (params != null) {
for (Parameter param : params) {
Type ptype = param.getType();
sb.append(getJVML(ptype));
}
}
sb.append(')').append(getJVML(type));
method = clazz.methods.vivify(sb.toString());
visitDecl(decl, method);
visitType(type, method.returnType);
if (params != null) {
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
AField field = method.parameters.vivify(i);
visitType(param.getType(), field.type);
}
}
if (rcvrParam.isPresent()) {
for (AnnotationExpr expr : rcvrParam.get().getAnnotations()) {
Annotation anno = extractAnnotation(expr);
method.receiver.type.tlAnnotationsHere.add(anno);
}
}
if (typeParams != null) {
for (int i = 0; i < typeParams.size(); i++) {
TypeParameter typeParam = typeParams.get(i);
List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
if (bounds != null) {
for (int j = 0; j < bounds.size(); j++) {
ClassOrInterfaceType bound = bounds.get(j);
BoundLocation loc = new BoundLocation(i, j);
bound.accept(this, method.bounds.vivify(loc));
}
}
}
}
return body == null ? null : body.accept(this, method);
}
use of scenelib.annotations.el.AMethod in project checker-framework by typetools.
the class WholeProgramInferenceScenes method updateInferredMethodParameterTypes.
/**
* Updates the parameter types of the method {@code methodElt} in the Scene of the method's
* enclosing class based on the overridden method {@code overriddenMethod} parameter types.
*
* <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 parameter on the overridden method 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 parameter
* on the overridden method.
* </ul>
*
* <p>
*
* @param methodTree the tree of the method that contains the parameter
* @param methodElt the element of the method
* @param overriddenMethod the AnnotatedExecutableType of the overridden method
* @param atf the annotated type factory of a given type system, whose type hierarchy will be
* used to update the parameter type
*/
@Override
public void updateInferredMethodParameterTypes(MethodTree methodTree, ExecutableElement methodElt, AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf) {
ClassSymbol classSymbol = getEnclosingClassSymbol(methodTree);
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);
for (int i = 0; i < overriddenMethod.getParameterTypes().size(); i++) {
VariableElement ve = methodElt.getParameters().get(i);
AnnotatedTypeMirror paramATM = atf.getAnnotatedType(ve);
AnnotatedTypeMirror argATM = overriddenMethod.getParameterTypes().get(i);
AField param = method.parameters.vivify(i);
helper.updateAnnotationSetInScene(param.type, atf, jaifPath, argATM, paramATM, TypeUseLocation.PARAMETER);
}
}
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 ToIndexFileConverter method visit.
@Override
public Void visit(ConstructorDeclaration decl, AElement elem) {
List<Parameter> params = decl.getParameters();
List<AnnotationExpr> rcvrAnnos = decl.getAnnotations();
BlockStmt body = decl.getBody();
StringBuilder sb = new StringBuilder("<init>(");
AClass clazz = (AClass) elem;
AMethod method;
// an empty list.
if (params != null) {
for (Parameter param : params) {
Type ptype = param.getType();
sb.append(getJVML(ptype));
}
}
sb.append(")V");
method = clazz.methods.vivify(sb.toString());
visitDecl(decl, method);
if (params != null) {
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
AField field = method.parameters.vivify(i);
visitType(param.getType(), field.type);
}
}
if (rcvrAnnos != null) {
for (AnnotationExpr expr : rcvrAnnos) {
Annotation anno = extractAnnotation(expr);
method.receiver.tlAnnotationsHere.add(anno);
}
}
return body == null ? null : body.accept(this, method);
// return super.visit(decl, elem);
}
Aggregations