use of org.sonar.java.resolve.SemanticModel in project sonar-java by SonarSource.
the class VisitorsBridgeForTests method createScannerContext.
@Override
protected JavaFileScannerContext createScannerContext(CompilationUnitTree tree, SemanticModel semanticModel, SonarComponents sonarComponents, boolean failedParsing) {
SemanticModel model = enableSemantic ? semanticModel : null;
testContext = new TestJavaFileScannerContext(tree, currentFile, model, sonarComponents, javaVersion, failedParsing);
return testContext;
}
use of org.sonar.java.resolve.SemanticModel in project sonar-java by SonarSource.
the class VisitorsBridgeTest method log_only_50_elements.
@Test
public void log_only_50_elements() throws Exception {
DecimalFormat formatter = new DecimalFormat("00");
IntFunction<String> classNotFoundName = i -> "NotFound" + formatter.format(i);
VisitorsBridge visitorsBridge = new VisitorsBridge(Collections.singletonList((JavaFileScanner) context -> {
assertThat(context.getSemanticModel()).isNotNull();
((SemanticModel) context.getSemanticModel()).classesNotFound().addAll(IntStream.range(0, 60).mapToObj(classNotFoundName).collect(Collectors.toList()));
}), Lists.newArrayList(), null);
checkFile("Foo.java", "class Foo {}", visitorsBridge);
visitorsBridge.endOfAnalysis();
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Classes not found during the analysis : [" + IntStream.range(0, 50).mapToObj(classNotFoundName).sorted().collect(Collectors.joining(", ")) + ", ...]");
}
use of org.sonar.java.resolve.SemanticModel in project sonar-java by SonarSource.
the class BehaviorCacheTest method clear_stack_when_taking_exceptional_path_from_method_invocation.
@Test
public void clear_stack_when_taking_exceptional_path_from_method_invocation() throws Exception {
Pair<SymbolicExecutionVisitor, SemanticModel> sevAndSemantic = createSymbolicExecutionVisitorAndSemantic("src/test/files/se/CleanStackWhenRaisingException.java");
SymbolicExecutionVisitor sev = sevAndSemantic.a;
SemanticModel semanticModel = sevAndSemantic.b;
MethodBehavior behavior = getMethodBehavior(sev, "foo");
assertThat(behavior.yields()).hasSize(4);
behavior.happyPathYields().forEach(y -> assertThat(y.resultConstraint()).isNull());
assertThat(behavior.happyPathYields().count()).isEqualTo(1);
List<ExceptionalYield> exceptionalYields = behavior.exceptionalPathYields().collect(Collectors.toList());
assertThat(exceptionalYields).hasSize(3);
assertThat(exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).isUnknown())).hasSize(1);
}
use of org.sonar.java.resolve.SemanticModel in project sonar-java by SonarSource.
the class ExceptionUtilsTest method test_is_unchecked_exception.
@Test
public void test_is_unchecked_exception() {
assertThat(ExceptionUtils.isUncheckedException(null)).isFalse();
assertThat(ExceptionUtils.isUncheckedException(Symbols.unknownType)).isFalse();
SemanticModel semanticModel = SETestUtils.getSemanticModel("src/test/java/org/sonar/java/se/ExceptionUtilsTest.java");
Type ex = semanticModel.getClassType("java.lang.IllegalArgumentException");
assertThat(ExceptionUtils.isUncheckedException(ex)).isTrue();
ex = semanticModel.getClassType("java.lang.Exception");
assertThat(ExceptionUtils.isUncheckedException(ex)).isTrue();
ex = semanticModel.getClassType("java.lang.Throwable");
assertThat(ExceptionUtils.isUncheckedException(ex)).isTrue();
}
use of org.sonar.java.resolve.SemanticModel in project sonar-java by SonarSource.
the class NullableAnnotationUtilsTest method getSemanticModel.
private static SemanticModel getSemanticModel(String fileName, List<File> classPath) {
CompilationUnitTree cut = (CompilationUnitTree) JavaParser.createParser().parse(new File(fileName));
SemanticModel semanticModel = SemanticModel.createFor(cut, new SquidClassLoader(classPath));
return semanticModel;
}
Aggregations