Search in sources :

Example 11 with BehaviorCache

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

the class DebugCheckTestUtils method verifyIssuesWithMaxSteps.

static void verifyIssuesWithMaxSteps(String sourcefile, SECheck check, int maxSteps) {
    BehaviorCache behaviorCache = new BehaviorCache(new SquidClassLoader(new ArrayList<>()));
    SymbolicExecutionVisitor sev = new SymbolicExecutionVisitor(Collections.singletonList(check), behaviorCache) {

        @Override
        protected ExplodedGraphWalker getWalker() {
            return new ExplodedGraphWalker(Collections.singletonList(check), behaviorCache, (SemanticModel) context.getSemanticModel()) {

                @Override
                protected int maxSteps() {
                    return maxSteps;
                }
            };
        }

        @Override
        public void scanFile(JavaFileScannerContext context) {
            super.scanFile(context);
            // the check has been executed, but we still need to call the scan manually to report the issues
            check.scanFile(context);
        }
    };
    JavaCheckVerifier.verify(sourcefile, sev);
}
Also used : ExplodedGraphWalker(org.sonar.java.se.ExplodedGraphWalker) JavaFileScannerContext(org.sonar.plugins.java.api.JavaFileScannerContext) ArrayList(java.util.ArrayList) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) SymbolicExecutionVisitor(org.sonar.java.se.SymbolicExecutionVisitor) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

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