Commit df7f1fb3 authored by Benedikt Engeser's avatar Benedikt Engeser

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents 9a1d769c 4c26a9a1
......@@ -196,6 +196,7 @@ public class ConflictResolutionManager {
predecesor.getState(),
foundNode.getPredecessorTransition());
predecessorState.setSuccessor(oldState);
oldState.setPredecessor(predecessorState);
resultList.add(predecessorState);
oldState = predecessorState;
foundNode = predecesor;
......@@ -229,6 +230,7 @@ public class ConflictResolutionManager {
}
CupConflictState newConflictState = new CupConflictState(actualNode.getState(), oldDFSNode.getPredTransition());
newConflictState.setSuccessor(oldConflictState);
oldConflictState.setPredecessor(newConflictState);
resultList.add(newConflictState);
oldConflictState = newConflictState;
......
......@@ -7,11 +7,13 @@ public class CupConflictState {
private final lalr_state state;
private final lalr_transition transition;
private CupConflictState successor;
private CupConflictState predecessor;
public CupConflictState(lalr_state state, lalr_transition transition) {
this.state = state;
this.transition = transition;
this.successor = null;
this.predecessor = null;
}
public CupConflictState getSuccessor() {
......@@ -29,7 +31,13 @@ public class CupConflictState {
public lalr_transition getTransition() {
return transition;
}
public CupConflictState getPredecessor() {
return predecessor;
}
public void setPredecessor(CupConflictState predecessor) {
this.predecessor = predecessor;
}
}
......@@ -89,6 +89,7 @@ import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.widgets.ConflictStateTooltip;
public class CupConflictGraphView extends CupGraphBase implements
ICupParserLaLrChangeObserver, IZoomableWorkbenchPart,
......@@ -163,7 +164,7 @@ public class CupConflictGraphView extends CupGraphBase implements
graphViewer.setNodeStyle(ZestStyles.NODES_NO_ANIMATION);
graphViewer.setInput(nodeModel.getNodes());
attachTooltip(graphViewer);
attachTooltip(graphViewer, new ConflictStateTooltip(Display.getCurrent()));
// Setup search Result Label
......@@ -552,10 +553,11 @@ public class CupConflictGraphView extends CupGraphBase implements
setModelForDFSAfterState(stateHashMap.get(index));
}
static class ParserConflictNode extends CupGraphNode {
public static class ParserConflictNode extends CupGraphNode {
private List<ParserConflictNode> connections;
private boolean isNonTerm = false;
private String transitionSymbol;
private CupConflictState cState;
public ParserConflictNode(lalr_state state, int id, String name) {
super(state, id, name, "");
......@@ -597,6 +599,14 @@ public class CupConflictGraphView extends CupGraphBase implements
public void setTransitionSymbol(String transitionSymbol) {
this.transitionSymbol = transitionSymbol;
}
public CupConflictState getcState() {
return cState;
}
public void setcState(CupConflictState cState) {
this.cState = cState;
}
}
static class ParserConflictConnection {
......@@ -672,6 +682,7 @@ public class CupConflictGraphView extends CupGraphBase implements
.getState().index(), "State "
+ state.getState().index());
newNode.setDescription(state.getState().toString());
newNode.setcState(state);
if (oldCupConflictState != null) {
newNode.setIsNonTerm(oldCupConflictState.getTransition()
.on_symbol().is_non_term());
......
......@@ -16,12 +16,12 @@ import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphItem;
import de.in.tum.www2.cup.internal.lalr_state;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView.ParserConflictNode;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceNode;
import de.tum.in.www2.cupplugin.widgets.StateTooltip;
public class CupGraphBase extends FailableView {
public class CupGraphBase extends FailableView {
public static class CupGraphNode {
protected int id;
protected String name;
......@@ -47,35 +47,36 @@ public class CupGraphBase extends FailableView {
public void setDescription(String description) {
this.description = description;
}
public CupGraphNode(lalr_state state, int id, String name, String description) {
public CupGraphNode(lalr_state state, int id, String name,
String description) {
this.state = state;
this.id = id;
this.name = name;
this.description = "";
}
}
// TODO: hack!
public static GraphItem giAtPopup;
public static int xAtPopup = -1;
public static int yAtPopup = -1;
public CupGraphBase(Composite parent) {
super(parent);
}
protected <T> void attachTooltip(GraphViewer graphViewer) {
StateTooltip tooltip = new StateTooltip(graphViewer.getGraphControl().getDisplay());
protected <T> void attachTooltip(GraphViewer graphViewer,
StateTooltip tooltip) {
// TODO: HACK!
List<Method> wrapper = new ArrayList<Method>();
try {
Method m = Graph.class.getDeclaredMethod("getGraphItem", new Class[] { IFigure.class });
Method m = Graph.class.getDeclaredMethod("getGraphItem",
new Class[] { IFigure.class });
m.setAccessible(true);
wrapper.add(m);
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) {
} catch (NoSuchMethodException | SecurityException
| IllegalArgumentException e) {
e.printStackTrace();
}
......@@ -84,47 +85,52 @@ public class CupGraphBase extends FailableView {
public void mouseDown(MouseEvent e) {
tooltip.fix();
}
@Override
public void mouseUp(MouseEvent e) {
tooltip.unfix();
}
});
graphViewer.getGraphControl().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (tooltip.isFixed())
return;
Graph g = (Graph) graphViewer.getControl();
Point p = e.display.getCursorLocation();
IFigure figure = g.getFigureAt(e.x, e.y);
if (figure != null) {
GraphItem gi = null;
try {
gi = (GraphItem) wrapper.get(0).invoke(g, figure);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e1) {
e1.printStackTrace();
}
if (gi.getData() instanceof CupGraphNode) {
CupGraphNode node = (CupGraphNode) gi.getData();
Point target = new Point(p.x + 10, p.y + 10);
if (giAtPopup != gi || !tooltip.isVisible ()) {
tooltip.setLocation(target);
tooltip.show(node.getState());
giAtPopup = gi;
xAtPopup = e.x;
yAtPopup = e.y;
graphViewer.getGraphControl().addMouseMoveListener(
new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (tooltip.isFixed())
return;
Graph g = (Graph) graphViewer.getControl();
Point p = e.display.getCursorLocation();
IFigure figure = g.getFigureAt(e.x, e.y);
if (figure != null) {
GraphItem gi = null;
try {
gi = (GraphItem) wrapper.get(0).invoke(g,
figure);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException e1) {
e1.printStackTrace();
}
if (gi.getData() instanceof CupGraphNode) {
CupGraphNode node = (CupGraphNode) gi.getData();
Point target = new Point(p.x + 10, p.y + 10);
if (giAtPopup != gi || !tooltip.isVisible()) {
tooltip.setLocation(target);
tooltip.show(node);
giAtPopup = gi;
xAtPopup = e.x;
yAtPopup = e.y;
}
}
} else if (Math.abs(xAtPopup - e.x) > 15
&& Math.abs(yAtPopup - e.y) > 15) {
tooltip.hide();
}
}
} else if (Math.abs(xAtPopup-e.x) > 15 && Math.abs(yAtPopup-e.y) > 15) {
tooltip.hide();
}
}
});
});
}
......
......@@ -193,7 +193,7 @@ public class CupReduceGraphView extends CupGraphBase
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
attachTooltip(graphViewer);
attachTooltip(graphViewer, new StateTooltip(Display.getCurrent()));
graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {
......
package de.tum.in.www2.cupplugin.widgets;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.swt.widgets.Display;
import de.in.tum.www2.cup.CupConflictState;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.lalr_transition;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView.ParserConflictNode;
import de.tum.in.www2.cupplugin.views.CupGraphBase.CupGraphNode;
public class ConflictStateTooltip extends StateTooltip {
private CupConflictState cState;
public ConflictStateTooltip(Display display) {
super(display);
}
@Override
public void show(CupGraphNode node) {
if(!(node instanceof ParserConflictNode)) {
return;
}
ParserConflictNode cNode = (ParserConflictNode)node;
if (this.cState != cNode.getcState()) {
this.cState = cNode.getcState();
StringBuilder builder = new StringBuilder();
for (Enumeration e = this.cState.getState().items().all(); e.hasMoreElements(); ) {
builder.append(((lalr_item)e.nextElement()).toString().replace("(*)", "\u2022"));
builder.append("\n");
}
List<lalr_transition> goneTransitions = new LinkedList<lalr_transition>();
CupConflictState current = cState;
while(current.getPredecessor()!=null) {
current = current.getPredecessor();
goneTransitions.add(current.getTransition());
}
Collections.reverse(goneTransitions);
builder.append("Actual gone path:\n");
for(lalr_transition trans : goneTransitions) {
builder.append(trans.toString());
builder.append("\n");
}
setText(builder.toString());
}
show();
}
}
package de.tum.in.www2.cupplugin.widgets;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.swt.widgets.Display;
import de.in.tum.www2.cup.CupConflictState;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.lalr_transition;
import de.tum.in.www2.cupplugin.views.CupGraphBase.CupGraphNode;
public class StateTooltip extends TooltipBase {
private lalr_state state;
public StateTooltip(Display display) {
super(display);
}
public void show(lalr_state state) {
if (this.state != state) {
this.state = state;
public void show(CupGraphNode node) {
lalr_state nState = node.getState();
if (this.state != nState) {
this.state = nState;
StringBuilder builder = new StringBuilder();
for (Enumeration e = this.state.items().all(); e.hasMoreElements(); ) {
......@@ -28,6 +35,5 @@ public class StateTooltip extends TooltipBase {
}
show();
}
}
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