Commit 0984e234 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Merge branch 'Sergio' into 'develop'

Dynamic initializerDeclaration in ConstructorDeclaration

See merge request !52
parents cee31cac 639bd5b6
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import com.github.javaparser.ast.comments.BlockComment;
import com.github.javaparser.ast.nodeTypes.NodeWithName;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
import es.upv.mist.slicing.graphs.augmented.ASDG;
import es.upv.mist.slicing.graphs.jsysdg.JSysDG;
import es.upv.mist.slicing.graphs.augmented.PSDG;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESSDG;
import es.upv.mist.slicing.graphs.sdg.SDG;
@@ -232,11 +233,12 @@ public class Slicer {
        }

        SDG sdg;
        switch (cliOpts.getOptionValue("type", "ESSDG")) {
        switch (cliOpts.getOptionValue("type", "JSysDG")) {
            case "SDG":   sdg = new SDG();   break;
            case "ASDG":  sdg = new ASDG();  break;
            case "PSDG":  sdg = new PSDG();  break;
            case "ESSDG": sdg = new ESSDG(); break;
            case "JSysDG": sdg = new JSysDG(); break;
            default:
                throw new IllegalArgumentException("Unknown type of graph. Available graphs are SDG, ASDG, PSDG, ESSDG");
        }
+33 −2
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
@@ -202,7 +203,6 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex, ClassGrap
    /** Add a field declaration vertex to the class graph */
    protected void addFieldDeclaration(FieldDeclaration n, ClassOrInterfaceDeclaration c){
        ClassGraph.Vertex v = new ClassGraph.Vertex(n);
        // Key value: hashCode + toString() to avoid multiple field declarations with the same syntax in different classes
        vertexDeclarationMap.put(c.getFullyQualifiedName().get()+ "." + n.toString(), v);
        addVertex(v);
    }
@@ -270,7 +270,6 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex, ClassGrap
                addEdge(source, v, new ClassArc.Implements());
        });
    }

    /** Creates a graph-appropriate DOT exporter. */
    public DOTExporter<CallableDeclaration<?>, CallGraph.Edge<?>> getDOTExporter() {
        DOTExporter<CallableDeclaration<?>, CallGraph.Edge<?>> dot = new DOTExporter<>();
@@ -311,6 +310,38 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex, ClassGrap
        }
    }

    /** Returns a List with the static FieldDeclarations and InitializerDeclarations of the given class */
    public List<BodyDeclaration<?>> getStaticInit(String className){
        return getClassInit(className,true);
    }

    /** Returns a List with the dynamic FieldDeclarations and InitializerDeclarations of the given class */
    public List<BodyDeclaration<?>> getDynInit(String className){
        return getClassInit(className,false);
    }

    /** Returns a List with FieldDeclarations and InitializerDeclarations static/dynamic items of the given class */
    private List<BodyDeclaration<?>> getClassInit(String className, Boolean isStatic){
        Vertex classNode = vertexDeclarationMap.get(className);
        List<BodyDeclaration<?>> members = classNode.declaration.asClassOrInterfaceDeclaration().getMembers();
        List<BodyDeclaration<?>> classInit = new LinkedList<>();
        for (BodyDeclaration<?> member : members) {
            if (member instanceof CallableDeclaration<?>)
                continue;

            if (member.isFieldDeclaration()) {
                if (isStatic == member.asFieldDeclaration().hasModifier(Modifier.Keyword.STATIC))
                    classInit.add(member);
                continue;
            }

            if (member.isInitializerDeclaration())
                if (isStatic == member.asInitializerDeclaration().isStatic())
                    classInit.add(member);
        }
        return classInit;
    }

    protected static class ClassArc extends Arc {
        /** An arc that connects a class with another one that inherits from it. */
        protected static class Extends extends ClassArc {}
+1 −3
Original line number Diff line number Diff line
@@ -87,9 +87,7 @@ public class GraphNodeContentVisitor<A> extends VoidVisitorAdapter<A> {
    }

    @Override
    public void visit(FieldDeclaration n, A arg) {
        throw new UnsupportedOperationException();
    }
    public void visit(FieldDeclaration n, A arg) { super.visit(n, arg); }

    @Override
    public void visit(ForEachStmt n, A arg) {
+1 −2
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.augmented;

import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.stmt.*;
import es.upv.mist.slicing.graphs.cfg.CFGBuilder;
import es.upv.mist.slicing.nodes.GraphNode;
@@ -134,7 +133,7 @@ public class ACFGBuilder extends CFGBuilder {
        GraphNode<ReturnStmt> node = connectTo(returnStmt);
        returnStmt.getExpression().ifPresent(n -> {
            n.accept(this, arg);
            node.addDefinedVariable(new NameExpr(VARIABLE_NAME_OUTPUT), n);
            node.addDefinedVariable(null, VARIABLE_NAME_OUTPUT, n);
        });
        returnList.add(node);
        clearHanging();
+2 −3
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ 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.NameExpr;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitor;
@@ -331,7 +330,7 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
        GraphNode<ReturnStmt> node = connectTo(returnStmt);
        returnStmt.getExpression().ifPresent(n -> {
            n.accept(this, arg);
            node.addDefinedVariable(new NameExpr(VARIABLE_NAME_OUTPUT), n);
            node.addDefinedVariable(null, VARIABLE_NAME_OUTPUT, n);
        });
        returnList.add(node);
        clearHanging();
@@ -379,7 +378,7 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
     * @see #VARIABLE_NAME_OUTPUT */
    protected void addMethodOutput(CallableDeclaration<?> callableDeclaration, GraphNode<?> exit) {
        if (!(callableDeclaration instanceof MethodDeclaration) || !((MethodDeclaration) callableDeclaration).getType().isVoidType()) {
            VariableAction usage = new VariableAction.Usage(new NameExpr(VARIABLE_NAME_OUTPUT), exit);
            VariableAction usage = new VariableAction.Usage(null, VARIABLE_NAME_OUTPUT, exit);
            exit.addMovableVariable(new VariableAction.Movable(usage, OutputNode.create(callableDeclaration)));
        }
    }
Loading