use of org.checkerframework.framework.flow.CFValue 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.framework.flow.CFValue in project checker-framework by typetools.
the class RegexTransfer method handleRegexUtil.
private TransferResult<CFValue, CFStore> handleRegexUtil(MethodInvocationNode n, ExecutableElement method, TransferResult<CFValue, CFStore> result) {
RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
if (ElementUtils.matchesElement(method, IS_REGEX_METHOD_NAME, String.class, int.class)) {
// RegexUtil.isRegex(s, groups) method
// (No special case is needed for isRegex(String) because of
// the annotation on that method's definition.)
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Receiver firstParam = FlowExpressions.internalReprOf(factory.getContext().getAnnotationProvider(), n.getArgument(0));
// add annotation with correct group count (if possible,
// regex annotation without count otherwise)
Node count = n.getArgument(1);
int groupCount;
if (count instanceof IntegerLiteralNode) {
IntegerLiteralNode iln = (IntegerLiteralNode) count;
groupCount = iln.getValue();
} else {
groupCount = 0;
}
AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
thenStore.insertValue(firstParam, regexAnnotation);
return newResult;
} else if (ElementUtils.matchesElement(method, AS_REGEX_METHOD_NAME, String.class, int.class)) {
// RegexUtil.asRegex(s, groups) method
// (No special case is needed for asRegex(String) because of
// the annotation on that method's definition.)
// add annotation with correct group count (if possible,
// regex annotation without count otherwise)
AnnotationMirror regexAnnotation;
Node count = n.getArgument(1);
int groupCount;
if (count instanceof IntegerLiteralNode) {
IntegerLiteralNode iln = (IntegerLiteralNode) count;
groupCount = iln.getValue();
} else {
groupCount = 0;
}
regexAnnotation = factory.createRegexAnnotation(groupCount);
CFValue newResultValue = analysis.createSingleAnnotationValue(regexAnnotation, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
return result;
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class I18nFormatterTransfer method visitMethodInvocation.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
I18nFormatterAnnotatedTypeFactory atypeFactory = (I18nFormatterAnnotatedTypeFactory) analysis.getTypeFactory();
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
I18nFormatterTreeUtil tu = atypeFactory.treeUtil;
// If hasFormat is called, make sure that the format string is annotated correctly
if (tu.isHasFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Result<I18nConversionCategory[]> cats = tu.getHasFormatCallCategories(node);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.indirect.arguments");
} else {
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
thenStore.insertValue(firstParam, anno);
}
return newResult;
}
// If isFormat is called, annotate the format string with I18nInvalidFormat
if (tu.isIsFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationBuilder builder = new AnnotationBuilder(tu.processingEnv, I18nInvalidFormat.class.getCanonicalName());
// No need to set a value of @I18nInvalidFormat
builder.setValue("value", "");
elseStore.insertValue(firstParam, builder.build());
return newResult;
}
// corresponding key's value
if (tu.isMakeFormatCall(node, atypeFactory)) {
Result<I18nConversionCategory[]> cats = tu.makeFormatCallCategories(node, atypeFactory);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.key.not.found");
} else {
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
CFValue newResultValue = analysis.createSingleAnnotationValue(anno, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
}
return result;
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LowerBoundTransfer method visitUnsignedRightShift.
@Override
public TransferResult<CFValue, CFStore> visitUnsignedRightShift(UnsignedRightShiftNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitUnsignedRightShift(n, p);
AnnotationMirror resultAnno = getAnnotationForRightShift(n, p);
return createNewResult(transferResult, resultAnno);
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LowerBoundTransfer method visitNumericalMultiplication.
@Override
public TransferResult<CFValue, CFStore> visitNumericalMultiplication(NumericalMultiplicationNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> result = super.visitNumericalMultiplication(n, p);
AnnotationMirror newAnno = getAnnotationForMultiply(n, p);
return createNewResult(result, newAnno);
}
Aggregations