Skip to content
GraphOptions.java 1.41 KiB
Newer Older
package tfm.graphbuilding;

import com.github.javaparser.ast.Node;
import tfm.graphs.CFG;
import tfm.graphs.Graph;
import tfm.graphs.PDG;
import tfm.graphs.SDG;
import tfm.visitors.cfg.CFGBuilder;
import tfm.visitors.pdg.PDGBuilder;
import tfm.visitors.sdg.SDGBuilder;

public abstract class GraphOptions<G extends Graph> {
    public abstract G empty();

    public G fromASTNode(Node node) {
        G emptyGraph = empty();

        buildGraphWithSpecificVisitor(emptyGraph, node);

        return emptyGraph;
    }

    protected abstract void buildGraphWithSpecificVisitor(G emptyGraph, Node node);
}

class CFGOptions extends GraphOptions<CFG> {
    public CFG empty() {
        return new CFG();
    protected void buildGraphWithSpecificVisitor(CFG emptyGraph, Node node) {
        node.accept(new CFGBuilder(emptyGraph), null);
    }
}

class PDGOptions extends GraphOptions<PDG> {
    public PDG empty() {
        return new PDG();
    protected void buildGraphWithSpecificVisitor(PDG emptyGraph, Node node) {
        node.accept(new PDGBuilder(emptyGraph), emptyGraph.getRootNode());
    }
}

class SDGOptions extends GraphOptions<SDG> {
    public SDG empty() {
        return new SDG();
    protected void buildGraphWithSpecificVisitor(SDG emptyGraph, Node node) {
        node.accept(new SDGBuilder(emptyGraph), null);
    }
}