diff --git a/src/main/java/br/unb/cic/analysis/df/Collector.java b/src/main/java/br/unb/cic/analysis/df/Collector.java index aaf142c4..4e4ffaaf 100644 --- a/src/main/java/br/unb/cic/analysis/df/Collector.java +++ b/src/main/java/br/unb/cic/analysis/df/Collector.java @@ -1,8 +1,8 @@ package br.unb.cic.analysis.df; import br.unb.cic.analysis.model.Conflict; +import soot.jimple.InstanceFieldRef; import soot.jimple.StaticFieldRef; -import soot.jimple.internal.JInstanceFieldRef; import java.util.HashMap; import java.util.HashSet; @@ -11,7 +11,7 @@ class Collector { private Set conflicts; - private Set> instanceFieldDictionary; + private Set> instanceFieldDictionary; private Set> staticFieldDictionary; private static Collector instance; @@ -28,12 +28,12 @@ public static Collector instance() { return instance; } - public Set> getHashJInstanceField() { + public Set> getHashInstanceField() { return instanceFieldDictionary; } - public void addHashJInstanceField(HashMap hash) { - instanceFieldDictionary.add(hash) ; + public void addHashInstanceField(HashMap hash) { + instanceFieldDictionary.add(hash); } public Set> getHashStaticField() { diff --git a/src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java b/src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java index 9d4e8b1a..dfc8c0f3 100644 --- a/src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java +++ b/src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java @@ -2,10 +2,10 @@ import br.unb.cic.analysis.model.Statement; import soot.Local; +import soot.jimple.InstanceFieldRef; import soot.jimple.StaticFieldRef; -import soot.jimple.internal.JInstanceFieldRef; -import java.util.*; +import java.util.Objects; /** * Information wee keep while traversing @@ -14,7 +14,7 @@ public class DataFlowAbstraction { private Local local; - private JInstanceFieldRef localField; + private InstanceFieldRef localField; private StaticFieldRef localStaticRef; private Statement stmt; @@ -23,7 +23,7 @@ public DataFlowAbstraction(Local local, Statement stmt) { this.stmt = stmt; } - public DataFlowAbstraction(JInstanceFieldRef localField, Statement stmt) { + public DataFlowAbstraction(InstanceFieldRef localField, Statement stmt) { this.localField = localField; this.stmt = stmt; } @@ -41,9 +41,10 @@ public StaticFieldRef getLocalStaticRef() { return localStaticRef; } - public JInstanceFieldRef getFieldRef() { + public InstanceFieldRef getFieldRef() { return localField; } + public Statement getStmt() { return stmt; } diff --git a/src/main/java/br/unb/cic/analysis/df/OverridingAssignmentAnalysis.java b/src/main/java/br/unb/cic/analysis/df/OverridingAssignmentAnalysis.java index a4b78ae2..90e944b7 100644 --- a/src/main/java/br/unb/cic/analysis/df/OverridingAssignmentAnalysis.java +++ b/src/main/java/br/unb/cic/analysis/df/OverridingAssignmentAnalysis.java @@ -4,6 +4,7 @@ import br.unb.cic.analysis.model.Conflict; import br.unb.cic.analysis.model.Statement; import soot.*; +import soot.jimple.InstanceFieldRef; import soot.jimple.StaticFieldRef; import soot.jimple.internal.JArrayRef; import soot.jimple.internal.JInstanceFieldRef; @@ -210,13 +211,13 @@ private Value getArrayRefName(JArrayRef arrayRef) { } /* - * If it's a JInstanceField, returns your complete name from the hashMapJInstanceField + * If it's a InstanceField, returns your complete name from the hashMapInstanceField */ - private JInstanceFieldRef getFieldName(ValueBox valueBox){ - JInstanceFieldRef fieldValue = (JInstanceFieldRef) valueBox.getValue(); + private InstanceFieldRef getFieldName(ValueBox valueBox) { + InstanceFieldRef fieldValue = (InstanceFieldRef) valueBox.getValue(); if (fieldValue.toString().contains("$stack")) { String chainName = getFieldsChain(valueBox.getValue().toString()); //return the complete chain with the FieldRef - ((Local) fieldValue.getBase()).setName(chainName.replace("."+fieldValue.getField().toString(), "")); //remove the double FieldRef from jInstanceFieldValue + ((Local) fieldValue.getBase()).setName(chainName.replace("." + fieldValue.getField().toString(), "")); //remove the double FieldRef from jInstanceFieldValue } return fieldValue; } @@ -291,7 +292,7 @@ private String getArrayChain(ValueBox valueBox){ * InitialKey($stack8.a) -> nextKey ($stack8) -> nextKey ($stack3) -> object.b has no nextKey (STOP) -> Return object chain -> Return: object.b.a.a */ private String getFieldsChain(String nextKey){ - List> auxValuesHashMap = new ArrayList<>(); + List> auxValuesHashMap = new ArrayList<>(); auxValuesHashMap.addAll(getHashMapJInstanceField()); //If nextKey not contain $stack is because simple key @@ -299,7 +300,7 @@ private String getFieldsChain(String nextKey){ return nextKey; } - JInstanceFieldRef currentField = null; + InstanceFieldRef currentField = null; //The second position is the field called String currentUniqueKey = "<"+nextKey.split(".<")[1]; @@ -313,7 +314,7 @@ private String getFieldsChain(String nextKey){ Iterator iterator = auxValuesHashMap.iterator(); while (iterator.hasNext() && !isNextKey){ - HashMap auxMap = (HashMap) iterator.next(); + HashMap auxMap = (HashMap) iterator.next(); for (String mapKey : auxMap.keySet()) { if (mapKey.equals(nextKey)) { currentField = auxMap.get(mapKey); @@ -339,13 +340,13 @@ private String getFieldsChain(String nextKey){ /* - * Generates the dictionary with the UseBoxes instances of JInstanceFieldRef or StaticFieldRef + * Generates the dictionary with the UseBoxes instances of InstanceFieldRef or StaticFieldRef */ public void generateFieldDictionary(Unit u){ for (ValueBox valueBox: u.getUseBoxes()) { - if (valueBox.getValue() instanceof JInstanceFieldRef) { + if (valueBox.getValue() instanceof InstanceFieldRef) { generateClassFieldDictionary(getStatementAssociatedWithUnit(u)); - }else if (valueBox.getValue() instanceof StaticFieldRef) { + } else if (valueBox.getValue() instanceof StaticFieldRef) { generateStaticRefDictionary(u, valueBox); } } @@ -368,20 +369,20 @@ private void generateStaticRefDictionary(Unit u, ValueBox valueBox){ * Generates a dictionary to JInstanceFieldRef */ private void generateClassFieldDictionary(Statement stmt){ - HashMap auxHashMap = new HashMap<>(); + HashMap auxHashMap = new HashMap<>(); StringBuilder strKey = new StringBuilder(); for (ValueBox valueBoxKey : stmt.getUnit().getDefBoxes()) { strKey.append(valueBoxKey.getValue().toString()); } - JInstanceFieldRef currentFieldRef = null; + InstanceFieldRef currentFieldRef = null; for (ValueBox catchRef : stmt.getUnit().getUseBoxes()) { - if (catchRef.getValue() instanceof JInstanceFieldRef) { - currentFieldRef = (JInstanceFieldRef) catchRef.getValue(); + if (catchRef.getValue() instanceof InstanceFieldRef) { + currentFieldRef = (InstanceFieldRef) catchRef.getValue(); auxHashMap.put(strKey.toString(), currentFieldRef); } } if (auxHashMap.size() != 0) { - Collector.instance().addHashJInstanceField(auxHashMap); + Collector.instance().addHashInstanceField(auxHashMap); } } } \ No newline at end of file diff --git a/src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java b/src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java index cc459849..105cfb75 100644 --- a/src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java +++ b/src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java @@ -1,15 +1,14 @@ package br.unb.cic.analysis.df; -import java.util.*; -import java.util.stream.Collectors; - import br.unb.cic.analysis.AbstractAnalysis; +import br.unb.cic.analysis.AbstractMergeConflictDefinition; import br.unb.cic.analysis.model.Conflict; import br.unb.cic.analysis.model.Statement; import soot.Body; import soot.Local; import soot.Unit; import soot.ValueBox; +import soot.jimple.InstanceFieldRef; import soot.jimple.StaticFieldRef; import soot.jimple.internal.JArrayRef; import soot.jimple.internal.JInstanceFieldRef; @@ -18,7 +17,8 @@ import soot.toolkits.scalar.FlowSet; import soot.toolkits.scalar.ForwardFlowAnalysis; -import br.unb.cic.analysis.AbstractMergeConflictDefinition; +import java.util.*; +import java.util.stream.Collectors; /** * Intraprocedural dataflow analysis for identifying @@ -176,28 +176,28 @@ protected boolean isSourceStatement(Unit d) { protected boolean isSinkStatement(Unit d) { return definition.getSinkStatements().stream().map(s -> s.getUnit()).collect(Collectors.toList()).contains(d); - } + } - public void clear() { - Collector.instance().clear(); - } + public void clear() { + Collector.instance().clear(); + } - public Set getConflicts() { - return Collector.instance().getConflicts(); - } + public Set getConflicts() { + return Collector.instance().getConflicts(); + } - public Set> getHashMapJInstanceField() { - return Collector.instance().getHashJInstanceField(); - } + public Set> getHashMapJInstanceField() { + return Collector.instance().getHashInstanceField(); + } - public Set> getHashMapStatic() { - return Collector.instance().getHashStaticField(); - } + public Set> getHashMapStatic() { + return Collector.instance().getHashStaticField(); + } - protected List getUseVariables(Unit u) { - return u.getUseBoxes().stream() - .map(box -> box.getValue()) - .filter(v -> v instanceof Local) + protected List getUseVariables(Unit u) { + return u.getUseBoxes().stream() + .map(box -> box.getValue()) + .filter(v -> v instanceof Local) .map(v -> (Local)v) .collect(Collectors.toList()); }