Verified Commit 0dde2d97 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Partial support for nested calls: unify behaviour of NOT visiting nested calls.

* CallGraph, VariableVisitor: unify visit arguments behaviour to avoid lookup errors of calls
  by the CallGraph that were not registered by VariableVisitor.
parent c4c00b25
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -127,18 +127,21 @@ public class CallGraph extends DirectedPseudograph<CallGraph.Vertex, CallGraph.E
            @Override
            public void visit(MethodCallExpr n, Void arg) {
                n.resolve().toAst().ifPresent(decl -> addEdge(declStack.peek(), decl, n));
                if (ASTUtils.shouldVisitArgumentsForMethodCalls(n))
                    super.visit(n, arg);
            }

            @Override
            public void visit(ObjectCreationExpr n, Void arg) {
                n.resolve().toAst().ifPresent(decl -> addEdge(declStack.peek(), decl, n));
                if (ASTUtils.shouldVisitArgumentsForMethodCalls(n))
                    super.visit(n, arg);
            }

            @Override
            public void visit(ExplicitConstructorInvocationStmt n, Void arg) {
                n.resolve().toAst().ifPresent(decl -> addEdge(declStack.peek(), decl, n));
                if (ASTUtils.shouldVisitArgumentsForMethodCalls(n))
                    super.visit(n, arg);
            }
        }, null);
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ public class VariableVisitor extends GraphNodeContentVisitor<VariableVisitor.Act

    /** Tries to resolve and add the corresponding call markers. */
    protected boolean visitCall(Resolvable<? extends ResolvedMethodLikeDeclaration> call, Action arg) {
        if (ASTUtils.getResolvedAST(call.resolve()).isEmpty() || graphNode == null)
        if (ASTUtils.shouldVisitArgumentsForMethodCalls(call, graphNode))
            return true;
        graphNode.addCallMarker(call, true);
        ASTUtils.getResolvableScope(call).ifPresent(s -> s.accept(this, arg));
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclarat
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration;
import es.upv.mist.slicing.nodes.GraphNode;

import java.util.List;
import java.util.Objects;
@@ -117,4 +118,12 @@ public class ASTUtils {
            return ((ResolvedConstructorDeclaration) resolvedDeclaration).toAst();
        throw new IllegalStateException("AST node of invalid type");
    }

    public static boolean shouldVisitArgumentsForMethodCalls(Resolvable<? extends ResolvedMethodLikeDeclaration> call) {
        return getResolvedAST(call.resolve()).isEmpty();
    }

    public static boolean shouldVisitArgumentsForMethodCalls(Resolvable<? extends ResolvedMethodLikeDeclaration> call, GraphNode<?> graphNode) {
        return shouldVisitArgumentsForMethodCalls(call) || graphNode == null;
    }
}