use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method unknown_method.
@Test
public void unknown_method() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/util/Set;)V").addMethodParam(arg).addBasicBlock(newBasicBlock("0").ret(constant("implicit return"), new LocationInFile(FILE_KEY, 9, 2, 9, 3))).build();
String source = "import java.util.Set;\n" + "import java.util.Collection;\n" + "import java.util.stream.Collectors;\n" + "public class A {\n" + " void method(Set<String> arg) { \n" + " arg.stream()\n" + " .flatMap(Collection::stream)\n" + " .collect(Collectors.toCollection(LinkedHashSet::new)); \n" + " }\n" + "}";
// Semantic model creates 2 kinds of "unknown" symbols: "Symbols.unknownSymbol" and "JavaSymbolNotFound"
// We need to test first case
// To make sure that code contains "Symbols.unknownSymbol" this assertion is there
// Note that if Semantic model is improved somehow that "Symbols.unknownSymbol" is not anymore generated in this case
// this test might be removed
assertUnknownMethodCalled(source);
assertCodeToUCfg(source, expectedUCFG);
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method basic_block_location.
@Test
public void basic_block_location() {
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, 3, 5, 3, 16))).build();
UCFG ucfg = assertCodeToUCfg("class A {\n String method(String arg) {\n return arg;\n}}", expectedUCFG);
assertThat(ucfg.entryBlocks()).hasSize(1);
assertThat(ucfg.entryBlocks().iterator().next().locationInFile()).isEqualTo(new LocationInFile(FILE_KEY, 3, 12, 3, 15));
}
use of org.sonar.ucfg.LocationInFile in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method build_assignment_for_string.
@Test
public void build_assignment_for_string() {
Expression.Variable arg = UCFGBuilder.variableWithId("arg");
Expression.Variable arg2 = UCFGBuilder.variableWithId("arg2");
Expression.Variable var1 = UCFGBuilder.variableWithId("var1");
UCFG expectedUCFG = UCFGBuilder.createUCFGForMethod("A#method(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;").addMethodParam(arg).addBasicBlock(newBasicBlock("1").assignTo(var1, call("__id").withArgs(arg), new LocationInFile(FILE_KEY, 1, 49, 1, 67)).assignTo(var1, call("__id").withArgs(arg2), new LocationInFile(FILE_KEY, 1, 88, 1, 99)).ret(var1, new LocationInFile(FILE_KEY, 1, 114, 1, 126))).build();
assertCodeToUCfg("class A {String method(String arg, String arg2) {String var1 = arg; int var2; int var3; var1 = arg2; var2 = var3; return var1;}}", expectedUCFG);
}
Aggregations