Commit 9f637260 authored by Benedikt Engeser's avatar Benedikt Engeser

Breakpoints

parent 1c8367a2
......@@ -15,7 +15,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.zest.layouts;bundle-version="1.1.100",
CupReferencedLibraries;bundle-version="1.0.0",
org.eclipse.ui.views;bundle-version="3.7.0",
org.eclipse.core.expressions;bundle-version="3.4.600"
org.eclipse.core.expressions;bundle-version="3.4.600",
org.eclipse.debug.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.10.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
......@@ -106,5 +106,30 @@
</extension>
<extension
point="org.eclipse.debug.ui.toggleBreakpointsTargetFactories">
<toggleTargetFactory
class="de.tum.in.www2.cupplugin.debug.ToggleBreakpointFactory"
id="de.tum.in.www2.cupplugin.debug.ToggleBreakpointFactoryId">
</toggleTargetFactory>
</extension>
<extension
point="org.eclipse.debug.core.breakpoints">
<breakpoint
class="de.tum.in.www2.cupplugin.debug.CupLineBreakpoint"
id="CupLineBreakpointId"
markerType="org.eclipse.debug.core.lineBreakpointMarker"
name="CUP Line Breakpoint">
</breakpoint>
</extension>
<extension
id="org.tum.in.www2.cupplugin.markers.problem"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<persistent
value="true">
</persistent>
</extension>
</plugin>
package de.tum.in.www2.cupplugin.debug;
import java.util.Arrays;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.LineBreakpoint;
public class CupLineBreakpoint extends LineBreakpoint {
public CupLineBreakpoint() {
//eclipse needs that for workspace reconstruction
super();
}
public CupLineBreakpoint(final IResource resource, final int lineNumber)
throws CoreException {
this(resource, lineNumber, true);
}
protected CupLineBreakpoint(final IResource resource, final int lineNumber,
final boolean persistent) throws CoreException {
super();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IMarker marker = resource
.createMarker("org.eclipse.debug.core.lineBreakpointMarker");
setMarkerUnnoticed(marker);
marker.setAttribute(IBreakpoint.ENABLED, true);
marker.setAttribute(IBreakpoint.PERSISTED, persistent);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
marker.setAttribute(IBreakpoint.ID, getModelIdentifier());
marker.setAttribute(IMarker.MESSAGE, "Line Breakpoint: "
+ resource.getName() + " [line: " + lineNumber + "]");
}
};
run(getMarkerRule(resource), runnable);
}
public void setMarker(IMarker marker) throws CoreException {
super.setMarker(marker);
IResource resource = marker.getResource();
System.out.println("Markers: "+Arrays.toString(resource.findMarkers(null, true, IResource.DEPTH_INFINITE)));
Debugger.getInstance(resource).getBreakpointManager().addBreakpoint(this);
}
public void setMarkerUnnoticed(IMarker marker) throws CoreException {
super.setMarker(marker);
// System.out.println("Markers: "+Arrays.toString(marker.getResource().findMarkers(null, true, IResource.DEPTH_INFINITE)));//TODO: DELETE
}
@Override
public void delete() throws CoreException {
super.delete();
// System.out.println("delete called "+this);//TODO: DELETE
}
@Override
public String getModelIdentifier() {
return Debugger.DEBUG_ID;
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.debug;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IResource;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointListener;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.model.IBreakpoint;
import de.tum.in.www2.cupplugin.controller.DocumentDidChangeJob;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
public class Debugger implements IBreakpointListener{
static final String DEBUG_ID = "de.tum.www2.cupplugin.debug.Debugger";
// Static reference to the controller instance per document
static HashMap<CupTextEditor, Debugger> instances = new HashMap<CupTextEditor, Debugger>();
/**
* Add Debug hooks to an editor
* @param editor the editor, the hooks shall be added to
* @return true, if adding hooks succeeded
*/
public static boolean addDebugHooksToTextEditor(CupTextEditor editor) {
//nothing so far...
return true;
}
// attributes
// 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;
private IBreakpointManager DefaultBreakPointManager = null;
/*
* Static singelton getter
*/
public static Debugger getInstance(CupTextEditor editor) {
Debugger instance = instances.get(editor);
if (instance != null) {
return instance;
} else {
instances.put(editor, new Debugger(editor));
return instances.get(editor);
}
}
public static Debugger getInstance(IResource resource) {
IResource current = null;
for (Map.Entry<CupTextEditor, Debugger> e : instances.entrySet()) {
current = (IResource) e.getKey().getEditorInput()
.getAdapter(IResource.class);
System.out.println("RESOURCE: " + current);
if (current != null && current.equals(resource)) {
return e.getValue();
}
current = null;
}
return null;
}
/*
* The Constructor, taking the document it's controlling as a parameter
*/
public Debugger(CupTextEditor editor) {
myEditor = editor;
DefaultBreakPointManager = DebugPlugin.getDefault().getBreakpointManager();
DefaultBreakPointManager.addBreakpointListener(this);
}
public IBreakpointManager getBreakpointManager() {
if (DefaultBreakPointManager == null) {
DefaultBreakPointManager = DebugPlugin.getDefault().getBreakpointManager();
}
return DefaultBreakPointManager;
}
@Override
public void breakpointAdded(IBreakpoint breakpoint) {
System.out.println("Breakpoint added to manager, add to Java");
}
@Override
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("Breakpoint removed to manager, remove from Java");
}
@Override
public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("Breakpoint changed at manager, change at Java");
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.debug;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPart;
public class ToggleBreakpointFactory implements IToggleBreakpointsTargetFactory {
Map<String, ToggleBreakpointsTarget> toggleTargets = null;
Set<String> targets = new HashSet<String>();
public ToggleBreakpointFactory() {
super();
toggleTargets = new HashMap<String, ToggleBreakpointsTarget>();
}
@Override
public Set<String> getToggleTargets(IWorkbenchPart part,
ISelection selection) {
if (targets.isEmpty())
targets.add(ToggleBreakpointsTarget.class.getName());
return targets;
}
@Override
public String getDefaultToggleTarget(IWorkbenchPart part,
ISelection selection) {
return ToggleBreakpointsTarget.class.getName();
}
@Override
public IToggleBreakpointsTarget createToggleTarget(String targetID) {
ToggleBreakpointsTarget target = new ToggleBreakpointsTarget();
toggleTargets.put(targetID, target);
return target;
}
@Override
public String getToggleTargetName(String targetID) {
// System.out.println("NAME:" + toggleTargets.get(targetID));// TODO: DELETE
//is that really right here?
return "NAME:" + toggleTargets.get(targetID);
}
@Override
public String getToggleTargetDescription(String targetID) {
// System.out.println("DESCRIPTION:" + toggleTargets.get(targetID));// TODO:DELETE
//i don't know
return "DESCRIPTION:" + toggleTargets.get(targetID);
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.debug;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPart;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.MultiPageEditor;
public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
CupTextEditor textEditor = null;
/*
* find out where the editor is
*/
if (part instanceof CupTextEditor){
textEditor = (CupTextEditor) part;
}
else if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
if (editor instanceof CupTextEditor)
textEditor = (CupTextEditor) editor;
}
if (textEditor != null) {
//prepare everything
IResource resource = (IResource) textEditor.getEditorInput()
.getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
// get doc identifier:
IDocument doc = null;
doc = textEditor.getDocumentProvider().getDocument(
textEditor.getEditorInput());
if (doc == null) {
return;
}
//create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger
.getInstance(textEditor).getBreakpointManager()
.getBreakpoints();
if (breakpoints != null) {
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
// existing breakpoint; delete
Debugger.getInstance(textEditor)
.getBreakpointManager()
.removeBreakpoint(breakpoint, true);
return;
}
}
}
}
// new breakpoint; create
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource,
lineNumber + 1);
Debugger.getInstance(textEditor).getBreakpointManager()
.addBreakpoint(lineBreakpoint);
/*System.out.println("CREATED! Length: "
+ Debugger.getInstance(textEditor).getBreakpointManager()
.getBreakpoints().length);*/// TODO: DELETE
}
}
@Override
public boolean canToggleLineBreakpoints(IWorkbenchPart part,
ISelection selection) {
// true, if we have an CupTextEditor
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Breakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
return (editor instanceof CupTextEditor);
}
return false;
}
@Override
public void toggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) throws CoreException {
//not implemented
//System.out.println("toggle watchpoints called");// TODO: DELETE
}
@Override
public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) {
//default answer: false
return false;
//do this, if you want to toggle method bps
/*if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(MethodBreakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
}
@Override
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
//System.out.println("toggleWatchpoints called");
}
@Override
public boolean canToggleWatchpoints(IWorkbenchPart part,
ISelection selection) {
return false;
/*
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Watchpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.editors;
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.model.Model;
public class CupTextEditor extends TextEditor {
IVerticalRulerInfo ruler = null;
private CupContentOutlinePage outlinePage;
static Color gray;
......@@ -72,5 +79,32 @@ public class CupTextEditor extends TextEditor {
}
return super.getAdapter(required);
}
public void addActions(){
if(ruler == null)
ruler = getVerticalRuler();
setAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK,
new ToggleBreakpointAction(this, null,ruler ));
this.addRulerContextMenuListener(new AddToggleBreakpointToMenuListener(
this));
}
class AddToggleBreakpointToMenuListener implements IMenuListener {
IWorkbenchPart part = null;
AddToggleBreakpointToMenuListener(IWorkbenchPart p) {
part = p;
}
@Override
public void menuAboutToShow(IMenuManager manager) {
IAction tba = new ToggleBreakpointAction(part, null,
getVerticalRuler());
manager.add(tba);
}
}
}
......@@ -19,6 +19,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.ide.IDE;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.debug.Debugger;
public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener{
......@@ -52,6 +53,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
setPageText(index, "Grammar");
setTitle(editor.getTitle());
addHooksToMainTextEditor(editor);
editor.addActions();
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Controller controller = Controller.getInstance(doc);
......@@ -188,6 +190,13 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
if(doc == null)
return false;
doc.addDocumentListener(new CTEDocumentListener(file));
if (editor instanceof CupTextEditor) {
if (!Debugger.addDebugHooksToTextEditor((CupTextEditor) editor)) {
return false;
}
}
return true;
}
......
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