use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitor method buildParameterAnnotationsBlock.
private BlockBuilder buildParameterAnnotationsBlock(MethodTree methodTree, IdentifierGenerator idGenerator, CFG cfg) {
LocationInFile parametersLocation = location(methodTree.openParenToken(), methodTree.closeParenToken());
UCFGBuilder.BlockBuilder blockBuilder = UCFGBuilder.newBasicBlock("paramAnnotations", parametersLocation);
getAnnotatedStringParameters(methodTree).forEach(parameter -> buildBlockForParameter(parameter, blockBuilder, idGenerator));
Label nextBlockLabel = UCFGBuilder.createLabel(Integer.toString(cfg.entry().id()));
blockBuilder.jumpTo(nextBlockLabel);
return blockBuilder;
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method ignore_parameter_annotations_for_non_string.
@Test
public void ignore_parameter_annotations_for_non_string() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/lang/Integer;)Ljava/lang/String;").addMethodParam(arg).addBasicBlock(newBasicBlock("1").ret(constant("foo"), new LocationInFile(FILE_KEY, 1, 66, 1, 79))).build();
assertCodeToUCfg("class A { String method(@javax.annotation.Nullable Integer arg) { return \"foo\";}}", expectedUCFG);
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method filter_invocation_unrelated_to_string.
@Test
public void filter_invocation_unrelated_to_string() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/lang/String;)Ljava/lang/String;").addMethodParam(arg).addBasicBlock(newBasicBlock("1").ret(arg, new LocationInFile(FILE_KEY, 1, 61, 1, 72))).build();
assertCodeToUCfg("class A { String method(String arg) {Object o; o.hashCode(); return arg;}}", expectedUCFG);
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method constructor_with_return.
@Test
public void constructor_with_return() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#<init>(Ljava/lang/String;)V").addMethodParam(arg).addBasicBlock(newBasicBlock("1").ret(constant("\"\""), new LocationInFile(FILE_KEY, 3, 4, 3, 11))).build();
assertCodeToUCfg("class A { \n" + " A(String arg) { \n" + " return;\n" + " }\n" + "}", expectedUCFG);
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method build_concatenate_elements.
@Test
public void build_concatenate_elements() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
Expression.Variable var = UCFGBuilder.variableWithId("%0");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/lang/String;)Ljava/lang/String;").addMethodParam(arg).addBasicBlock(newBasicBlock("1").assignTo(var, call("__concat").withArgs(constant("Myconst"), arg), new LocationInFile(FILE_KEY, 1, 43, 1, 56)).ret(var, new LocationInFile(FILE_KEY, 1, 36, 1, 57))).build();
assertCodeToUCfg("class A {String method(String arg) {return \"Myconst\"+arg;}}", expectedUCFG);
expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/lang/String;)Ljava/lang/String;").addMethodParam(arg).addBasicBlock(newBasicBlock("1").assignTo(arg, call("__concat").withArgs(arg, constant("someConst")), new LocationInFile(FILE_KEY, 1, 43, 1, 59)).ret(arg, new LocationInFile(FILE_KEY, 1, 36, 1, 60))).build();
assertCodeToUCfg("class A {String method(String arg) {return arg+=\"someConst\";}}", expectedUCFG);
}
Aggregations