From 77f532e1dae0a52b7bd0ed9a0f2eb81444ab1262 Mon Sep 17 00:00:00 2001 From: Matheus Barbosa Date: Wed, 6 Oct 2021 17:22:22 -0300 Subject: [PATCH] refactor(#31): pr adjuts --- .../InterproceduralOverrideAssignment.java | 46 ++++++++----------- ...duralOverridingAssignmentAnalysisTest.java | 9 ++++ .../samples/ioa/StringArraySample.java | 31 +++++++++++++ 3 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 src/test/java/br/unb/cic/analysis/samples/ioa/StringArraySample.java 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 391ebead..28475cb4 100644 --- a/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java +++ b/src/main/java/br/unb/cic/analysis/ioa/InterproceduralOverrideAssignment.java @@ -23,12 +23,12 @@ // TODO Do not add anything when assignments are equal. public class InterproceduralOverrideAssignment extends SceneTransformer implements AbstractAnalysis { - private final Set conflicts; - private final PointsToAnalysis pointsToAnalysis; - private final List traversedMethods; - private final AbstractMergeConflictDefinition definition; - private final FlowSet left; - private final FlowSet right; + private Set conflicts; + private PointsToAnalysis pointsToAnalysis; + private List traversedMethods; + private AbstractMergeConflictDefinition definition; + private FlowSet left; + private FlowSet right; private List stacktraceList; private final Logger logger; @@ -76,13 +76,8 @@ protected void internalTransform(String s, Map map) { List methods = Scene.v().getEntryPoints(); methods.forEach(sootMethod -> traverse(new ArraySparseSet<>(), sootMethod, Statement.Type.IN_BETWEEN)); - Set conflictsFilter = new HashSet<>(); - filterConflicts(getConflicts(), conflictsFilter); - - logger.log(Level.INFO, () -> String.format("%s", "Number of conflicts filter: " + conflictsFilter.size())); - conflictsFilter.forEach(conflict -> { - logger.log(Level.INFO, conflict.toStringAbstract()); - }); + Set conflictsFilter = filterConflicts(getConflicts()); + conflictsFilter.forEach(conflict -> logger.log(Level.INFO, conflict.toStringAbstract())); //logger.log(Level.INFO, () -> String.format("%s", "CONFLICTS: " + conflictsFilter)); @@ -97,7 +92,8 @@ protected void internalTransform(String s, Map map) { }); */ } - private void filterConflicts(Set conflictsResults, Set conflictsFilter) { + private Set filterConflicts(Set conflictsResults) { + Set conflictsFilter = new HashSet<>(); conflictsResults.forEach(conflict -> { if (conflictsFilter.isEmpty()) { conflictsFilter.add(conflict); @@ -108,6 +104,7 @@ private void filterConflicts(Set conflictsResults, Set confl } }); }); + return conflictsFilter; } /** @@ -190,7 +187,7 @@ private FlowSet runAnalysis(FlowSet in AssignStmt assignStmt = (AssignStmt) unit; if (assignStmt.containsInvokeExpr()) { - return executeCallGraph(in, flowChangeTag, unit, sootMethod); + return executeCallGraph(in, flowChangeTag, unit); } separeteAbstraction(in); @@ -221,7 +218,7 @@ In this case, this condition will be executed for the call to the foo() method a For builders, InvokeExpression is an instance of InvokeSpecial */ } else if (unit instanceof InvokeStmt) { - return executeCallGraph(in, flowChangeTag, unit, sootMethod); + return executeCallGraph(in, flowChangeTag, unit); } return in; @@ -241,11 +238,11 @@ private void separeteAbstraction(FlowSet in) { } private FlowSet executeCallGraph(FlowSet in, - Statement.Type flowChangeTag, Unit unit, SootMethod sootMethod) { + Statement.Type flowChangeTag, Unit unit) { CallGraph callGraph = Scene.v().getCallGraph(); Iterator edges = callGraph.edgesOutOf(unit); - List> flowSetList = new ArrayList>(); + List> flowSetList = new ArrayList<>(); while (edges.hasNext()) { Edge e = edges.next(); @@ -258,7 +255,9 @@ private FlowSet executeCallGraph(FlowSet flowSetUnion = new ArraySparseSet<>(); - flowSetList.forEach(flowSet -> flowSetUnion.union(flowSet)); + for (FlowSet flowSet : flowSetList) { + flowSetUnion.union(flowSet); + } return flowSetUnion; } @@ -388,7 +387,7 @@ private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u, } private void setStackTraceInStmt(Statement stmt) { - stmt.setTraversedLine(new ArrayList(this.stacktraceList)); + stmt.setTraversedLine(new ArrayList<>(this.stacktraceList)); } private void addStackTrace(TraversedLine traversedLine) { @@ -400,12 +399,7 @@ private void removeStackTrace(TraversedLine traversedLine) { } private boolean isBothUnitOrBothStatementFlow(Unit u, Statement.Type flowChangeTag) { - if (isRightUnit(u) && isInLeftStatementFlow(flowChangeTag)) { - return true; - } else if (isLeftUnit(u) && isInRightStatementFlow(flowChangeTag)) { - return true; - } - return false; + return (isRightUnit(u) && isInLeftStatementFlow(flowChangeTag)) || (isLeftUnit(u) && isInRightStatementFlow(flowChangeTag)); } private boolean isLeftUnit(Unit u) { diff --git a/src/test/java/br/unb/cic/analysis/ioa/InterproceduralOverridingAssignmentAnalysisTest.java b/src/test/java/br/unb/cic/analysis/ioa/InterproceduralOverridingAssignmentAnalysisTest.java index 453feb1d..3aafe871 100644 --- a/src/test/java/br/unb/cic/analysis/ioa/InterproceduralOverridingAssignmentAnalysisTest.java +++ b/src/test/java/br/unb/cic/analysis/ioa/InterproceduralOverridingAssignmentAnalysisTest.java @@ -122,6 +122,15 @@ private void configureSootOptions(List testClasses) { Options.v().set_include(getIncludeList()); } + @Test + public void StringArraySample() { + String sampleClassPath = "br.unb.cic.analysis.samples.ioa.StringArraySample"; + AbstractMergeConflictDefinition definition = DefinitionFactory + .definition(sampleClassPath, new int[]{11}, new int[]{22}); + InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition); + configureTest(analysis); + Assert.assertEquals(1, analysis.getConflicts().size()); + } @Test public void stacktraceConflictSample() { diff --git a/src/test/java/br/unb/cic/analysis/samples/ioa/StringArraySample.java b/src/test/java/br/unb/cic/analysis/samples/ioa/StringArraySample.java new file mode 100644 index 00000000..d4f7d13d --- /dev/null +++ b/src/test/java/br/unb/cic/analysis/samples/ioa/StringArraySample.java @@ -0,0 +1,31 @@ +package br.unb.cic.analysis.samples.ioa; + +public class StringArraySample { + + protected static final String[] python2Keywords = { + "abs", "all", "any", "apply", "as", + "bin", "bool", "buffer", "bytearray", + "callable", "chr", "classmethod", "coerce", "compile", "complex", + "del", "delattr", "dict", "dir", "divmod", // LEFT + "enumerate", "eval", "execfile", + "file", "filter", "float", "format", "frozenset", + "getattr", "globals", + "hasattr", "hash", "help", "hex", + "id", "input", "int", "intern", "isinstance", "issubclass", "iter", + "len", "list", "locals", + "map", "max", "min", "next", + "memoryview", + "object", "oct", "open", "ord", + "pow", "print", "property", + "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", // RIGHT + "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", + "tuple", "type", + "unichr", "unicode", + "vars", + "with", + "xrange", + "zip", + "__import__", + "True", "False", "None" + }; +}