use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.
the class LiveVarTransfer method visitMethodInvocation.
@Override
public RegularTransferResult<LiveVarValue, LiveVarStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<LiveVarValue, LiveVarStore> p) {
RegularTransferResult<LiveVarValue, LiveVarStore> transferResult = (RegularTransferResult<LiveVarValue, LiveVarStore>) super.visitMethodInvocation(n, p);
LiveVarStore store = transferResult.getRegularStore();
for (Node arg : n.getArguments()) {
store.addUseInExpression(arg);
}
return transferResult;
}
use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.
the class ValueTransfer method addAnnotationToStore.
private void addAnnotationToStore(CFStore store, AnnotationMirror anno, Node node) {
// If node is assignment, iterate over lhs and rhs; otherwise, iterator contains just node.
for (Node internal : splitAssignments(node)) {
JavaExpression je = JavaExpression.fromNode(internal);
CFValue currentValueFromStore;
if (CFAbstractStore.canInsertJavaExpression(je)) {
currentValueFromStore = store.getValue(je);
} else {
// Don't just `continue;` which would skip the calls to refine{Array,String}...
currentValueFromStore = null;
}
AnnotationMirror currentAnno = (currentValueFromStore == null ? atypeFactory.UNKNOWNVAL : getValueAnnotation(currentValueFromStore));
// Combine the new annotations based on the results of the comparison with the existing type.
AnnotationMirror newAnno = hierarchy.greatestLowerBound(anno, currentAnno);
store.insertValue(je, newAnno);
if (node instanceof FieldAccessNode) {
refineArrayAtLengthAccess((FieldAccessNode) internal, store);
} else if (node instanceof MethodInvocationNode) {
MethodInvocationNode miNode = (MethodInvocationNode) node;
refineAtLengthInvocation(miNode, store);
}
}
}
use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.
the class AliasingTransfer method processPostconditions.
/**
* Handling pseudo-assignments. Called by {@code CFAbstractTransfer.visitMethodInvocation()}.
*
* <p>Case 2: Given a method call, traverses all formal parameters of the method declaration, and
* if it doesn't have the {@literal @}NonLeaked or {@literal @}LeakedToResult annotations, we
* remove the node of the respective argument in the method call from the store. If parameter has
* {@literal @}LeakedToResult, {@code visitMethodInvocation()} handles it.
*/
@Override
protected void processPostconditions(MethodInvocationNode n, CFStore store, ExecutableElement methodElement, Tree tree) {
super.processPostconditions(n, store, methodElement, tree);
if (TreeUtils.isEnumSuper(n.getTree())) {
// Skipping the init() method for enums.
return;
}
List<Node> args = n.getArguments();
List<? extends VariableElement> params = methodElement.getParameters();
assert (args.size() == params.size()) : "Number of arguments in " + "the method call " + n + " is different from the" + " number of parameters for the method declaration: " + methodElement.getSimpleName();
AnnotatedExecutableType annotatedType = factory.getAnnotatedType(methodElement);
List<AnnotatedTypeMirror> paramTypes = annotatedType.getParameterTypes();
for (int i = 0; i < args.size(); i++) {
Node arg = args.get(i);
AnnotatedTypeMirror paramType = paramTypes.get(i);
if (!paramType.hasAnnotation(NonLeaked.class) && !paramType.hasAnnotation(LeakedToResult.class)) {
store.clearValue(JavaExpression.fromNode(arg));
}
}
// Now, doing the same as above for the receiver parameter
Node receiver = n.getTarget().getReceiver();
AnnotatedDeclaredType receiverType = annotatedType.getReceiverType();
if (receiverType != null && !receiverType.hasAnnotation(LeakedToResult.class) && !receiverType.hasAnnotation(NonLeaked.class)) {
store.clearValue(JavaExpression.fromNode(receiver));
}
}
use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.
the class I18nFormatterTreeUtil method asFormatCallCategoriesLowLevel.
private I18nConversionCategory[] asFormatCallCategoriesLowLevel(MethodInvocationNode node) {
Node vararg = node.getArgument(1);
if (vararg instanceof ArrayCreationNode) {
List<Node> convs = ((ArrayCreationNode) vararg).getInitializers();
I18nConversionCategory[] res = new I18nConversionCategory[convs.size()];
for (int i = 0; i < convs.size(); i++) {
Node conv = convs.get(i);
if (conv instanceof FieldAccessNode) {
if (typeMirrorToClass(((FieldAccessNode) conv).getType()) == I18nConversionCategory.class) {
res[i] = I18nConversionCategory.valueOf(((FieldAccessNode) conv).getFieldName());
continue;
/* avoid returning null */
}
}
return null;
}
return res;
}
return null;
}
use of org.checkerframework.dataflow.cfg.node.MethodInvocationNode in project checker-framework by typetools.
the class IndexMethodIdentifier method isLengthOfMethodInvocation.
/**
* Returns true if {@code node} is an invocation of a method that returns the length of {@code
* this}
*
* @param node a node
* @return true if {@code node} is an invocation of a method that returns the length of {@code
* this}
*/
public boolean isLengthOfMethodInvocation(Node node) {
if (node instanceof MethodInvocationNode) {
MethodInvocationNode methodInvocationNode = (MethodInvocationNode) node;
MethodAccessNode methodAccessNode = methodInvocationNode.getTarget();
ExecutableElement ele = methodAccessNode.getMethod();
return isLengthOfMethodInvocation(ele);
}
return false;
}
Aggregations