Loading sdg-cli/src/main/java/es/upv/mist/slicing/cli/ClassGraphLog.java 0 → 100644 +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(); } } sdg-core/src/main/java/es/upv/mist/slicing/graphs/CallGraph.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 -> { Loading sdg-core/src/main/java/es/upv/mist/slicing/graphs/ClassGraph.java +452 −88 File changed.Preview size limit exceeded, changes collapsed. Show changes sdg-core/src/main/java/es/upv/mist/slicing/graphs/ExpressionObjectTreeFinder.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); Loading sdg-core/src/main/java/es/upv/mist/slicing/graphs/cfg/CFGBuilder.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
sdg-cli/src/main/java/es/upv/mist/slicing/cli/ClassGraphLog.java 0 → 100644 +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(); } }
sdg-core/src/main/java/es/upv/mist/slicing/graphs/CallGraph.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 -> { Loading
sdg-core/src/main/java/es/upv/mist/slicing/graphs/ClassGraph.java +452 −88 File changed.Preview size limit exceeded, changes collapsed. Show changes
sdg-core/src/main/java/es/upv/mist/slicing/graphs/ExpressionObjectTreeFinder.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); Loading
sdg-core/src/main/java/es/upv/mist/slicing/graphs/cfg/CFGBuilder.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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