Commit 91f2e026 authored by Benedikt Engeser's avatar Benedikt Engeser
Browse files

Feierabend

parent abbf3c81
......@@ -17,7 +17,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.views;bundle-version="3.7.0",
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"
org.eclipse.debug.ui;bundle-version="3.10.1",
org.eclipse.jdt;bundle-version="3.10.0",
org.eclipse.jdt.debug;bundle-version="3.8.101"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
......@@ -15,13 +15,12 @@ import org.eclipse.jface.text.ITextSelection;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.MultiPageEditor;
import de.tum.in.www2.cupplugin.model.Model;
public final class PluginUtility {
public static void showMessage(String message) {
MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell());
mb.setMessage(message);
......@@ -69,14 +68,38 @@ public final class PluginUtility {
}
public static IFile getReverseFilePartner(IFile javaFile){
/* for(Tuple<IFile,IFile> e : fileMatching){
if( e.has(javaFile)){
return (IFile)e.other(javaFile);
}
}*/return null;
}
public static void addFileTuple(IFile cupFile, IFile javaFile){
if(cupFile == null || javaFile == null)
return;
/*
for(Tuple<IFile,IFile> e : fileMatching){
if(e.has(cupFile) || e.has(javaFile)){
fileMatching.remove(e);
}
}*/
// fileMatching.add(new Tuple<IFile, IFile>(cupFile, javaFile));
return;
}
/**
* Find the generated file that matches our cup file.
* @param cupFile The original cup file.
* @return Can return null if no matching generated file is found.
*/
public static IFile findGenerated(IFile cupFile) {
if (cupFile == null)
if (cupFile == null){
return null;
}
IContainer container = cupFile.getParent();
String name = cupFile.getName();
......@@ -96,10 +119,14 @@ public final class PluginUtility {
// TODO: maybe search for "The following code was generated by CUP" string
// at the beginning of the file?
addFileTuple(cupFile,(IFile) res);
return (IFile) res;
}
return null;
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.debug;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.debug.core.IBreakpointListener;
import org.eclipse.debug.core.model.IBreakpoint;
import de.tum.in.www2.cupplugin.PluginUtility;
//import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
public class BreakpointListener implements IBreakpointListener {
static BreakpointListener instance = null;;
static BreakpointMapper mapper = new BreakpointMapper();
static BreakpointListener instance = null;;
static BreakpointListener getInstance(){
if(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);
System.out.println("ADD: " + breakpoint);
if (breakpoint.getMarker().getResource() != null) {
System.out.println("AT: "
+ breakpoint.getMarker().getResource()
.getProjectRelativePath().toString()+" LINE: "+breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, 0));
PluginUtility.findGenerated((IFile) breakpoint.getMarker().getResource());
}
if(breakpoint instanceof CupLineBreakpoint){
mapper.add((CupLineBreakpoint) breakpoint);
}
System.out.println(breakpoint);
}
@Override
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("DELETE: "+breakpoint+" \n DELTA: "+delta);
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("DELETE: " + breakpoint + " \n DELTA: " + delta);
if(breakpoint instanceof CupLineBreakpoint){
mapper.remove((CupLineBreakpoint) breakpoint);
}
}
@Override
public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
System.out.println("CHANGE: "+breakpoint+" \n DELTA: "+delta);
if(breakpoint instanceof CupLineBreakpoint){
mapper.change((CupLineBreakpoint) breakpoint);
}
}
}
package de.tum.in.www2.cupplugin.debug;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import org.eclipse.jdt.debug.core.JDIDebugModel;
import de.tum.in.www2.cupplugin.PluginUtility;
public class BreakpointMapper {
private Map<CupLineBreakpoint, IBreakpoint> mappings = new HashMap<CupLineBreakpoint, IBreakpoint>();
private Set<CupLineBreakpoint> breakpoints = new HashSet<CupLineBreakpoint>();
public IBreakpoint getRemoteBreakpoint(CupLineBreakpoint breakpoint) {
return mappings.get(breakpoint);
}
public CupLineBreakpoint getOrigin(IBreakpoint breakpoint) {
for (Map.Entry<CupLineBreakpoint, IBreakpoint> e : mappings.entrySet()) {
if (e.getValue().equals(breakpoint)) {
return e.getKey();
}
}
return null;
}
protected void addRemoteBreakpoint(CupLineBreakpoint origin) {
IJavaLineBreakpoint remote = null;
IFile resource = PluginUtility.findGenerated(((IFile) origin
.getResource()));
Map<String, Object> attributes = new HashMap<String, Object>();
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(resource.getContents()));
} catch (CoreException e1) {
e1.printStackTrace();
return;
}
SimpleDebugLineMatcher lineMatcher = new SimpleDebugLineMatcher(reader);
List<Integer> debugIds = new LinkedList<Integer>();
int originLineNumber = origin.getMarker().getAttribute(IMarker.LINE_NUMBER, -1);
if(originLineNumber == -1){
return;
}
debugIds.add(originLineNumber);
int remoteLineNumber = lineMatcher.debuggerFindCase(debugIds).get(0);
if(remoteLineNumber == -1){
return;
}
//remoteLineNumber = 5;//TODO nur zum testen
attributes.put(IBreakpoint.PERSISTED, false);
if (resource != null) {
try {
remote = JDIDebugModel.createLineBreakpoint(resource,
Debugger.getGeneratedTargetClass(origin), remoteLineNumber, -1, -1, 0,
true, attributes);
remote.setEnabled(true);
DebugPlugin.getDefault().getBreakpointManager()
.addBreakpoint(remote);
remote.isInstalled();
} catch (DebugException e) {
e.printStackTrace();
return;
} catch (CoreException e) {
e.printStackTrace();
return;
}
mappings.put(origin, remote);
}
}
protected static boolean removeRemoteBreakpoint(IBreakpoint breakpoint) {
try {
DebugPlugin.getDefault().getBreakpointManager()
.removeBreakpoint(breakpoint, true);
} catch (CoreException e) {
return false;
}
return true;
}
public void add(CupLineBreakpoint breakpoint) {
breakpoints.add(breakpoint);
remap();
}
public void remove(CupLineBreakpoint breakpoint) {
breakpoints.remove(breakpoint);
remap();
}
public void change(CupLineBreakpoint breakpoint) {
remap();
}
protected void removeAll() {
for (IBreakpoint breakpoint : mappings.values()) {
removeRemoteBreakpoint(breakpoint);
}
}
protected void addAll() {
for (CupLineBreakpoint breakpoint : breakpoints) {
addRemoteBreakpoint(breakpoint);
}
}
public void remap() {
removeAll();
addAll();
}
}
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;
......@@ -9,10 +8,19 @@ 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;
import org.eclipse.jdt.debug.core.JDIDebugModel;
public class CupLineBreakpoint extends LineBreakpoint {
private IResource resource = null;
private int lineNumber = -1;
public int getLineNumber(){
return lineNumber;
}
public IResource getResource(){
return resource;
}
public CupLineBreakpoint() {
//eclipse needs that for workspace reconstruction
......@@ -29,6 +37,8 @@ public class CupLineBreakpoint extends LineBreakpoint {
protected CupLineBreakpoint(final IResource resource, final int lineNumber,
final boolean persistent) throws CoreException {
super();
this.resource = resource;
this.lineNumber = lineNumber;
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
......@@ -64,16 +74,20 @@ public class CupLineBreakpoint extends LineBreakpoint {
}
@Override
public void delete() throws CoreException {
super.delete();
// System.out.println("delete called "+this);//TODO: DELETE
}
@Override
public String getModelIdentifier() {
return Debugger.DEBUG_ID;
return JDIDebugModel.getPluginIdentifier();
}
}
\ No newline at end of file
......@@ -3,15 +3,11 @@ 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 org.eclipse.ui.IEditorInput;
import de.tum.in.www2.cupplugin.controller.DocumentDidChangeJob;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.model.Model;
import de.in.tum.www2.cup.analysis.FindNextCodeBlockLineVisitor;
......@@ -23,7 +19,10 @@ public class 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>();
private static final BreakpointMapper breakpointMapper = new BreakpointMapper();
private static final String DEFAULT_CLASS = "Test";//TODO: auf Parser umstellen
/**
* Add Debug hooks to an editor
*
......@@ -38,8 +37,7 @@ public class Debugger {
}
// 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;
......@@ -72,6 +70,10 @@ public class Debugger {
return instances.get(editor);
}
}
public static BreakpointMapper getBreakpointMapper(){
return breakpointMapper;
}
public static Debugger getInstance(IResource resource) {
IResource current = null;
......@@ -115,7 +117,11 @@ public class Debugger {
}
/**
* Get the next useful location for a breakpointmarker
* @param line the line, the action was triggered on
* @return the next useful line
*/
public int getNextCodeBlockForLineBreakpoint(int line) {
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
......@@ -130,4 +136,15 @@ public class Debugger {
return v.getResult();
}
/**
* The java class in which a remote breakpoint will be set. The Java debugger needs that information to break correctly.
* example: Parser
* Parser$NestedSubClass
* @param breakpoint the breakpoint that asks
* @return the class name
*/
public static String getGeneratedTargetClass(CupLineBreakpoint breakpoint){
return DEFAULT_CLASS;
}
}
\ No newline at end of file
......@@ -7,7 +7,6 @@ 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.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPart;
......
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