Search in sources :

Example 16 with CFG

use of org.sonar.java.cfg.CFG in project sonar-java by SonarSource.

the class UCFGJavaVisitor method visitMethod.

@Override
public void visitMethod(MethodTree tree) {
    super.visitMethod(tree);
    if (tree.block() != null) {
        CFG cfg = CFG.build(tree);
        try {
            UCFG uCFG = buildUCfg(tree, cfg);
            UCFGtoProtobuf.toProtobufFile(uCFG, filePath());
        } catch (Exception e) {
            LOG.error("Cannot generate ucfg in file " + fileKey + " for method at line" + tree.firstToken().line(), e);
        }
    }
}
Also used : UCFG(org.sonar.ucfg.UCFG) CFG(org.sonar.java.cfg.CFG) UCFG(org.sonar.ucfg.UCFG)

Example 17 with CFG

use of org.sonar.java.cfg.CFG in project sonar-java by SonarSource.

the class ProgramPointTest method test_to_string_method.

@Test
public void test_to_string_method() throws Exception {
    // ToString method of program point is used by viewer.
    CFG cfg = CFGTest.buildCFG("void foo() {foo();}");
    ProgramPoint pp = new ProgramPoint(cfg.blocks().get(0));
    assertThat(pp.toString()).isEqualTo("B1.0  IDENTIFIER1");
    pp = pp.next().next();
    assertThat(pp.toString()).isEqualTo("B1.2  ");
}
Also used : CFG(org.sonar.java.cfg.CFG) Test(org.junit.Test) CFGTest(org.sonar.java.cfg.CFGTest)

Aggregations

CFG (org.sonar.java.cfg.CFG)17 Test (org.junit.Test)7 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)6 LiveVariables (org.sonar.java.cfg.LiveVariables)5 Symbol (org.sonar.plugins.java.api.semantic.Symbol)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 RelationalSymbolicValue (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)4 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)4 List (java.util.List)3 Set (java.util.Set)3 Label (org.objectweb.asm.Label)3 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)3 Tree (org.sonar.plugins.java.api.tree.Tree)3 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)3 Preconditions (com.google.common.base.Preconditions)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 SonarComponents (org.sonar.java.SonarComponents)2