Commit b170f2b5 authored by Johannes Roith's avatar Johannes Roith

Mixed changes.

parent 8e4b63d8
......@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0",
org.eclipse.text
org.eclipse.text,
org.eclipse.ui.forms;bundle-version="3.6.100"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
......@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
......@@ -18,13 +19,9 @@ public class Activator extends AbstractUIPlugin {
public class DebugListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("GOT EVENT: " + event.getType());
Debugger.getBreakpointMapper().remap();
if (event.getType() != IResourceChangeEvent.POST_BUILD)
return;
System.out.println("GOT POST BUILD EVENT!");
Debugger.getBreakpointMapper().remap();
}
}
......@@ -39,7 +36,8 @@ public class Activator extends AbstractUIPlugin {
*/
public Activator() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(new DebugListener());
workspace.addResourceChangeListener(new DebugListener(),
IResourceChangeEvent.POST_BUILD);
}
/*
......
package de.tum.in.www2.cupplugin;
import org.eclipse.swt.graphics.RGB;
public class Colors {
public static final RGB white = new RGB (255, 255, 255);
public static final RGB darkGray = new RGB (20, 20, 20);
// public static final RGB darkGray = new RGB (30, 30, 30);
public static final RGB gray = new RGB (150, 150, 150);
public static final RGB blue = new RGB (53, 87, 197);
public static final RGB brightBlue = new RGB (38, 99, 236);
public static final RGB green = new RGB (44, 173, 57);
public static final RGB orange = new RGB (220, 150, 50);
public static final RGB purple = new RGB (177, 33, 114);
public static final RGB blueGreen = new RGB (43, 126, 136);
public static final RGB red = new RGB (255, 0, 0);
public static final RGB pink = new RGB (255, 0, 255);
public static final RGB brown = new RGB (132, 90, 49);
/*
public static final RGB stateGreen = new RGB (155, 218, 158);
public static final RGB stateBlue = new RGB (155, 208, 128);
public static final RGB stateRed = new RGB (218, 155, 173);
public static final RGB stateYellow = new RGB (218, 214, 155);
*/
//public static final RGB stateGreen = new RGB (196, 232, 197);
public static final RGB stateGreen = new RGB (146, 203, 135);
public static final RGB stateBlue = new RGB (196, 232, 230);
public static final RGB stateRed = new RGB (232, 196, 196);
public static final RGB stateYellow = new RGB (218, 214, 155);
public static final RGB stateBrightYellow = new RGB (241, 237, 122);
}
......@@ -74,13 +74,15 @@ public class GeneratedFileLocator {
// if (candidates.size() == 0)
// System.out.println("Found no candidates!");
for (IFile candidate : candidates) {
System.out.println("candidate: " + candidate.getName());
// System.out.println("candidate: " + candidate.getName());
if (currentTargetFile.containsKey(fullPath)) {
// TODO: check if better than candidate.
// e.g. if package matches
}
currentTargetFile.put(fullPath, candidate);
}
if (!currentTargetFile.containsKey(fullPath))
return null;
return currentTargetFile.get(fullPath);
}
......
......@@ -23,7 +23,7 @@ public class OpenDeclarationHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO: this has been copied from the DefinitionHandler, exception
// TODO: this has been copied from the DefinitionHandler, except
// that IHasDefinitionReference -> IHasDeclarationReference
// an getDefinition() -> getDeclaration()
......
......@@ -66,6 +66,7 @@ public class RenameSymbolHandler extends AbstractHandler {
int offset = node.getBegin().getOffsetFromStart();
try {
doc.replace(offset, oldNameLength, newName);
withName.getName().name = newName;
} catch (BadLocationException e) {
e.printStackTrace();
}
......
......@@ -2,21 +2,16 @@ package de.tum.in.www2.cupplugin.controller;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.internal.core.util.WeakHashSet;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.ui.texteditor.IDocumentProvider;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.debug.Debugger;
import de.tum.in.www2.cupplugin.editors.CupPartionScanner;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
......@@ -29,37 +24,28 @@ public class Controller {
doNothing, parseCode, buildTable
};
// The Job handling changes in a document is triggered after x seconds
static final int SET_CHANGED_AFTER_SECONDS = 1;
private static final int SET_CHANGED_AFTER_SECONDS = 1;
// TODO: we need to remove the editor from the list, when it gets disposed.
// Static reference to the controller instance per document
static WeakHashMap<CupTextEditor, Controller> instances = new WeakHashMap<CupTextEditor, Controller>();
static CupTextEditor AnonymousEditor = null;
// attributes
private static WeakHashMap<CupTextEditor, Controller> instances = new WeakHashMap<CupTextEditor, Controller>();
// The Job that's executed after a document change is detected (changeJob)
private DocumentDidChangeJob myJob = null;
// the document, the instance is managing
private CupTextEditor myEditor = null;
// if the changeJob takes some time, it's good to know if it has to be
// reexecuted after it finishes
private long changeJobReRunRequested = 0;
// a lock, since some operations might not be threadsafe
private final Object lock = new Object();
private final Object lock = new Object();
private CupTextEditor editor = null;
private List<DocumentEvent> documentEvents;
private final EnumSet<JobsToDo> jobElements = EnumSet
.noneOf(JobsToDo.class);
private long currentRevisionNumber = 0;
private Set<IRegisterForControllerChanges> controllerObservers = Collections.newSetFromMap(
new WeakHashMap<IRegisterForControllerChanges, Boolean>());
/*
* Static singleton getter
*/
public static Controller getInstance(CupTextEditor edit) {
Controller instance = instances.get(edit);
if (instance != null) {
......@@ -70,38 +56,17 @@ public class Controller {
}
}
public static Controller getInstance(IDocument doc) {
for (Map.Entry<CupTextEditor, Controller> e : instances.entrySet()) {
CupTextEditor editor = e.getKey();
if (editor != null) {
IDocumentProvider provider = editor.getDocumentProvider();
if (provider != null) {
IDocument doc2 = provider.getDocument(editor
.getEditorInput());
if (doc2.equals(doc))
return e.getValue();
}
}
}
// this is hacky, but it shouldn't happen anyways...
return getInstance(AnonymousEditor);
}
/*
* The Constructor, taking the editor it's controlling as a parameter
*/
public Controller(CupTextEditor editor) {
myEditor = editor;
private Controller(CupTextEditor editor) {
this.editor = editor;
myJob = new DocumentDidChangeJob(editor);
myJob.setSystem(true);
documentEvents = new LinkedList<DocumentEvent>();
Debugger.getInstance(myEditor.getDocument()); // TODO: why is this here?
Debugger.getInstance(editor.getDocument()); // TODO: why is this here?
}
public void addDocumentEvent(DocumentEvent e) {
synchronized (documentEvents) {
this.documentEvents.add(e);
private void addJobToDo(JobsToDo job) {
synchronized (jobElements) {
jobElements.add(job);
}
}
......@@ -113,15 +78,9 @@ public class Controller {
}
}
public void addJobToDo(JobsToDo job) {
synchronized (jobElements) {
jobElements.add(job);
}
}
public void removeJobToDo(JobsToDo job) {
synchronized (jobElements) {
jobElements.remove(job);
public void addDocumentEvent(DocumentEvent e) {
synchronized (documentEvents) {
this.documentEvents.add(e);
}
}
......@@ -160,10 +119,9 @@ public class Controller {
addDocumentEvent(event);
IDocument document = myEditor.getDocumentProvider().getDocument(
myEditor.getEditorInput());
IDocument document = editor.getDocument();
currentRevisionNumber = RevisionManager.increment(document);
RevisionManager.increment(document);
EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class);
synchronized (controllerObservers) {
......@@ -272,14 +230,12 @@ public class Controller {
* @return if the job will ever run
*/
public boolean requestJobRun() {
IDocument document = myEditor.getDocumentProvider().getDocument(
myEditor.getEditorInput());
IDocument document = editor.getDocument();
EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class);
synchronized (controllerObservers) {
for (IRegisterForControllerChanges observer : controllerObservers) {
for (IRegisterForControllerChanges observer : controllerObservers)
observedJobs.addAll(observer.getRequiredJobs());
}
}
for (JobsToDo job : observedJobs) {
......@@ -287,9 +243,8 @@ public class Controller {
case parseCode:
long modelAstRev = Model.getInstanceForDocument(document)
.getAstModelRevisionNumber();
if (modelAstRev != RevisionManager.get(document)) {
if (modelAstRev != RevisionManager.get(document))
addJobToDo(job);
}
break;
case buildTable:
long modelLaLrRev = Model.getInstanceForDocument(document)
......@@ -318,17 +273,14 @@ public class Controller {
*/
public void notifyChangeJobFinished() {
synchronized (lock) {
System.out.println("job finished -> " + changeJobReRunRequested); // Log
// message
// TODO:
// DELETE!
System.out.println("job finished -> " + changeJobReRunRequested);
if (changeJobReRunRequested > 0) {
changeJobReRunRequested = 0;
// TODO: why is this only multiplied by 100 here, but 1000 above ???
long remainderOfDelay = (SET_CHANGED_AFTER_SECONDS * 100)
- (System.currentTimeMillis() - changeJobReRunRequested);
myJob.revNumber = RevisionManager.get(myEditor
.getDocumentProvider().getDocument(
myEditor.getEditorInput()));
myJob.revNumber = RevisionManager.get(editor.getDocument());
myJob.schedule((remainderOfDelay >= 0) ? remainderOfDelay : 0);
}
}
......
......@@ -78,7 +78,7 @@ public class DocumentDidChangeJob extends Job {
return Status.CANCEL_STATUS;
}
// TODO: can we really works with the document just like that
// TODO: can we really work with the document just like that
// on this thread? What about changes that are happening
// to the document? We should probably copy the document
// data first or something !!!
......@@ -150,14 +150,7 @@ public class DocumentDidChangeJob extends Job {
} else {
System.out.println("LALRResult.Compute was not called, "
+ "because the parser has reported errors.");
if (parser == null) {
System.out.println("Null parser");
} else {
System.out.println("Parser has Errors: "
+ parser.hasParseErrors());
}
}
} catch (internal_error e) {
e.printStackTrace();
}
......@@ -194,24 +187,24 @@ public class DocumentDidChangeJob extends Job {
}
static class CallbackJob extends UIJob {
CupTextEditor myEditor = null;
private CupTextEditor editor = null;
public CallbackJob(CupTextEditor editor) {
super("" + editor.hashCode());
myEditor = editor;
this.editor = editor;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Controller.getInstance(myEditor).notifyChangeJobFinished();
Controller.getInstance(editor).notifyChangeJobFinished();
return Status.OK_STATUS;
}
}
class ParserResultJob extends UIJob {
ParserResult parserResult;
long parserModelRevisionNumber;
private ParserResult parserResult;
private long parserModelRevisionNumber;
public ParserResultJob(ParserResult result, long revisionNumber) {
super("Parser Result UI Job");
......@@ -238,18 +231,16 @@ public class DocumentDidChangeJob extends Job {
}
class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob;
public SetupJob(DocumentDidChangeJob documentDidChangeJob) {
super("Parswer Setup Job");
super("Parser Setup Job");
this.documentDidChangeJob = documentDidChangeJob;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Controller controller = Controller.getInstance(myEditor);
if (documentDidChangeJob.documentEvents == null
......@@ -270,19 +261,11 @@ public class DocumentDidChangeJob extends Job {
if (myEditor == null)
return Status.CANCEL_STATUS;
IDocumentProvider provider = documentDidChangeJob.myEditor
.getDocumentProvider();
IDocument document = myEditor.getDocument();
if (provider == null)
if (revNumber != RevisionManager.get(document))
return Status.CANCEL_STATUS;
IDocument document = provider
.getDocument(myEditor.getEditorInput());
if (revNumber != RevisionManager.get(document)) {
return Status.CANCEL_STATUS;
}
documentDidChangeJob.codeText = document.get();
return Status.OK_STATUS;
......
......@@ -177,6 +177,7 @@ public class BreakpointMapper {
}
public void remap() {
System.err.println("DEBUGGER: remap called.");
removeAll();
addAll();
}
......
......@@ -13,7 +13,10 @@ import de.tum.in.www2.cupplugin.model.Model;
class CupDocumentListener implements IDocumentListener {
public CupDocumentListener() {
private CupTextEditor editor;
public CupDocumentListener(CupTextEditor editor) {
this.editor = editor;
}
private int linesRemoved = 0;
......@@ -102,7 +105,7 @@ class CupDocumentListener implements IDocumentListener {
public void documentChanged(DocumentEvent event) {
patchModel(event);
Controller controller = Controller.getInstance(event.getDocument());
Controller controller = Controller.getInstance(editor);
controller.notifyChange(event);
}
......
......@@ -35,23 +35,24 @@ import de.tum.in.www2.cupplugin.model.Model;
public class CupTextEditor extends TextEditor
implements ICupParserASTChangeObserver, IRegisterForControllerChanges
{
public static HashSet<IDocument> hasOpened = new HashSet<IDocument>();
private static HashSet<IDocument> hasOpened = new HashSet<IDocument>();
IVerticalRulerInfo ruler = null;
private IVerticalRulerInfo ruler = null;
private Jumper jumper;
private CupContentOutlinePage outlinePage;
private Position lastPosition;
private boolean hasRequestedPostSaveSyntaxRefresh;
static Color gray;
static Color blue;
static Color brightBlue;
static Color green;
static Color orange;
static Color purple;
static Color blueGreen;
static Color red;
static Color pink;
static Color brown;
private static Color gray;
private static Color blue;
private static Color brightBlue;
private static Color green;
private static Color orange;
private static Color purple;
private static Color blueGreen;
private static Color red;
private static Color pink;
private static Color brown;
static {
Display display = Display.getCurrent();
......@@ -82,8 +83,9 @@ public class CupTextEditor extends TextEditor
public static final Color JAVA_TEXTUAL = brightBlue;
public static final Color JAVA_CUP_DEFINED = blueGreen;
public CupTextEditor() {
public CupTextEditor(Jumper jumper) {
super();
this.jumper = jumper;
setSourceViewerConfiguration(new CupSourceViewerConfiguration(this));
}
......@@ -92,7 +94,7 @@ public class CupTextEditor extends TextEditor
getModel().registerModelObserver(this);
Controller.getInstance(this).registerObserver(this);
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
return EnumSet.of(JobsToDo.parseCode);
......
package de.tum.in.www2.cupplugin.editors;
public class Jumper {
private MultiPageEditor mpe;
Jumper (MultiPageEditor mpe) {
this.mpe = mpe;
}
}
package de.tum.in.www2.cupplugin.editors;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
......@@ -11,7 +10,6 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
......@@ -19,10 +17,7 @@ import org.eclipse.ui.*;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
......@@ -30,6 +25,7 @@ import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.debug.Debugger;
import de.tum.in.www2.cupplugin.views.CupActionTableView;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView;
import de.tum.in.www2.cupplugin.views.CupConflictsView;
import de.tum.in.www2.cupplugin.views.CupOverviewView;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView;
import de.tum.in.www2.cupplugin.views.CupReduceTableView;
......@@ -38,22 +34,23 @@ public class MultiPageEditor extends MultiPageEditorPart implements
IResourceChangeListener {
private CupTextEditor editor;
private CupReduceGraphView graphReduceView;
// Zoom for the GraphView
private ZoomContributionViewItem graphReduceZoomContribution;
private IMenuManager graphReduceMenu;
private CupOverviewView overviewView;
private CupConflictsView conflictsView;
private CupActionTableView actionTableView;
private CupReduceTableView reduceTableView;
private CupConflictGraphView conflictGraphView;
private CupReduceGraphView graphReduceView;
private final int OVERVIEW_PAGE_INDEX = 0;
private final int EDITOR_PAGE_INDEX = 1;
private final int GRAPH_PAGE_INDEX = 2;
private final int ACTION_TABLE_PAGE_INDEX = 3;
private final int REDUCE_TABLE_PAGE_INDEX = 4;
private final int CONFLICT_GRAPH_PAGE_INDEX = 5;
private final int CONFLICTS_PAGE_INDEX = 2;
private final int GRAPH_PAGE_INDEX = 3;
private final int ACTION_TABLE_PAGE_INDEX = 4;
private final int REDUCE_TABLE_PAGE_INDEX = 5;
private final int CONFLICT_GRAPH_PAGE_INDEX = 6;
private int previousPageIndex = EDITOR_PAGE_INDEX;
......@@ -66,9 +63,9 @@ public class MultiPageEditor extends MultiPageEditorPart implements
return editor;
}
void createEditorPage() {
void createEditorPage(Jumper jumper) {
try {
editor = new CupTextEditor();
editor = new CupTextEditor(jumper);
int index = addPage(editor, getEditorInput());
setPageText(index, "Grammar");
setTitle(editor.getTitle());
......@@ -80,7 +77,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
// we need to call init _after_ the editor has a document.
editor.init();
Controller controller = Controller.getInstance(doc);
Controller controller = Controller.getInstance(editor);
controller.initialRun();
} catch (PartInitException e) {
......@@ -89,63 +86,73 @@ public class MultiPageEditor extends MultiPageEditorPart implements
}
}
void createGraphPage() {
void createGraphPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
graphReduceView = new CupReduceGraphView(composite, getEditor());
graphReduceView = new CupReduceGraphView(composite, jumper, getEditor());
int index = addPage(composite);
setPageText(index, "Automaton View (costly)");
}
void createOverviewPage() {
void createOverviewPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
overviewView = new CupOverviewView(composite, doc);
IDocument doc = editor.getDocument();
overviewView = new CupOverviewView(composite, jumper, doc, editor.getTitle());
addPage(OVERVIEW_PAGE_INDEX, composite);
setPageText(OVERVIEW_PAGE_INDEX, "Overview");
}
void createActionTablePage() {
void createConflictsPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
actionTableView = new CupActionTableView(composite, editor);
IDocument doc = editor.getDocument();
conflictsView = new CupConflictsView(composite, jumper, doc);
addPage(CONFLICTS_PAGE_INDEX, composite);
setPageText(CONFLICTS_PAGE_INDEX, "Conflicts");
}
void createActionTablePage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocument();
actionTableView = new CupActionTableView(composite, jumper, editor);
addPage(ACTION_TABLE_PAGE_INDEX, composite);
setPageText(ACTION_TABLE_PAGE_INDEX, "Action Table");
}
void createReduceTablePage() {
void createReduceTablePage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
reduceTableView = new CupReduceTableView(composite, doc);
IDocument doc = editor.getDocument();
reduceTableView = new CupReduceTableView(composite, jumper, doc);
addPage(REDUCE_TABLE_PAGE_INDEX, composite);
setPageText(REDUCE_TABLE_PAGE_INDEX, "Reduce Table");
}
void createConflictGraphPage() {
void createConflictGraphPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
conflictGraphView = new CupConflictGraphView(composite, editor);
IDocument doc = editor.getDocument();
conflictGraphView = new CupConflictGraphView(composite, jumper, editor);
addPage(CONFLICT_GRAPH_PAGE_INDEX, composite);
setPageText(CONFLICT_GRAPH_PAGE_INDEX, "Conflict Graph");
}
protected void createPages() {
createEditorPage();
createOverviewPage();
createGraphPage();
createActionTablePage();
createReduceTablePage();
createConflictGraphPage();
Jumper jumper = new Jumper(this);
createEditorPage(jumper);
createOverviewPage(jumper);
createConflictsPage(jumper);
createGraphPage(jumper);
createActionTablePage(jumper);
createReduceTablePage(jumper);
createConflictGraphPage(jumper);
setActivePage(previousPageIndex);
}
@Override
public void dispose() {
overviewView.dispose();
conflictsView.dispose();
actionTableView.dispose();
reduceTableView.dispose();
conflictGraphView.dispose();
graphReduceView.dispose();
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
super.dispose();
}
......@@ -188,6 +195,9 @@ public class MultiPageEditor extends MultiPageEditorPart implements
case OVERVIEW_PAGE_INDEX:
overviewView.becameHidden();
break;
case CONFLICTS_PAGE_INDEX:
conflictsView.becameHidden();