Search in sources :

Example 1 with UCFGBuilder

use of org.sonar.ucfg.UCFGBuilder in project sonar-java by SonarSource.

the class UCFGJavaVisitor method buildUCfg.

private UCFG buildUCfg(MethodTree methodTree, CFG cfg) {
    String signature = signatureFor(methodTree.symbol());
    IdentifierGenerator idGenerator = new IdentifierGenerator(methodTree);
    UCFGBuilder builder = UCFGBuilder.createUCFGForMethod(signature);
    methodTree.parameters().stream().map(p -> idGenerator.lookupIdFor(p.symbol())).map(UCFGBuilder::variableWithId).forEach(builder::addMethodParam);
    BlockBuilder entryBlockBuilder = buildBasicBlock(cfg.entry(), methodTree, idGenerator);
    if (getAnnotatedStringParameters(methodTree).count() > 0) {
        builder.addStartingBlock(buildParameterAnnotationsBlock(methodTree, idGenerator, cfg));
        builder.addBasicBlock(entryBlockBuilder);
    } else {
        builder.addStartingBlock(entryBlockBuilder);
    }
    cfg.blocks().stream().filter(b -> !b.equals(cfg.entry())).forEach(b -> builder.addBasicBlock(buildBasicBlock(b, methodTree, idGenerator)));
    return builder.build();
}
Also used : JavaSymbol(org.sonar.java.resolve.JavaSymbol) Label(org.sonar.ucfg.Label) BaseTreeVisitor(org.sonar.plugins.java.api.tree.BaseTreeVisitor) JavaFileScanner(org.sonar.plugins.java.api.JavaFileScanner) Loggers(org.sonar.api.utils.log.Loggers) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) PLUS(org.sonar.plugins.java.api.tree.Tree.Kind.PLUS) Map(java.util.Map) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) Set(java.util.Set) Collectors(java.util.stream.Collectors) JavaFileScannerContext(org.sonar.plugins.java.api.JavaFileScannerContext) Sets(com.google.common.collect.Sets) List(java.util.List) UCFGtoProtobuf(org.sonar.ucfg.UCFGtoProtobuf) Stream(java.util.stream.Stream) MEMBER_SELECT(org.sonar.plugins.java.api.tree.Tree.Kind.MEMBER_SELECT) UCFGBuilder.variableWithId(org.sonar.ucfg.UCFGBuilder.variableWithId) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) Symbol(org.sonar.plugins.java.api.semantic.Symbol) ASSIGNMENT(org.sonar.plugins.java.api.tree.Tree.Kind.ASSIGNMENT) PLUS_ASSIGNMENT(org.sonar.plugins.java.api.tree.Tree.Kind.PLUS_ASSIGNMENT) UCFG(org.sonar.ucfg.UCFG) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) HashSet(java.util.HashSet) BlockBuilder(org.sonar.ucfg.UCFGBuilder.BlockBuilder) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) UCFGBuilder(org.sonar.ucfg.UCFGBuilder) LiteralUtils(org.sonar.java.model.LiteralUtils) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) ReturnStatementTree(org.sonar.plugins.java.api.tree.ReturnStatementTree) LiteralTree(org.sonar.plugins.java.api.tree.LiteralTree) UCFGBuilder.call(org.sonar.ucfg.UCFGBuilder.call) METHOD_INVOCATION(org.sonar.plugins.java.api.tree.Tree.Kind.METHOD_INVOCATION) Tree(org.sonar.plugins.java.api.tree.Tree) Type(org.sonar.plugins.java.api.semantic.Type) File(java.io.File) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) LocationInFile(org.sonar.ucfg.LocationInFile) CFG(org.sonar.java.cfg.CFG) VariableReadExtractor(org.sonar.java.cfg.VariableReadExtractor) Preconditions(com.google.common.base.Preconditions) Expression(org.sonar.ucfg.Expression) UCFGBuilder.constant(org.sonar.ucfg.UCFGBuilder.constant) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) UCFGBuilder(org.sonar.ucfg.UCFGBuilder) BlockBuilder(org.sonar.ucfg.UCFGBuilder.BlockBuilder)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 Logger (org.sonar.api.utils.log.Logger)1 Loggers (org.sonar.api.utils.log.Loggers)1 CFG (org.sonar.java.cfg.CFG)1 VariableReadExtractor (org.sonar.java.cfg.VariableReadExtractor)1 LiteralUtils (org.sonar.java.model.LiteralUtils)1 JavaSymbol (org.sonar.java.resolve.JavaSymbol)1 JavaFileScanner (org.sonar.plugins.java.api.JavaFileScanner)1 JavaFileScannerContext (org.sonar.plugins.java.api.JavaFileScannerContext)1