Commit d8a6bc48 authored by Johannes Roith's avatar Johannes Roith

Integrate resolution hints.

parent 7c7ee465
......@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -19,23 +18,22 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.ConflictType;
import de.in.tum.www2.cup.CupConflictState;
import de.in.tum.www2.cup.ConflictResolutionManager;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.internal.internal_error;
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.terminal;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.PluginUtility;
import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
......@@ -60,14 +58,16 @@ public class CupConflictsView implements ICupEditorPageVisibility,
private static final int COLUMNS = 3;
private static final int HEADING_FONT_SIZE = 14;
private static final int SIZE_INCREASE_PER_LINE = 8;
private Conflict conflict;
private Label conflictTypeLabel;
private Link stateLabel;
private Label symbolLabel;
private Link detailText;
private Label resolutionHint;
private List<Range> links = new ArrayList<Range>();
private Color backgroundColorReduce;
......@@ -75,6 +75,8 @@ public class CupConflictsView implements ICupEditorPageVisibility,
private Color backgroundColorShift;
private Color foregroundColorShift;
GridData gridData;
public ConflictPanel(Composite parent, int style) {
super(parent, style);
......@@ -83,11 +85,11 @@ public class CupConflictsView implements ICupEditorPageVisibility,
backgroundColorShift = new Color(Display.getCurrent(), Colors.conflictBgYellow);
foregroundColorShift = new Color(Display.getCurrent(), Colors.conflictFgYellow);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.grabExcessHorizontalSpace = true;
data.widthHint = 100; // Do not remove. This is a bugfix. :-)
data.heightHint = 80;
setLayoutData(data);
gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.grabExcessHorizontalSpace = true;
gridData.widthHint = 100; // Do not remove. This is a bugfix. :-)
gridData.heightHint = 80;
setLayoutData(gridData);
GridLayout gl = new GridLayout();
gl.numColumns = COLUMNS;
......@@ -99,7 +101,7 @@ public class CupConflictsView implements ICupEditorPageVisibility,
fD[0].setHeight(HEADING_FONT_SIZE);
conflictTypeLabel.setFont( new Font(Display.getCurrent(),fD[0]));
this.symbolLabel = new Label(this, SWT.NONE);
this.symbolLabel = new Label(this, SWT.NONE);
this.stateLabel = new Link(this, SWT.NONE);
GridData td2 = new GridData(GridData.HORIZONTAL_ALIGN_END);
......@@ -128,6 +130,8 @@ public class CupConflictsView implements ICupEditorPageVisibility,
System.out.println(e.text);
}
});
this.resolutionHint = new Label(this, SWT.NONE);
}
private Composite makeDetailWrapper(int columns) {
......@@ -160,13 +164,38 @@ public class CupConflictsView implements ICupEditorPageVisibility,
detailText.setBackground(background);
}
public void update(Conflict conflict) {
private Pair<String,Integer> makeConflictResolutionHint(ConflictResolutionManager crm, lalr_state state) {
List<CupConflictState> resultList = crm.searchForState(state);
StringBuilder builder = new StringBuilder();
int count = 0;
if (resultList != null) {
for (CupConflictState n : resultList) {
if (n.getSuccessor() != null) {
builder.append("From: State ");
builder.append(n.getState().index());
builder.append(" to: State ");
builder.append(n.getSuccessor().getState().index());
builder.append(" with Transition: ");
builder.append(n.getTransition().on_symbol().toString() + "\n");
count++;
}
}
}
return new Pair<String,Integer>(builder.toString(), count);
}
public void update(ConflictResolutionManager crm, Conflict conflict) {
this.conflict = conflict;
links.clear();
int linkCounter = 0;
int cindex = conflict.getState().index();
lalr_state state = conflict.getState();
Pair<String,Integer> hint = makeConflictResolutionHint(crm, state);
resolutionHint.setText(hint.getFirst());
gridData.heightHint += hint.getSecond() * SIZE_INCREASE_PER_LINE;
int cindex = state.index();
stateLabel.setText("<a href=\"" + cindex + "\">State: " + cindex + "</a>");
if (conflict instanceof ReduceReduceConflict) {
......@@ -311,13 +340,14 @@ public class CupConflictsView implements ICupEditorPageVisibility,
refreshScrolledLayout();
}
private void updateConflicts(List<Conflict> conflicts) {
private void updateConflicts(ConflictResolutionManager crm) {
List<Conflict> conflicts = crm.getAllConflicts();
int size = conflicts.size();
matchPanelNumber(size);
for (int i = 0; i < size; i++) {
Conflict conflict = conflicts.get(i);
ConflictPanel panel = conflictPanels.get(i);
panel.update(conflict);
panel.update(crm, conflict);
}
refreshScrolledLayout();
}
......@@ -352,8 +382,8 @@ public class CupConflictsView implements ICupEditorPageVisibility,
Model model = Model.getInstanceForDocument(editor.getDocument());
LALRResult result = model.getLaLrResult();
if (result != null) {
ConflictManager cm = result.getContext().getConflictManager();
updateConflicts(cm.getConflicts());
ConflictResolutionManager crm = new ConflictResolutionManager(result.getContext());
updateConflicts(crm);
}
}
}
......@@ -375,8 +405,8 @@ public class CupConflictsView implements ICupEditorPageVisibility,
public void modelChanged(Model model) {
LALRResult result = model.getLaLrResult();
if (result != null) {
ConflictManager cm = result.getContext().getConflictManager();
updateConflicts(cm.getConflicts());
ConflictResolutionManager crm = new ConflictResolutionManager(result.getContext());
updateConflicts(crm);
} else {
matchPanelNumber(0);
}
......
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