Search in sources :

Example 1 with BehaviorCache

use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.

the class BytecodeEGWalkerExecuteTest method initializeWalker.

@Before
public void initializeWalker() {
    BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
    behaviorCache.setFileContext(null, semanticModel);
    walker = new BytecodeEGWalker(behaviorCache, semanticModel);
}
Also used : BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) Before(org.junit.Before)

Example 2 with BehaviorCache

use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.

the class BytecodeEGWalkerExecuteTest method athrow_should_not_be_linked_to_next_label.

@Test
public void athrow_should_not_be_linked_to_next_label() throws Exception {
    CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse("class A {int field;}");
    SquidClassLoader classLoader = new SquidClassLoader(Collections.singletonList(new File("src/test/JsrRet")));
    SemanticModel semanticModel = SemanticModel.createFor(tree, classLoader);
    BehaviorCache behaviorCache = new BehaviorCache(classLoader);
    behaviorCache.setFileContext(null, semanticModel);
    BytecodeEGWalker walker = new BytecodeEGWalker(behaviorCache, semanticModel);
    MethodBehavior methodBehavior = walker.getMethodBehavior("org.apache.commons.io.FileUtils#readFileToString(Ljava/io/File;)Ljava/lang/String;", classLoader);
    assertThat(methodBehavior.happyPathYields().collect(Collectors.toList())).hasSize(1);
    assertThat(methodBehavior.exceptionalPathYields().collect(Collectors.toList())).hasSize(2);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SemanticModel(org.sonar.java.resolve.SemanticModel) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) File(java.io.File) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) Test(org.junit.Test)

Example 3 with BehaviorCache

use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.

the class BytecodeSECheckTest method getEGWalker.

private static BytecodeEGWalker getEGWalker() {
    BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
    behaviorCache.setFileContext(null, semanticModel);
    return new BytecodeEGWalker(behaviorCache, semanticModel);
}
Also used : BehaviorCache(org.sonar.java.se.xproc.BehaviorCache)

Example 4 with BehaviorCache

use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.

the class BytecodeEGWalkerTest method max_step_exception_should_log_warning_and_generate_behavior.

@Test
public void max_step_exception_should_log_warning_and_generate_behavior() {
    BytecodeEGWalker bytecodeEGWalker = new BytecodeEGWalker(new BehaviorCache(squidClassLoader), semanticModel) {

        @Override
        int maxSteps() {
            return 2;
        }
    };
    MethodBehavior methodBehavior = getMethodBehavior(BytecodeTestClass.class, "fun(ZLjava/lang/Object;)Ljava/lang/Object;", bytecodeEGWalker);
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Dataflow analysis is incomplete for method org.sonar.java.bytecode.se.testdata.BytecodeTestClass#fun(ZLjava/lang/Object;)Ljava/lang/Object;" + " : Too many steps resolving org.sonar.java.bytecode.se.testdata.BytecodeTestClass#fun(ZLjava/lang/Object;)Ljava/lang/Object;");
    assertThat(methodBehavior.isComplete()).isFalse();
    assertThat(methodBehavior.isVisited()).isTrue();
}
Also used : MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) Test(org.junit.Test)

Example 5 with BehaviorCache

use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.

the class BytecodeEGWalkerTest method getBytecodeEGWalker.

private static BytecodeEGWalker getBytecodeEGWalker(SquidClassLoader squidClassLoader) {
    BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
    behaviorCache.setFileContext(null, semanticModel);
    return new BytecodeEGWalker(behaviorCache, semanticModel);
}
Also used : BehaviorCache(org.sonar.java.se.xproc.BehaviorCache)

Aggregations

BehaviorCache (org.sonar.java.se.xproc.BehaviorCache)11 Test (org.junit.Test)6 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)5 ArrayList (java.util.ArrayList)4 SemanticModel (org.sonar.java.resolve.SemanticModel)3 SETestUtils.createSymbolicExecutionVisitor (org.sonar.java.se.SETestUtils.createSymbolicExecutionVisitor)3 MethodBehavior (org.sonar.java.se.xproc.MethodBehavior)3 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)3 BinaryExpressionTree (org.sonar.plugins.java.api.tree.BinaryExpressionTree)3 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)3 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)3 Tree (org.sonar.plugins.java.api.tree.Tree)3 File (java.io.File)2 ObjectConstraint (org.sonar.java.se.constraint.ObjectConstraint)2 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 BytecodeCFG (org.sonar.java.bytecode.cfg.BytecodeCFG)1 Instruction (org.sonar.java.bytecode.cfg.Instruction)1 CFG (org.sonar.java.cfg.CFG)1