Commit f7f3cb99 authored by Benedikt Engeser's avatar Benedikt Engeser
Browse files

BpListener global registriert

parent 7468ae5a
package de.tum.in.www2.cupplugin.debug;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.debug.core.IBreakpointListener;
import org.eclipse.debug.core.model.IBreakpoint;
public class BreakpointListener implements IBreakpointListener {
static BreakpointListener instance = null;;
static BreakpointListener getInstance(){
if(instance == null){
instance = new BreakpointListener();
Debugger.getBreakpointManager().addBreakpointListener(instance);
}
return instance;
}
public BreakpointListener() {
}
@Override
public void breakpointAdded(IBreakpoint breakpoint) {
// TODO Auto-generated method stub
System.out.println("ADD: "+breakpoint);
}
@Override
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("DELETE: "+breakpoint+" \n DELTA: "+delta);
}
@Override
public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("CHANGE: "+breakpoint+" \n DELTA: "+delta);
}
}
......@@ -51,7 +51,9 @@ public class CupLineBreakpoint extends LineBreakpoint {
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);
BreakpointListener.getInstance();
Debugger.getBreakpointManager().addBreakpoint(this);
}
......
......@@ -9,6 +9,7 @@ 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 org.eclipse.ui.IEditorInput;
import de.tum.in.www2.cupplugin.controller.DocumentDidChangeJob;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
......@@ -16,32 +17,33 @@ import de.tum.in.www2.cupplugin.model.Model;
import de.in.tum.www2.cup.analysis.FindNextCodeBlockLineVisitor;
import de.in.tum.www2.cup.ast.ParserResult;
public class Debugger implements IBreakpointListener{
public class Debugger {
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>();
static HashMap<IResource, Debugger> delayedInstances = new HashMap<IResource, Debugger>();
/**
* Add Debug hooks to an editor
* @param editor the editor, the hooks shall be added to
*
* @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...
// 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;
private static IBreakpointManager DefaultBreakPointManager = null;
/*
* Static singelton getter
......@@ -49,7 +51,20 @@ public class Debugger implements IBreakpointListener{
public static Debugger getInstance(CupTextEditor editor) {
Debugger instance = instances.get(editor);
if (instance != null) {
if (!instances.isEmpty()) {
for (Map.Entry<CupTextEditor, Debugger> e : instances
.entrySet()) {
IEditorInput input = e.getKey().getEditorInput();
if (input == null) {
continue;
}
IResource resource = (IResource) input
.getAdapter(IResource.class);
if (delayedInstances.get(resource) != null) {
delayedInstances.remove(resource);
}
}
}
return instance;
} else {
......@@ -61,8 +76,12 @@ public class Debugger implements IBreakpointListener{
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);
IEditorInput input = e.getKey().getEditorInput();
if (input != null) {
current = (IResource) input.getAdapter(IResource.class);
} else {
continue;
}
System.out.println("RESOURCE: " + current);
if (current != null && current.equals(resource)) {
return e.getValue();
......@@ -70,8 +89,10 @@ public class Debugger implements IBreakpointListener{
}
current = null;
}
Debugger tmp = new Debugger(new CupTextEditor());
delayedInstances.put(resource, tmp);
return null;
return tmp;
}
/*
......@@ -79,49 +100,34 @@ public class Debugger implements IBreakpointListener{
*/
public Debugger(CupTextEditor editor) {
myEditor = editor;
DefaultBreakPointManager = DebugPlugin.getDefault().getBreakpointManager();
DefaultBreakPointManager.addBreakpointListener(this);
DefaultBreakPointManager = DebugPlugin.getDefault()
.getBreakpointManager();
BreakpointListener.getInstance();
}
public IBreakpointManager getBreakpointManager() {
public static IBreakpointManager getBreakpointManager() {
if (DefaultBreakPointManager == null) {
DefaultBreakPointManager = DebugPlugin.getDefault().getBreakpointManager();
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");
public int getNextCodeBlockForLineBreakpoint(int line) {
}
public int getNextCodeBlockForLineBreakpoint(int line){
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider().getDocument(myEditor.getEditorInput()));
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
.getDocument(myEditor.getEditorInput()));
ParserResult astModel = m.getAstModel();
if(astModel == null)
if (astModel == null)
return line;
//create Visitor
// create Visitor
FindNextCodeBlockLineVisitor v = new FindNextCodeBlockLineVisitor(line);
astModel.accept(v, null);
return v.getResult();
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.debug;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
......@@ -10,6 +11,9 @@ import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory;
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 ToggleBreakpointFactory implements IToggleBreakpointsTargetFactory {
Map<String, ToggleBreakpointsTarget> toggleTargets = null;
......@@ -24,16 +28,21 @@ public class ToggleBreakpointFactory implements IToggleBreakpointsTargetFactory
@Override
public Set<String> getToggleTargets(IWorkbenchPart part,
ISelection selection) {
if (targets.isEmpty())
targets.add(ToggleBreakpointsTarget.class.getName());
return targets;
if (part instanceof CupTextEditor || part instanceof MultiPageEditor) {
if (targets.isEmpty())
targets.add(ToggleBreakpointsTarget.class.getName());
return targets;
}
return Collections.emptySet();
}
@Override
public String getDefaultToggleTarget(IWorkbenchPart part,
ISelection selection) {
return ToggleBreakpointsTarget.class.getName();
if (part instanceof CupTextEditor || part instanceof MultiPageEditor) {
return ToggleBreakpointsTarget.class.getName();
}
return "";
}
@Override
......@@ -45,15 +54,17 @@ public class ToggleBreakpointFactory implements IToggleBreakpointsTargetFactory
@Override
public String getToggleTargetName(String targetID) {
// System.out.println("NAME:" + toggleTargets.get(targetID));// TODO: DELETE
//is that really right here?
// 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
// System.out.println("DESCRIPTION:" + toggleTargets.get(targetID));//
// TODO:DELETE
// i don't know
return "DESCRIPTION:" + toggleTargets.get(targetID);
}
......
......@@ -58,8 +58,7 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
}
//create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger
.getInstance(textEditor).getBreakpointManager()
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger.getBreakpointManager()
.getBreakpoints();
if (breakpoints != null) {
for (int i = 0; i < breakpoints.length; i++) {
......@@ -67,8 +66,7 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
if (resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
// existing breakpoint; delete
Debugger.getInstance(textEditor)
.getBreakpointManager()
Debugger.getBreakpointManager()
.removeBreakpoint(breakpoint, true);
return;
}
......@@ -79,10 +77,10 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
// new breakpoint; create
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource,
lineNumber + 1);
Debugger.getInstance(textEditor).getBreakpointManager()
Debugger.getBreakpointManager()
.addBreakpoint(lineBreakpoint);
/*System.out.println("CREATED! Length: "
+ Debugger.getInstance(textEditor).getBreakpointManager()
+ Debugger.getBreakpointManager()
.getBreakpoints().length);*/// TODO: DELETE
}
......
Supports Markdown
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