Commit a134b5fe authored by Lulu Luong's avatar Lulu Luong
Browse files

#45

parent dd86d9f3
Pipeline #31131 failed with stages
...@@ -11,7 +11,14 @@ import edu.kit.iti.formal.psdbg.interpreter.data.State; ...@@ -11,7 +11,14 @@ import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.dbg.PTreeNode; import edu.kit.iti.formal.psdbg.interpreter.dbg.PTreeNode;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor; import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
import javafx.beans.property.MapProperty;
import javafx.beans.property.SimpleMapProperty;
import javafx.collections.FXCollections;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.TextFieldTreeCell;
import javafx.util.StringConverter;
import lombok.Getter; import lombok.Getter;
import java.util.*; import java.util.*;
...@@ -36,8 +43,12 @@ public class ScriptTreeGraph { ...@@ -36,8 +43,12 @@ public class ScriptTreeGraph {
private List<PlaceholderNode> placeholderNodes; private List<PlaceholderNode> placeholderNodes;
private HashMap<Node, PTreeNode> foreachNodes; private HashMap<Node, PTreeNode> foreachNodes;
private final MutableGraph<AbstractTreeNode> graph =
GraphBuilder.directed().allowsSelfLoops(false).build(); /**
* Contains color of nodes
*/
private MapProperty<Node, String> colorOfNodes = new SimpleMapProperty<Node, String>(FXCollections.observableHashMap());
public void createGraph(PTreeNode<KeyData> rootPTreeNode, Node root) { public void createGraph(PTreeNode<KeyData> rootPTreeNode, Node root) {
...@@ -62,60 +73,10 @@ public class ScriptTreeGraph { ...@@ -62,60 +73,10 @@ public class ScriptTreeGraph {
computeList(); computeList();
compute(); compute();
addGoals(); addGoals();
// TODO: replace addParentsAndChildren() with placeholders;
mapping.size();
//TODO: remove following
System.out.print(front);
System.out.println(getMappingString(mapping.get(root)));
} }
/**
* creates the connection between parent and children in mapping, which haven't been set yet
*/
private void addParentsAndChildren() {
Node currentNode;
AbstractTreeNode currentTreenode;
Iterator<PTreeNode<KeyData>> iter = sortedList.listIterator(0);
//iterate through all ptreenodes in execution order
while (iter.hasNext()) {
PTreeNode<KeyData> next = iter.next();
if (next.getStateAfterStmt() != null) {
Map.Entry<Node, AbstractTreeNode> entry = getMappingEntry(next); //get entry in mapping
if (entry == null) {
continue;
}
currentTreenode = entry.getValue();
currentNode = entry.getKey();
//set parent
Node parent = currentNode.parent();
if(parent != null && currentTreenode != null) {
addToSubChildren(searchParentInMapping(parent), mapping.get(currentNode));
}
//set children
for (GoalNode<KeyData> gn: next.getStateAfterStmt().getGoals()) {
if(mapping.get(gn.getData().getNode()) != null && mapping.get(gn.getData().getNode()).getParent() != null)
mapping.get(gn.getData().getNode()).setParent(currentTreenode);
addToChildren(currentNode, mapping.get(gn.getData().getNode()));
}
}
}
}
/** /**
* Adds an AbstractTreeNode atn to the children in the mapping list with given key node * Adds an AbstractTreeNode atn to the children in the mapping list with given key node
...@@ -244,6 +205,7 @@ public class ScriptTreeGraph { ...@@ -244,6 +205,7 @@ public class ScriptTreeGraph {
if (children.size() != 0) { if (children.size() != 0) {
children.forEach(k -> treeItem.getChildren().add(rekursiveToView(k))); children.forEach(k -> treeItem.getChildren().add(rekursiveToView(k)));
} }
return treeItem; return treeItem;
} }
...@@ -308,7 +270,6 @@ public class ScriptTreeGraph { ...@@ -308,7 +270,6 @@ public class ScriptTreeGraph {
if(branchlabel.size() != 0) { if(branchlabel.size() != 0) {
System.out.println("_______Branchlabels");
Lists.reverse(branchlabel).forEach(k -> Lists.reverse(branchlabel).forEach(k ->
System.out.println(k.getNode().serialNr() + " " + k.getLabelName())); System.out.println(k.getNode().serialNr() + " " + k.getLabelName()));
...@@ -356,7 +317,6 @@ public class ScriptTreeGraph { ...@@ -356,7 +317,6 @@ public class ScriptTreeGraph {
replacePlaceholder(n, match); replacePlaceholder(n, match);
putIntoMapping(n, match); putIntoMapping(n, match);
addPlaceholder(match, n); addPlaceholder(match, n);
//front.remove(n);
return null; return null;
} }
...@@ -370,7 +330,6 @@ public class ScriptTreeGraph { ...@@ -370,7 +330,6 @@ public class ScriptTreeGraph {
replacePlaceholder(n, match); replacePlaceholder(n, match);
putIntoMapping(n, match); putIntoMapping(n, match);
addPlaceholder(match, n); addPlaceholder(match, n);
//front.remove(n);
return null; return null;
} }
...@@ -397,7 +356,6 @@ public class ScriptTreeGraph { ...@@ -397,7 +356,6 @@ public class ScriptTreeGraph {
: (nextPtreeNode.getStepOver() != null && nextPtreeNode.getStepOver().getStateBeforeStmt() != null) ? nextPtreeNode.getStepOver().getStateBeforeStmt().getGoals() : (nextPtreeNode.getStepOver() != null && nextPtreeNode.getStepOver().getStateBeforeStmt() != null) ? nextPtreeNode.getStepOver().getStateBeforeStmt().getGoals()
: new ArrayList<>(); : new ArrayList<>();
aftergoals.forEach(k -> foreachNodes.put(k.getData().getNode(), nextPtreeNode)); aftergoals.forEach(k -> foreachNodes.put(k.getData().getNode(), nextPtreeNode));
//
return null; return null;
} }
...@@ -522,7 +480,7 @@ public class ScriptTreeGraph { ...@@ -522,7 +480,7 @@ public class ScriptTreeGraph {
while (childnode.parent() != parentnode) { while (childnode.parent() != parentnode) {
if (childnode.parent().childrenCount() > 1) { if (childnode.parent().childrenCount() > 1) {
String calcBranchlabel = (childnode.getNodeInfo().getBranchLabel() == null)? String calcBranchlabel = (childnode.getNodeInfo().getBranchLabel() == null)?
"Case " + childnode.parent().getChildNr(childnode) + 1 "Case " + (childnode.parent().getChildNr(childnode) + 1)
: childnode.getNodeInfo().getBranchLabel(); : childnode.getNodeInfo().getBranchLabel();
branchlabels.add(new BranchLabelNode(childnode, calcBranchlabel)); branchlabels.add(new BranchLabelNode(childnode, calcBranchlabel));
} }
...@@ -617,25 +575,57 @@ public class ScriptTreeGraph { ...@@ -617,25 +575,57 @@ public class ScriptTreeGraph {
private void addGoals() { private void addGoals() {
front.forEach(k -> replacePlaceholder(k, new DummyGoalNode(k, k.isClosed()))); front.forEach(k -> replacePlaceholder(k, new DummyGoalNode(k, k.isClosed())));
}
private TreeCell<TreeNode> cellFactory(TreeView<TreeNode> nodeTreeView) {
TextFieldTreeCell<TreeNode> tftc = new TextFieldTreeCell<>();
StringConverter<TreeNode> stringConverter = new StringConverter<TreeNode>() {
@Override
public String toString(TreeNode object) {
return object.label;
}
@Override
public TreeNode fromString(String string) {
return null;
}
};
tftc.setConverter(stringConverter);
tftc.itemProperty().addListener((p, o, n) -> {
if (n != null)
repaint(tftc);
});
//colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
return tftc;
} }
private String getMappingString (AbstractTreeNode node){
String s = ""; private void repaint(TextFieldTreeCell<TreeNode> tftc) {
if (node != null) { TreeNode item = tftc.getItem();
s += node.toTreeNode().label + "\n"; Node n = item.node;
List<AbstractTreeNode> children = node.getChildren(); tftc.setStyle("");
if (children == null) return s; if (n != null) {
if (children.size() == 1) { if (n.leaf() && !item.label.contains("BRANCH")) {
s += getMappingString(children.get(0)); if (n.isClosed()) {
colorOfNodes.putIfAbsent(n, "lightseagreen");
//tftc.setStyle("-fx-background-color: greenyellow");
} else { } else {
s += " Children:\n"; colorOfNodes.putIfAbsent(n, "indianred");
for (AbstractTreeNode child : children) { }
s += " " + getMappingString(child); if (colorOfNodes.containsKey(n)) {
} tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";");
} }
} }
return s; //TODO for Screenshot tftc.setStyle("-fx-font-size: 18pt");
/* if (colorOfNodes.containsKey(n)) {
tftc.setStyle("-fx-border-color: "+colorOfNodes.get(n)+";");
}*/
} }
//expandRootToItem(tftc.getTreeItem());
}
} }
...@@ -3,6 +3,7 @@ package edu.kit.iti.formal.psdbg.gui.controls; ...@@ -3,6 +3,7 @@ package edu.kit.iti.formal.psdbg.gui.controls;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
import edu.kit.iti.formal.psdbg.gui.controller.DebuggerMain; import edu.kit.iti.formal.psdbg.gui.controller.DebuggerMain;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.AbstractTreeNode; import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.AbstractTreeNode;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.BranchLabelNode;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.DummyGoalNode; import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.DummyGoalNode;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.ScriptTreeNode; import edu.kit.iti.formal.psdbg.gui.controls.ScriptTree.ScriptTreeNode;
import javafx.beans.property.MapProperty; import javafx.beans.property.MapProperty;
...@@ -53,11 +54,11 @@ public class ScriptTreeView extends BorderPane { ...@@ -53,11 +54,11 @@ public class ScriptTreeView extends BorderPane {
} }
}; };
tftc.setConverter(stringConverter); tftc.setConverter(stringConverter);
/*
tftc.itemProperty().addListener((p, o, n) -> { tftc.itemProperty().addListener((p, o, n) -> {
if (n != null) if (n != null)
repaint(tftc); repaint(tftc);
}); */ });
//colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc)); //colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
return tftc; return tftc;
...@@ -132,10 +133,16 @@ public class ScriptTreeView extends BorderPane { ...@@ -132,10 +133,16 @@ public class ScriptTreeView extends BorderPane {
} else { } else {
colorOfNodes.putIfAbsent(n, "indianred"); colorOfNodes.putIfAbsent(n, "indianred");
} }
if(stg.getMapping().get(n) instanceof BranchLabelNode){
colorOfNodes.putIfAbsent(n, "gray");
}
if (colorOfNodes.containsKey(n)) { if (colorOfNodes.containsKey(n)) {
tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";"); tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";");
} }
} }
} }
} }
} }
Markdown is supported
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