use of org.checkerframework.dataflow.cfg.node.MethodAccessNode in project checker-framework by typetools.
the class RegexTransfer method visitMethodInvocation.
// TODO: These are special cases for isRegex(String, int) and asRegex(String, int).
// They should be replaced by adding an @EnsuresQualifierIf annotation that supports
// specifying attributes.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(n, in);
// refine result for some helper methods
MethodAccessNode target = n.getTarget();
ExecutableElement method = target.getMethod();
Node receiver = target.getReceiver();
if (receiver instanceof ClassNameNode) {
ClassNameNode cnn = (ClassNameNode) receiver;
String receiverName = cnn.getElement().toString();
if (isRegexUtil(receiverName)) {
result = handleRegexUtil(n, method, result);
}
}
return result;
}
use of org.checkerframework.dataflow.cfg.node.MethodAccessNode in project checker-framework by typetools.
the class IndexMethodIdentifier method isLengthOfMethodInvocation.
/**
* @return whether or not {@code tree} is an invocation of a method that returns the length of
* "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;
}
use of org.checkerframework.dataflow.cfg.node.MethodAccessNode in project checker-framework by typetools.
the class RegexTransfer method handleMatcherGroupCount.
/**
* See whether possibleMatcher is a call of groupCount on a Matcher and possibleConstant is a
* constant. If so, annotate the matcher as constant + 1 if !isAlsoEqual constant if isAlsoEqual
*
* @param possibleMatcher the Node that might be a call of Matcher.groupCount()
* @param possibleConstant the Node that might be a constant
* @param isAlsoEqual whether the comparison operation is strict or reflexive
* @param in the TransferInput
* @param resultIn TransferResult
* @return the possibly refined output TransferResult
*/
private TransferResult<CFValue, CFStore> handleMatcherGroupCount(Node possibleMatcher, Node possibleConstant, boolean isAlsoEqual, TransferInput<CFValue, CFStore> in, TransferResult<CFValue, CFStore> resultIn) {
if (!(possibleMatcher instanceof MethodInvocationNode)) {
return resultIn;
}
if (!(possibleConstant instanceof IntegerLiteralNode)) {
return resultIn;
}
MethodAccessNode methodAccessNode = ((MethodInvocationNode) possibleMatcher).getTarget();
ExecutableElement method = methodAccessNode.getMethod();
Node receiver = methodAccessNode.getReceiver();
if (!isMatcherGroupCountMethod(method, receiver)) {
return resultIn;
}
Receiver matcherReceiver = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiver);
IntegerLiteralNode iln = (IntegerLiteralNode) possibleConstant;
int groupCount;
if (isAlsoEqual) {
groupCount = iln.getValue();
} else {
groupCount = iln.getValue() + 1;
}
CFStore thenStore = resultIn.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(resultIn.getResultValue(), thenStore, elseStore);
RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
thenStore.insertValue(matcherReceiver, regexAnnotation);
return newResult;
}
Aggregations