Commit df09b4eb authored by Carlos Galindo's avatar Carlos Galindo
Browse files

First approach to AC

parent 142c36e1
Loading
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.cli;

import es.upv.mist.slicing.graphs.ClassGraph;
import org.jgrapht.nio.Attribute;
import org.jgrapht.nio.dot.DOTExporter;

import java.util.Map;

public class ClassGraphLog {
    protected DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> getDOTExporter() {
        DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> dot = new DOTExporter<>();
        dot.setVertexAttributeProvider(this::attributes);
        dot.setEdgeAttributeProvider(this::attributes);
        return dot;
    }

    protected Map<String, Attribute> attributes(ClassGraph.Vertex<?> vertex) {
        DOTAttributes res = new DOTAttributes();
        res.set("label", vertex.toString());
        if (vertex instanceof ClassGraph.ClassVertex<?> && ((ClassGraph.ClassVertex<?>) vertex).isUserDefined())
            res.add("style", "filled");
        return res.build();
    }

    protected Map<String, Attribute> attributes(ClassGraph.ClassArc arc) {
        DOTAttributes res = new DOTAttributes();
        return res.build();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ public class CallGraph extends DirectedPseudograph<CallGraph.Vertex, CallGraph.E
                }
                Optional<Expression> scope = call.getScope();
                // Determine the type of the call's scope
                Set<ClassOrInterfaceDeclaration> dynamicTypes;
                Stream<ClassGraph.ClassVertex<?>> dynamicTypes;
                if (scope.isEmpty()) {
                    // a) No scope: any class the method is in, or any outer class if the class is not static.
                    // Early exit: it is easier to find the methods that override the
@@ -211,7 +211,7 @@ public class CallGraph extends DirectedPseudograph<CallGraph.Vertex, CallGraph.E
                // To locate them, use the method signature and search for it in the class graph
                // Connect to each declaration
                AtomicInteger edgesCreated = new AtomicInteger();
                dynamicTypes.stream()
                dynamicTypes
                        .map(t -> classGraph.findMethodByTypeAndSignature(t, decl))
                        .collect(Collectors.toCollection(NodeHashSet::new))
                        .forEach(methodDecl -> {
+452 −88

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class ExpressionObjectTreeFinder {
     * @return A list of pairs, containing the variable actions and the member of such
     * actions where the link must be placed.
     */
    protected List<Pair<VariableAction, String>> locateExpressionResultTrees(Expression expression) {
    public List<Pair<VariableAction, String>> locateExpressionResultTrees(Expression expression) {
        List<Pair<VariableAction, String>> list = new LinkedList<>();
        expression.accept(new VoidVisitorAdapter<String>() {
            @Override
@@ -289,7 +289,7 @@ public class ExpressionObjectTreeFinder {
        String sourceMember = sourcePair.b;
        if (targetAction.hasObjectTree()) {
            boolean sourceTypesInClassGraph = sourceAction.getDynamicTypes().stream()
                    .anyMatch(ClassGraph.getInstance()::containsType);
                    .anyMatch(ClassGraph.getInstance()::containsVertex);
            if (sourceTypesInClassGraph && !sourceAction.hasObjectTree())
                ObjectTree.copyTargetTreeToSource(sourceAction.getObjectTree(), targetAction.getObjectTree(), sourceMember, targetMember);
            sourceAction.setPDGTreeConnectionTo(targetAction, sourceMember, targetMember);
+11 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.BooleanLiteralExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitor;
@@ -341,6 +342,16 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
    // ============================ Declarations ============================
    // ======================================================================

    @Override
    public void visit(ObjectCreationExpr n, Void arg) {
//        n.getAnonymousClassBody().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
        n.getArguments().forEach(p -> p.accept(this, arg));
        n.getScope().ifPresent(l -> l.accept(this, arg));
        n.getType().accept(this, arg);
        n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
        n.getComment().ifPresent(l -> l.accept(this, arg));
    }

    @Override
    public void visit(MethodDeclaration n, Void arg) {
        visitCallableDeclaration(n, arg);
Loading