Commit b170f2b5 authored by Johannes Roith's avatar Johannes Roith

Mixed changes.

parent 8e4b63d8
...@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.ui, ...@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.core;bundle-version="3.10.0", org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1", org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0", 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-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-ClassPath: . Bundle-ClassPath: .
...@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin; ...@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin;
import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin;
...@@ -18,13 +19,9 @@ public class Activator extends AbstractUIPlugin { ...@@ -18,13 +19,9 @@ public class Activator extends AbstractUIPlugin {
public class DebugListener implements IResourceChangeListener { public class DebugListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) { public void resourceChanged(IResourceChangeEvent event) {
System.out.println("GOT EVENT: " + event.getType());
Debugger.getBreakpointMapper().remap();
if (event.getType() != IResourceChangeEvent.POST_BUILD) if (event.getType() != IResourceChangeEvent.POST_BUILD)
return; return;
System.out.println("GOT POST BUILD EVENT!"); Debugger.getBreakpointMapper().remap();
} }
} }
...@@ -39,7 +36,8 @@ public class Activator extends AbstractUIPlugin { ...@@ -39,7 +36,8 @@ public class Activator extends AbstractUIPlugin {
*/ */
public Activator() { public Activator() {
IWorkspace workspace = ResourcesPlugin.getWorkspace(); 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 { ...@@ -74,13 +74,15 @@ public class GeneratedFileLocator {
// if (candidates.size() == 0) // if (candidates.size() == 0)
// System.out.println("Found no candidates!"); // System.out.println("Found no candidates!");
for (IFile candidate : candidates) { for (IFile candidate : candidates) {
System.out.println("candidate: " + candidate.getName()); // System.out.println("candidate: " + candidate.getName());
if (currentTargetFile.containsKey(fullPath)) { if (currentTargetFile.containsKey(fullPath)) {
// TODO: check if better than candidate. // TODO: check if better than candidate.
// e.g. if package matches // e.g. if package matches
} }
currentTargetFile.put(fullPath, candidate); currentTargetFile.put(fullPath, candidate);
} }
if (!currentTargetFile.containsKey(fullPath))
return null;
return currentTargetFile.get(fullPath); return currentTargetFile.get(fullPath);
} }
......
...@@ -23,7 +23,7 @@ public class OpenDeclarationHandler extends AbstractHandler { ...@@ -23,7 +23,7 @@ public class OpenDeclarationHandler extends AbstractHandler {
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { 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 // that IHasDefinitionReference -> IHasDeclarationReference
// an getDefinition() -> getDeclaration() // an getDefinition() -> getDeclaration()
......
...@@ -66,6 +66,7 @@ public class RenameSymbolHandler extends AbstractHandler { ...@@ -66,6 +66,7 @@ public class RenameSymbolHandler extends AbstractHandler {
int offset = node.getBegin().getOffsetFromStart(); int offset = node.getBegin().getOffsetFromStart();
try { try {
doc.replace(offset, oldNameLength, newName); doc.replace(offset, oldNameLength, newName);
withName.getName().name = newName;
} catch (BadLocationException e) { } catch (BadLocationException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -2,21 +2,16 @@ package de.tum.in.www2.cupplugin.controller; ...@@ -2,21 +2,16 @@ package de.tum.in.www2.cupplugin.controller;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import org.eclipse.core.runtime.jobs.Job; 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.DocumentEvent;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion; 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.debug.Debugger;
import de.tum.in.www2.cupplugin.editors.CupPartionScanner; import de.tum.in.www2.cupplugin.editors.CupPartionScanner;
import de.tum.in.www2.cupplugin.editors.CupTextEditor; import de.tum.in.www2.cupplugin.editors.CupTextEditor;
...@@ -29,37 +24,28 @@ public class Controller { ...@@ -29,37 +24,28 @@ public class Controller {
doNothing, parseCode, buildTable doNothing, parseCode, buildTable
}; };
// The Job handling changes in a document is triggered after x seconds private static final int SET_CHANGED_AFTER_SECONDS = 1;
static final int SET_CHANGED_AFTER_SECONDS = 1;
// TODO: we need to remove the editor from the list, when it gets disposed. // 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>(); private static WeakHashMap<CupTextEditor, Controller> instances = new WeakHashMap<CupTextEditor, Controller>();
static CupTextEditor AnonymousEditor = null;
// attributes
// The Job that's executed after a document change is detected (changeJob) // The Job that's executed after a document change is detected (changeJob)
private DocumentDidChangeJob myJob = null; 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 // if the changeJob takes some time, it's good to know if it has to be
// reexecuted after it finishes // reexecuted after it finishes
private long changeJobReRunRequested = 0; 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 List<DocumentEvent> documentEvents;
private final EnumSet<JobsToDo> jobElements = EnumSet private final EnumSet<JobsToDo> jobElements = EnumSet
.noneOf(JobsToDo.class); .noneOf(JobsToDo.class);
private long currentRevisionNumber = 0;
private Set<IRegisterForControllerChanges> controllerObservers = Collections.newSetFromMap( private Set<IRegisterForControllerChanges> controllerObservers = Collections.newSetFromMap(
new WeakHashMap<IRegisterForControllerChanges, Boolean>()); new WeakHashMap<IRegisterForControllerChanges, Boolean>());
/*
* Static singleton getter
*/
public static Controller getInstance(CupTextEditor edit) { public static Controller getInstance(CupTextEditor edit) {
Controller instance = instances.get(edit); Controller instance = instances.get(edit);
if (instance != null) { if (instance != null) {
...@@ -70,38 +56,17 @@ public class Controller { ...@@ -70,38 +56,17 @@ public class Controller {
} }
} }
public static Controller getInstance(IDocument doc) { private Controller(CupTextEditor editor) {
for (Map.Entry<CupTextEditor, Controller> e : instances.entrySet()) { this.editor = editor;
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;
myJob = new DocumentDidChangeJob(editor); myJob = new DocumentDidChangeJob(editor);
myJob.setSystem(true); myJob.setSystem(true);
documentEvents = new LinkedList<DocumentEvent>(); 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) { private void addJobToDo(JobsToDo job) {
synchronized (documentEvents) { synchronized (jobElements) {
this.documentEvents.add(e); jobElements.add(job);
} }
} }
...@@ -113,15 +78,9 @@ public class Controller { ...@@ -113,15 +78,9 @@ public class Controller {
} }
} }
public void addJobToDo(JobsToDo job) { public void addDocumentEvent(DocumentEvent e) {
synchronized (jobElements) { synchronized (documentEvents) {
jobElements.add(job); this.documentEvents.add(e);
}
}
public void removeJobToDo(JobsToDo job) {
synchronized (jobElements) {
jobElements.remove(job);
} }
} }
...@@ -160,10 +119,9 @@ public class Controller { ...@@ -160,10 +119,9 @@ public class Controller {
addDocumentEvent(event); addDocumentEvent(event);
IDocument document = myEditor.getDocumentProvider().getDocument( IDocument document = editor.getDocument();
myEditor.getEditorInput());
currentRevisionNumber = RevisionManager.increment(document); RevisionManager.increment(document);
EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class); EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class);
synchronized (controllerObservers) { synchronized (controllerObservers) {
...@@ -272,14 +230,12 @@ public class Controller { ...@@ -272,14 +230,12 @@ public class Controller {
* @return if the job will ever run * @return if the job will ever run
*/ */
public boolean requestJobRun() { public boolean requestJobRun() {
IDocument document = myEditor.getDocumentProvider().getDocument( IDocument document = editor.getDocument();
myEditor.getEditorInput());
EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class); EnumSet<JobsToDo> observedJobs = EnumSet.noneOf(JobsToDo.class);
synchronized (controllerObservers) { synchronized (controllerObservers) {
for (IRegisterForControllerChanges observer : controllerObservers) { for (IRegisterForControllerChanges observer : controllerObservers)
observedJobs.addAll(observer.getRequiredJobs()); observedJobs.addAll(observer.getRequiredJobs());
}
} }
for (JobsToDo job : observedJobs) { for (JobsToDo job : observedJobs) {
...@@ -287,9 +243,8 @@ public class Controller { ...@@ -287,9 +243,8 @@ public class Controller {
case parseCode: case parseCode:
long modelAstRev = Model.getInstanceForDocument(document) long modelAstRev = Model.getInstanceForDocument(document)
.getAstModelRevisionNumber(); .getAstModelRevisionNumber();
if (modelAstRev != RevisionManager.get(document)) { if (modelAstRev != RevisionManager.get(document))
addJobToDo(job); addJobToDo(job);
}
break; break;
case buildTable: case buildTable:
long modelLaLrRev = Model.getInstanceForDocument(document) long modelLaLrRev = Model.getInstanceForDocument(document)
...@@ -318,17 +273,14 @@ public class Controller { ...@@ -318,17 +273,14 @@ public class Controller {
*/ */
public void notifyChangeJobFinished() { public void notifyChangeJobFinished() {
synchronized (lock) { synchronized (lock) {
System.out.println("job finished -> " + changeJobReRunRequested); // Log System.out.println("job finished -> " + changeJobReRunRequested);
// message
// TODO:
// DELETE!
if (changeJobReRunRequested > 0) { if (changeJobReRunRequested > 0) {
changeJobReRunRequested = 0; changeJobReRunRequested = 0;
// TODO: why is this only multiplied by 100 here, but 1000 above ???
long remainderOfDelay = (SET_CHANGED_AFTER_SECONDS * 100) long remainderOfDelay = (SET_CHANGED_AFTER_SECONDS * 100)
- (System.currentTimeMillis() - changeJobReRunRequested); - (System.currentTimeMillis() - changeJobReRunRequested);
myJob.revNumber = RevisionManager.get(myEditor myJob.revNumber = RevisionManager.get(editor.getDocument());
.getDocumentProvider().getDocument(
myEditor.getEditorInput()));
myJob.schedule((remainderOfDelay >= 0) ? remainderOfDelay : 0); myJob.schedule((remainderOfDelay >= 0) ? remainderOfDelay : 0);
} }
} }
......
...@@ -78,7 +78,7 @@ public class DocumentDidChangeJob extends Job { ...@@ -78,7 +78,7 @@ public class DocumentDidChangeJob extends Job {
return Status.CANCEL_STATUS; 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 // on this thread? What about changes that are happening
// to the document? We should probably copy the document // to the document? We should probably copy the document
// data first or something !!! // data first or something !!!
...@@ -150,14 +150,7 @@ public class DocumentDidChangeJob extends Job { ...@@ -150,14 +150,7 @@ public class DocumentDidChangeJob extends Job {
} else { } else {
System.out.println("LALRResult.Compute was not called, " System.out.println("LALRResult.Compute was not called, "
+ "because the parser has reported errors."); + "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) { } catch (internal_error e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -194,24 +187,24 @@ public class DocumentDidChangeJob extends Job { ...@@ -194,24 +187,24 @@ public class DocumentDidChangeJob extends Job {
} }
static class CallbackJob extends UIJob { static class CallbackJob extends UIJob {
CupTextEditor myEditor = null; private CupTextEditor editor = null;
public CallbackJob(CupTextEditor editor) { public CallbackJob(CupTextEditor editor) {
super("" + editor.hashCode()); super("" + editor.hashCode());
myEditor = editor; this.editor = editor;
} }
@Override @Override
public IStatus runInUIThread(IProgressMonitor monitor) { public IStatus runInUIThread(IProgressMonitor monitor) {
Controller.getInstance(myEditor).notifyChangeJobFinished(); Controller.getInstance(editor).notifyChangeJobFinished();
return Status.OK_STATUS; return Status.OK_STATUS;
} }
} }
class ParserResultJob extends UIJob { class ParserResultJob extends UIJob {
ParserResult parserResult; private ParserResult parserResult;
long parserModelRevisionNumber; private long parserModelRevisionNumber;
public ParserResultJob(ParserResult result, long revisionNumber) { public ParserResultJob(ParserResult result, long revisionNumber) {
super("Parser Result UI Job"); super("Parser Result UI Job");
...@@ -238,18 +231,16 @@ public class DocumentDidChangeJob extends Job { ...@@ -238,18 +231,16 @@ public class DocumentDidChangeJob extends Job {
} }
class SetupJob extends UIJob { class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob; private DocumentDidChangeJob documentDidChangeJob;
public SetupJob(DocumentDidChangeJob documentDidChangeJob) { public SetupJob(DocumentDidChangeJob documentDidChangeJob) {
super("Parswer Setup Job"); super("Parser Setup Job");
this.documentDidChangeJob = documentDidChangeJob; this.documentDidChangeJob = documentDidChangeJob;
} }
@Override @Override
public IStatus runInUIThread(IProgressMonitor monitor) { public IStatus runInUIThread(IProgressMonitor monitor) {
Controller controller = Controller.getInstance(myEditor); Controller controller = Controller.getInstance(myEditor);
if (documentDidChangeJob.documentEvents == null if (documentDidChangeJob.documentEvents == null
...@@ -270,19 +261,11 @@ public class DocumentDidChangeJob extends Job { ...@@ -270,19 +261,11 @@ public class DocumentDidChangeJob extends Job {
if (myEditor == null) if (myEditor == null)
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
IDocumentProvider provider = documentDidChangeJob.myEditor IDocument document = myEditor.getDocument();
.getDocumentProvider();
if (provider == null) if (revNumber != RevisionManager.get(document))
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
IDocument document = provider
.getDocument(myEditor.getEditorInput());
if (revNumber != RevisionManager.get(document)) {
return Status.CANCEL_STATUS;
}
documentDidChangeJob.codeText = document.get(); documentDidChangeJob.codeText = document.get();
return Status.OK_STATUS; return Status.OK_STATUS;
......
...@@ -177,6 +177,7 @@ public class BreakpointMapper { ...@@ -177,6 +177,7 @@ public class BreakpointMapper {
} }
public void remap() { public void remap() {
System.err.println("DEBUGGER: remap called.");
removeAll(); removeAll();
addAll(); addAll();
} }
......
...@@ -13,7 +13,10 @@ import de.tum.in.www2.cupplugin.model.Model; ...@@ -13,7 +13,10 @@ import de.tum.in.www2.cupplugin.model.Model;
class CupDocumentListener implements IDocumentListener { class CupDocumentListener implements IDocumentListener {
public CupDocumentListener() { private CupTextEditor editor;
public CupDocumentListener(CupTextEditor editor) {
this.editor = editor;
}