Commit 0c8b2d36 authored by Henrik Niehaus's avatar Henrik Niehaus
Browse files

Merge branch 'master' into devel

parents e9abbae1 a6b945e8
......@@ -41,6 +41,10 @@ import de.unipaderborn.visuflow.model.VFNode;
import de.unipaderborn.visuflow.model.VFUnit;
import de.unipaderborn.visuflow.util.MapUtil;
import de.unipaderborn.visuflow.util.ServiceUtil;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.jimple.internal.JInstanceFieldRef;
public class NavigationHandler extends AbstractHandler {
......@@ -81,6 +85,16 @@ public class NavigationHandler extends AbstractHandler {
e.printStackTrace();
}
}
else if (event.getCommand().getId().equals("JimpleEditor.VariablePath"))
{
try {
List<VFNode> unitList = prepareVariablePath(className, document,
content.trim().substring(0, content.length() - 1), lineNumber);
ServiceUtil.getService(DataModel.class).filterGraph(unitList, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (BadLocationException e) {
e.printStackTrace();
......@@ -202,4 +216,70 @@ public class NavigationHandler extends AbstractHandler {
});
}
private List<VFNode> prepareVariablePath(String className, IDocument document, String content, int lineNumber){
DataModel dataModel = ServiceUtil.getService(DataModel.class);
List<VFNode> unitList = new ArrayList<VFNode>();
//Map<VFUnit,Value> map = new LinkedHashMap<VFUnit,Value>();
for (VFClass vfClass : dataModel.listClasses()) {
if (vfClass.getSootClass().getName().equals(className)) {
List<VFMethod> vfMethods = vfClass.getMethods();
Map<String, Integer> methodLines = getMethodLineNumbers(document, vfMethods);
Collection<Integer> allMethodLines = methodLines.values();
List<Integer> lesserThanCuurent = allMethodLines.stream().filter(x -> x.intValue() < lineNumber)
.collect(Collectors.toList());
int toBeCompared = lesserThanCuurent.get(lesserThanCuurent.size() - 1);
for (VFMethod method : vfMethods) {
int methodLine = methodLines.get(method.getSootMethod().getDeclaration());
if (toBeCompared == methodLine) {
unitList = createPointsToSet(method, content);
}
}
}
}
return unitList;
}
private List<VFNode> createPointsToSet(VFMethod method, String content){
List<VFNode> unitList = new ArrayList<VFNode>();
List<Value> valueList = new ArrayList<Value>();
for (VFUnit unit : method.getUnits()) {
Unit u = unit.getUnit();
for(ValueBox db : u.getDefBoxes()){
for(ValueBox ub : u.getUseBoxes()){
if(!valueList.contains(ub.getValue())){
valueList.remove(db.getValue());
}
}
}
if (unit.getUnit().toString().trim().equals(content)) {
for(ValueBox db : u.getDefBoxes()){
unitList.add(new VFNode(unit, 0));
valueList.add(db.getValue());
}
}
System.out.println(unit.getUnit());
for(ValueBox ub : u.getUseBoxes()){
if(valueList.contains(ub.getValue())){
if(u.getDefBoxes().isEmpty()){
unitList.add(new VFNode(unit, 0));
}
for(ValueBox db : u.getDefBoxes()){
if(db.getValue() instanceof JInstanceFieldRef){
JInstanceFieldRef jirf = (JInstanceFieldRef) db.getValue();
if(!jirf.getBase().equals(ub.getValue())){
unitList.add(new VFNode(unit, 0));
valueList.add(db.getValue());
}
}
else {
unitList.add(new VFNode(unit, 0));
valueList.add(db.getValue());
}
}
}
}
}
return unitList;
}
}
......@@ -11,6 +11,7 @@ public class VFMethod {
protected SootMethod wrapped;
private List<VFUnit> units = new ArrayList<>();
private List<VFMethodEdge> incomingEdges = new ArrayList<>();
private Body body;
private ControlFlowGraph controlFlowGraph;
private int id;
......@@ -70,5 +71,17 @@ public class VFMethod {
public String toString() {
return wrapped != null ? /*wrapped.getDeclaringClass().getName()+"."+*/ wrapped.getName() : super.toString();
}
public List<VFMethodEdge> getIncomingEdges() {
return incomingEdges;
}
public void setIncomingEdges(List<VFMethodEdge> incomingEdges) {
this.incomingEdges = incomingEdges;
}
public void addIncomingEdge(VFMethodEdge incomingEdge){
incomingEdges.add(incomingEdge);
}
}
......@@ -34,4 +34,8 @@ public class VFMethodEdge {
public void setDestMethod(VFMethod destMethod) {
this.destMethod = destMethod;
}
public String toString(){
return "Source: " + sourceMethod + " | Destination: " + destMethod;
}
}
package de.unipaderborn.visuflow.model.graph;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -29,6 +30,8 @@ public class JimpleModelAnalysis {
private int methodcount = 0;
private int edgeCount = 0;
private Map<SootMethod,VFMethod> methodMap = new HashMap<>();
private String[] sootString;
......@@ -56,7 +59,13 @@ public class JimpleModelAnalysis {
if(entryMethod.isMain())
{
methodcount++;
VFMethod vfmethod = new VFMethod(entryMethod);
VFMethod vfmethod;
if(methodMap.containsKey(entryMethod)){
vfmethod = methodMap.get(entryMethod);
}else{
vfmethod = new VFMethod(entryMethod);
methodMap.put(entryMethod, vfmethod);
}
methodGraph.listMethods.add(vfmethod);
break;
}
......@@ -76,7 +85,13 @@ public class JimpleModelAnalysis {
vfClasses.add(currentClass);
for (SootMethod sootMethod : sootClass.getMethods()) {
VFMethod currentMethod = new VFMethod(sootMethod);
VFMethod currentMethod;
if(methodMap.containsKey(sootMethod)){
currentMethod = methodMap.get(sootMethod);
}else{
currentMethod = new VFMethod(sootMethod);
methodMap.put(sootMethod, currentMethod);
}
currentMethod.setVfClass(currentClass);
Body body = sootMethod.retrieveActiveBody();
for (Unit unit : body.getUnits()) {
......@@ -136,7 +151,14 @@ public class JimpleModelAnalysis {
if(!methodPresent)
{
methodcount++;
VFMethod method = new VFMethod(methodcount, destination);
VFMethod method;
if(methodMap.containsKey(destination)){
method = methodMap.get(destination);
method.setId(methodcount);
}else{
method = new VFMethod(methodcount,destination);
methodMap.put(destination, method);
}
methodGraph.listMethods.add(method);
}
VFMethod sourceMethod = null;
......@@ -156,6 +178,11 @@ public class JimpleModelAnalysis {
}
edgeCount++;
VFMethodEdge edge = new VFMethodEdge(edgeCount, sourceMethod, destinationMethod);
destinationMethod.addIncomingEdge(edge);
System.out.println("Method "+destinationMethod+" Edge "+edge);
if(destinationMethod.getIncomingEdges().isEmpty()){
System.out.println("adding didnt work");
}
methodGraph.listEdges.add(edge);
traverseMethods(destination, cg);
}
......
......@@ -26,6 +26,7 @@ import org.osgi.service.event.EventAdmin;
import de.unipaderborn.visuflow.model.DataModel;
import de.unipaderborn.visuflow.model.VFClass;
import de.unipaderborn.visuflow.model.VFMethod;
import de.unipaderborn.visuflow.model.VFMethodEdge;
import de.unipaderborn.visuflow.model.VFNode;
import de.unipaderborn.visuflow.model.VFUnit;
import de.unipaderborn.visuflow.model.graph.ICFGStructure;
......@@ -40,6 +41,7 @@ public class DataModelImpl implements DataModel {
private List<VFMethod> selectedClassMethods;
private List<VFUnit> selectedMethodUnits;
private List<VFMethodEdge> selectedMethodincEdges;
private EventAdmin eventAdmin;
......@@ -112,6 +114,7 @@ public class DataModelImpl implements DataModel {
this.selectedMethod = this.selectedClass.getMethods().get(0);
this.selectedClassMethods = this.selectedClass.getMethods();
this.populateUnits();
this.populateEdges();
this.setSelectedMethod(this.selectedClass.getMethods().get(0));
}
......@@ -119,6 +122,7 @@ public class DataModelImpl implements DataModel {
public void setSelectedMethod(VFMethod selectedMethod) {
this.selectedMethod = selectedMethod;
this.populateUnits();
this.populateEdges();
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("selectedMethod", selectedMethod);
// properties.put("selectedClassMethods", selectedClassMethods);
......@@ -145,6 +149,10 @@ public class DataModelImpl implements DataModel {
private void populateUnits() {
this.selectedMethodUnits = this.selectedMethod.getUnits();
}
private void populateEdges() {
this.selectedMethodincEdges = this.selectedMethod.getIncomingEdges();
}
public void setEventAdmin(EventAdmin eventAdmin) {
this.eventAdmin = eventAdmin;
......
......@@ -418,8 +418,7 @@ public class GraphManager implements Runnable, ViewerListener, EventHandler {
Object node = curr.getAttribute("nodeMethod");
if(node instanceof VFMethod)
{
VFMethod currentMethod = (VFMethod) node;
VFMethod selectedMethod = dataModel.getVFMethodByName(currentMethod.getSootMethod());
VFMethod selectedMethod = (VFMethod) node;
try {
if(selectedMethod.getControlFlowGraph() == null)
throw new Exception("CFG Null Exception");
......@@ -427,6 +426,10 @@ public class GraphManager implements Runnable, ViewerListener, EventHandler {
{
renderMethodCFG(selectedMethod.getControlFlowGraph());
dataModel.setSelectedMethod(selectedMethod);
List<VFMethodEdge> incEdges = selectedMethod.getIncomingEdges();
/*for(VFMethodEdge edge : incEdges){
System.out.println(edge);
}*/
}
} catch (Exception e1) {
e1.printStackTrace();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment