Commit 9ba2e8d1 authored by Javier Costa's avatar Javier Costa
Browse files

NodeFactory to create new nodes + GraphNode constructors package private

parent 6bb53029
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.io.DOTExporter;
import tfm.arcs.Arc;
import tfm.nodes.GraphNode;
import tfm.utils.NodeFactory;
import tfm.nodes.NodeFactory;

import java.util.*;
import java.util.function.Consumer;
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package tfm.graphs;

import com.github.javaparser.ast.Node;
import tfm.nodes.GraphNode;
import tfm.utils.NodeFactory;
import tfm.nodes.NodeFactory;

import java.util.Objects;
import java.util.Optional;
+4 −3
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import com.github.javaparser.ast.stmt.EmptyStmt;
import org.jgrapht.io.DOTExporter;
import tfm.arcs.Arc;
import tfm.nodes.GraphNode;
import tfm.nodes.NodeFactory;
import tfm.slicing.SlicingCriterion;
import tfm.utils.Context;

@@ -50,7 +51,7 @@ public class SDGGraph extends Graph implements Sliceable<SDGGraph> {
    @Deprecated
    public void addPDG(PDGGraph pdgGraph, MethodDeclaration methodDeclaration) {
        for (Parameter parameter : methodDeclaration.getParameters()) {
            GraphNode<?> sdgNode = new GraphNode<>(
            GraphNode<?> sdgNode = NodeFactory.graphNode(
                    getNextVertexId(),
                    String.format("%s = %s_in", parameter.getNameAsString(), parameter.getNameAsString()),
                    new EmptyStmt()
@@ -61,7 +62,7 @@ public class SDGGraph extends Graph implements Sliceable<SDGGraph> {

        for (GraphNode<?> node : pdgGraph.vertexSet()) {
            if (!this.containsVertex(node)) {
                GraphNode<?> sdgNode = new GraphNode<>(
                GraphNode<?> sdgNode = NodeFactory.computedGraphNode(
                        getNextVertexId(),
                        node.getInstruction(),
                        node.getAstNode(),
@@ -76,7 +77,7 @@ public class SDGGraph extends Graph implements Sliceable<SDGGraph> {
    }

    public void addMethod(MethodDeclaration methodDeclaration, PDGGraph pdgGraph) {
        GraphNode<MethodDeclaration> methodRootNode = new GraphNode<>(
        GraphNode<MethodDeclaration> methodRootNode = NodeFactory.graphNode(
                getNextVertexId(),
                "ENTER " + methodDeclaration.getDeclarationAsString(false, false, true),
                methodDeclaration
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ public class GraphNode<N extends Node> {
    private final Set<String> definedVariables;
    private final Set<String> usedVariables;

    public GraphNode(int id, String instruction, @NotNull N astNode) {
    GraphNode(int id, String instruction, @NotNull N astNode) {
        this(
                id,
                instruction,
@@ -39,7 +39,7 @@ public class GraphNode<N extends Node> {
        }
    }

    public GraphNode(
    GraphNode(
                int id,
                String instruction,
                @NonNull N astNode,
+12 −1
Original line number Diff line number Diff line
package tfm.utils;
package tfm.nodes;

import com.github.javaparser.ast.Node;
import org.checkerframework.checker.nullness.qual.NonNull;
import tfm.nodes.GraphNode;

import java.util.Collection;
import java.util.Objects;

public class NodeFactory {

@@ -28,6 +30,12 @@ public class NodeFactory {
            Collection<String> definedVariables,
            Collection<String> usedVariables
    ) {
        Objects.requireNonNull(instruction, "Instruction cannot be null!");
        Objects.requireNonNull(node, "AST Node cannot be null");
        Objects.requireNonNull(declaredVariables, "declared variables collection cannot be null!");
        Objects.requireNonNull(definedVariables, "defined variables collection cannot be null");
        Objects.requireNonNull(usedVariables, "Used variables collection cannot be null!");

        return new GraphNode<>(
                id,
                instruction,
@@ -52,6 +60,9 @@ public class NodeFactory {
            String instruction,
            ASTNode node
    ) {
        Objects.requireNonNull(instruction, "Instruction cannot be null!");
        Objects.requireNonNull(node, "AST Node cannot be null");

        return new GraphNode<>(
                id,
                instruction,