use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaFilesCacheTest method resource_file_mapping.
@Test
public void resource_file_mapping() {
JavaFilesCache javaFilesCache = new JavaFilesCache();
JavaAstScanner.scanSingleFileForTests(new File("src/test/resources/JavaFilesCacheTestFile.java"), new VisitorsBridge(javaFilesCache));
assertThat(javaFilesCache.resourcesCache.keySet()).hasSize(8);
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$plop");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A$I");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A$1B");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A$1B$1");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A$2");
assertThat(javaFilesCache.resourcesCache.keySet()).contains("org/sonar/java/JavaFilesCacheTestFile$A$3");
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class MethodMatcherTest method detected.
@Test
public void detected() {
MethodMatcher objectToString = MethodMatcher.create().typeDefinition(TypeCriteria.subtypeOf("java.lang.Object")).name("toString").withoutParameter();
MethodMatcher objectToStringWithIntParam = MethodMatcher.create().name("toString").parameters("int");
MethodMatcher objectToStringWithStringParam = MethodMatcher.create().typeDefinition(TypeCriteria.anyType()).name(NameCriteria.is("toString")).parameters("java.lang.String");
MethodMatcher objectToStringWithAnyParam = MethodMatcher.create().typeDefinition(TypeCriteria.is("Test")).name("toString").withAnyParameters();
MethodMatcher integerToString = MethodMatcher.create().typeDefinition("java.lang.Integer").name("toString").withoutParameter();
MethodMatcher foo = MethodMatcher.create().typeDefinition(TypeCriteria.anyType()).name("foo").withoutParameter();
MethodMatcher callSiteIsTest = MethodMatcher.create().typeDefinition(TypeCriteria.anyType()).name(NameCriteria.any()).withAnyParameters().callSite(TypeCriteria.is("Test"));
Map<MethodMatcher, List<Integer>> matches = new HashMap<>();
matches.put(objectToString, new ArrayList<>());
matches.put(objectToStringWithIntParam, new ArrayList<>());
matches.put(objectToStringWithStringParam, new ArrayList<>());
matches.put(objectToStringWithAnyParam, new ArrayList<>());
matches.put(integerToString, new ArrayList<>());
matches.put(foo, new ArrayList<>());
matches.put(callSiteIsTest, new ArrayList<>());
JavaAstScanner.scanSingleFileForTests(new File("src/test/files/matcher/Test.java"), new VisitorsBridge(Collections.singletonList(new Visitor(matches)), new ArrayList<>(), null));
assertThat(matches.get(objectToString)).containsExactly(6, 19, 27);
assertThat(matches.get(objectToStringWithIntParam)).containsExactly(10);
assertThat(matches.get(objectToStringWithStringParam)).containsExactly(11, 14);
assertThat(matches.get(objectToStringWithAnyParam)).containsExactly(6, 10, 11, 14);
assertThat(matches.get(integerToString)).containsExactly(19);
assertThat(matches.get(foo)).containsExactly(35, 36);
assertThat(matches.get(callSiteIsTest)).containsExactly(6, 10, 11, 14, 18, 22);
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class AbstractMethodDetectionTest method withAnyParameters.
@Test
public void withAnyParameters() throws Exception {
Visitor visitor = new Visitor(ImmutableList.of(MethodMatcher.create().typeDefinition("A").name("method").withAnyParameters()));
JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/AbstractMethodDetection.java"), new VisitorsBridge(visitor));
assertThat(visitor.lines).containsExactly(14, 15, 16, 17);
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaSquid method createVisitorBridge.
private static VisitorsBridge createVisitorBridge(Iterable<JavaCheck> codeVisitors, List<File> classpath, JavaVersion javaVersion, @Nullable SonarComponents sonarComponents, SymbolicExecutionMode symbolicExecutionMode) {
VisitorsBridge visitorsBridge = new VisitorsBridge(codeVisitors, classpath, sonarComponents, symbolicExecutionMode);
visitorsBridge.setJavaVersion(javaVersion);
return visitorsBridge;
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class MethodJavaSymbolTest method test_unknowns.
@Test
public void test_unknowns() {
MethodVisitor methodVisitor = new MethodVisitor(Sets.newHashSet(16, 21), Sets.newHashSet(7, 15, 17, 31));
JavaAstScanner.scanSingleFileForTests(new File("src/test/files/resolve/MethodSymbols.java"), new VisitorsBridge(methodVisitor));
}
Aggregations