Skip to content
Snippets Groups Projects
Commit c7a2eb70 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

moved unnecessary fields from JSysCFG to JSysCFG.Builder

Closes #54
parent 47cc94ec
No related branches found
No related tags found
1 merge request!57Fix bad smells
......@@ -25,22 +25,20 @@ import java.util.Set;
* polymorphism and other features.
*/
public class JSysCFG extends ESCFG {
/** ClassGraph associated to the Method represented by the CFG */
protected ClassGraph classGraph;
/** Set of constructors that must be built with implicit nodes. */
protected Set<ConstructorDeclaration> implicitConstructors;
public JSysCFG(ClassGraph classGraph, Set<ConstructorDeclaration> implicitConstructors) {
super();
this.classGraph = classGraph;
this.implicitConstructors = implicitConstructors;
@Override
public void build(CallableDeclaration<?> declaration) {
throw new UnsupportedOperationException("Use build(CallableDeclaration, ClassGraph, Set<ConstructorDeclaration>)");
}
@Override
public void buildRootNode(CallableDeclaration<?> rootNodeAst) {
super.buildRootNode(rootNodeAst);
if (implicitConstructors.contains(rootNodeAst))
rootNode.markAsImplicit();
public void build(CallableDeclaration<?> declaration, ClassGraph classGraph, Set<ConstructorDeclaration> implicitConstructors) {
Builder builder = (Builder) newCFGBuilder();
builder.classGraph = classGraph;
builder.implicitDeclaration = implicitConstructors.contains(declaration);
declaration.accept(builder, null);
// Verify that it has been built
exitNode = vertexSet().stream().filter(MethodExitNode.class::isInstance).findFirst()
.orElseThrow(() -> new IllegalStateException("Built graph has no exit node!"));
built = true;
}
@Override
......@@ -49,6 +47,8 @@ public class JSysCFG extends ESCFG {
}
public class Builder extends ESCFG.Builder {
/** ClassGraph associated to the Method represented by the CFG */
protected ClassGraph classGraph;
/** List of implicit instructions inserted explicitly in this CFG.
* They should be included in the graph as ImplicitNodes. */
protected List<Node> methodInsertedInstructions = new LinkedList<>();
......@@ -93,8 +93,6 @@ public class JSysCFG extends ESCFG {
@Override
public void visit(ConstructorDeclaration n, Void arg) {
if (implicitConstructors.contains(n))
implicitDeclaration = true;
// Insert call to super() if it is implicit.
if (!ASTUtils.constructorHasExplicitConstructorInvocation(n)){
var superCall = new ExplicitConstructorInvocationStmt(null, null, false, null, new NodeList<>());
......@@ -106,11 +104,13 @@ public class JSysCFG extends ESCFG {
}
// Perform the same task as previous graphs.
super.visit(n, arg);
// Convert the exit nodes to implicit if appropriate
if (implicitDeclaration)
// Convert enter/exit nodes to implicit if appropriate
if (implicitDeclaration) {
getRootNode().markAsImplicit();
vertexSet().stream()
.filter(MethodExitNode.class::isInstance)
.forEach(GraphNode::markAsImplicit);
}
}
}
}
......@@ -3,6 +3,7 @@ package es.upv.mist.slicing.graphs.jsysdg;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.visitor.ModifierVisitor;
......@@ -45,9 +46,14 @@ public class JSysDG extends ESSDG {
}, null);
}
@Override
protected void buildCFG(CallableDeclaration<?> declaration, CFG cfg) {
((JSysCFG) cfg).build(declaration, classGraph, newlyInsertedConstructors);
}
@Override
protected CFG createCFG() {
return new JSysCFG(classGraph, newlyInsertedConstructors);
return new JSysCFG();
}
@Override
......
package es.upv.mist.slicing.graphs.jsysdg;
import com.github.javaparser.ast.body.ConstructorDeclaration;
import es.upv.mist.slicing.graphs.ClassGraph;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESPDG;
import java.util.Set;
public class JSysPDG extends ESPDG {
public JSysPDG(ClassGraph classGraph, Set<ConstructorDeclaration> implicitConstructors) {
this(new JSysCFG(classGraph, implicitConstructors));
public JSysPDG() {
this(new JSysCFG());
}
public JSysPDG(JSysCFG cfg) {
......
......@@ -129,19 +129,24 @@ public class SDG extends Graph implements Sliceable, Buildable<NodeList<Compilat
@Override
public void visit(MethodDeclaration n, Void arg) {
CFG cfg = createCFG();
cfg.build(n);
buildCFG(n, cfg);
cfgMap.put(n, cfg);
}
@Override
public void visit(ConstructorDeclaration n, Void arg) {
CFG cfg = createCFG();
cfg.build(n);
buildCFG(n, cfg);
cfgMap.put(n, cfg);
}
}, null);
}
/** Given a single empty CFG and a declaration, build the CFG. */
protected void buildCFG(CallableDeclaration<?> declaration, CFG cfg) {
cfg.build(declaration);
}
/** Create call graph from the list of compilation units. */
protected CallGraph createCallGraph(NodeList<CompilationUnit> nodeList) {
CallGraph callGraph = new CallGraph(cfgMap, classGraph);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment