From d55e86bcb9df02d5064f7bff00ba95fa4ad6f71b Mon Sep 17 00:00:00 2001 From: Matheus Barbosa Date: Wed, 6 Oct 2021 17:44:44 -0300 Subject: [PATCH] refactor(#31): pr adjuts --- .../AbstractMergeConflictDefinition.java | 15 +++--- .../InterproceduralOverrideAssignment.java | 54 +++++-------------- .../br/unb/cic/analysis/model/Statement.java | 12 +++++ 3 files changed, 31 insertions(+), 50 deletions(-) diff --git a/src/main/java/br/unb/cic/analysis/AbstractMergeConflictDefinition.java b/src/main/java/br/unb/cic/analysis/AbstractMergeConflictDefinition.java index ecfd51b2..1529d9b2 100644 --- a/src/main/java/br/unb/cic/analysis/AbstractMergeConflictDefinition.java +++ b/src/main/java/br/unb/cic/analysis/AbstractMergeConflictDefinition.java @@ -6,10 +6,10 @@ import soot.jimple.IdentityStmt; import soot.jimple.InvokeStmt; import soot.jimple.Stmt; -import soot.jimple.internal.JAssignStmt; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * This abstract class works as a contract. Whenever we @@ -42,7 +42,6 @@ public void loadSinkStatements() { sinkStatements = loadStatements(sinkDefinitions, Statement.Type.SINK); } - public List getSourceStatements() { return sourceStatements; } @@ -51,7 +50,6 @@ public List getSinkStatements() { return sinkStatements; } - /** * This method should return a list of pairs, where the * first element is the full qualified name of @@ -153,7 +151,7 @@ else if(u instanceof InvokeStmt) { return res; } - private Statement createStatement(SootMethod sm, Unit u, Statement.Type type) { + public Statement createStatement(SootMethod sm, Unit u, Statement.Type type) { return Statement.builder().setClass(sm.getDeclaringClass()).setMethod(sm) .setUnit(u).setType(type).setSourceCodeLineNumber(u.getJavaSourceStartLineNumber()) .build(); @@ -199,11 +197,10 @@ private SootClass retrieveOuterClass(SootClass aClass) { * or not. So, in this implementation, we first try to retrieve * one. If an exception is thrown, we just return null. */ - private Body retrieveActiveBodySafely(SootMethod method) { + public Body retrieveActiveBodySafely(SootMethod method) { try { return method.retrieveActiveBody(); - } - catch(RuntimeException e) { + } catch (RuntimeException e) { return null; } } diff --git a/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java b/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java index 28475cb4..324909e4 100644 --- a/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java +++ b/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java @@ -125,7 +125,7 @@ private FlowSet traverse(FlowSet in, S this.traversedMethods.add(sootMethod); - Body body = retrieveActiveBodySafely(sootMethod); + Body body = definition.retrieveActiveBodySafely(sootMethod); if (body != null) { for (Unit unit : body.getUnits()) { @@ -146,13 +146,6 @@ private FlowSet traverse(FlowSet in, S return in; } - private Body retrieveActiveBodySafely(SootMethod sootMethod) { - try { - return sootMethod.retrieveActiveBody(); - } catch (RuntimeException e) { - return null; - } - } private FlowSet runAnalysisWithTaggedUnit(FlowSet in, SootMethod sootMethod, Statement.Type flowChangeTag, Unit unit) { @@ -193,7 +186,7 @@ private FlowSet runAnalysis(FlowSet in separeteAbstraction(in); if (tagged) { Statement stmt = getStatementAssociatedWithUnit(sootMethod, unit, flowChangeTag); - setStackTraceInStmt(stmt); + stmt.setTraversedLine(new ArrayList<>(this.stacktraceList)); // logger.log(Level.INFO, () -> String.format("%s", "stmt: " + stmt.toString())); gen(in, stmt); } else { @@ -226,12 +219,12 @@ In this case, this condition will be executed for the call to the foo() method a private void separeteAbstraction(FlowSet in) { in.forEach(item -> { - if (isLefAndRightStatement(item.getStmt())) { - right.add(item); + if (item.getStmt().isLefAndRightStatement()) { left.add(item); - } else if (isLeftStatement(item.getStmt())) { + right.add(item); + } else if (item.getStmt().isLeftStatement()) { left.add(item); - } else if (isRightStatement(item.getStmt())) { + } else if (item.getStmt().isRightStatement()) { right.add(item); } }); @@ -281,13 +274,13 @@ private boolean isInLeftAndRightStatementFlow(Statement.Type flowChangeTag) { // TODO add depth to InstanceFieldRef and StaticFieldRef... // TODO rename Statement. (UnitWithExtraInformations) private void gen(FlowSet in, Statement stmt) { - if (isLeftStatement(stmt)) { + if (stmt.isLeftStatement()) { checkConflict(stmt, right); - } else if (isRightStatement(stmt)) { + } else if (stmt.isRightStatement()) { checkConflict(stmt, left); - } else if (isLefAndRightStatement(stmt)) { + } else if (stmt.isLefAndRightStatement()) { addConflict(stmt, stmt); } addStmtToList(stmt, in); @@ -373,21 +366,17 @@ private String getArrayRefName(ArrayRef arrayRef) { private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u, Statement.Type flowChangeTag) { if (isLeftAndRightUnit(u) || isInLeftAndRightStatementFlow(flowChangeTag) || isBothUnitOrBothStatementFlow(u, flowChangeTag)) { - return createStatement(sootMethod, u, Statement.Type.SOURCE_SINK); + return definition.createStatement(sootMethod, u, Statement.Type.SOURCE_SINK); } else if (isLeftUnit(u)) { return findLeftStatement(u); } else if (isRightUnit(u)) { return findRightStatement(u); } else if (isInLeftStatementFlow(flowChangeTag)) { - return createStatement(sootMethod, u, flowChangeTag); + return definition.createStatement(sootMethod, u, flowChangeTag); } else if (isInRightStatementFlow(flowChangeTag)) { - return createStatement(sootMethod, u, flowChangeTag); + return definition.createStatement(sootMethod, u, flowChangeTag); } - return createStatement(sootMethod, u, Statement.Type.IN_BETWEEN); - } - - private void setStackTraceInStmt(Statement stmt) { - stmt.setTraversedLine(new ArrayList<>(this.stacktraceList)); + return definition.createStatement(sootMethod, u, Statement.Type.IN_BETWEEN); } private void addStackTrace(TraversedLine traversedLine) { @@ -424,21 +413,4 @@ private Statement findLeftStatement(Unit u) { findFirst().get(); } - private Statement createStatement(SootMethod sootMethod, Unit u, Statement.Type flowChangeTag) { - return Statement.builder().setClass(sootMethod.getDeclaringClass()).setMethod(sootMethod) - .setUnit(u).setType(flowChangeTag).setSourceCodeLineNumber(u.getJavaSourceStartLineNumber()) - .build(); - } - - private boolean isRightStatement(Statement stmt) { - return stmt.getType().equals(Statement.Type.SINK); - } - - private boolean isLeftStatement(Statement stmt) { - return stmt.getType().equals(Statement.Type.SOURCE); - } - - private boolean isLefAndRightStatement(Statement stmt) { - return stmt.getType().equals(Statement.Type.SOURCE_SINK); - } } diff --git a/src/main/java/br/unb/cic/analysis/model/Statement.java b/src/main/java/br/unb/cic/analysis/model/Statement.java index 8fc1b554..54ff8479 100644 --- a/src/main/java/br/unb/cic/analysis/model/Statement.java +++ b/src/main/java/br/unb/cic/analysis/model/Statement.java @@ -109,6 +109,18 @@ public boolean isSink() { return type == Type.SINK || type == Type.SOURCE_SINK; } + public boolean isRightStatement() { + return this.type == Type.SINK || type == Type.SOURCE_SINK; + } + + public boolean isLeftStatement() { + return this.type == Type.SOURCE || type == Type.SOURCE_SINK; + } + + public boolean isLefAndRightStatement() { + return this.type == Type.SOURCE_SINK; + } + public boolean isAssign() { return this.unit instanceof AssignStmt; }