Commit e79280d6 authored by Benedikt Engeser's avatar Benedikt Engeser

Aufhübschen/Output auskommentieren/Bla

parent a25ee9a5
......@@ -119,8 +119,8 @@ public class DocumentDidChangeJob extends Job {
errorReporter.pushToUIThread();
if (result != null) {
ParserResultJob resultModelJob = new ParserResultJob(
result, context, revNumber);
ParserResultJob resultModelJob = new ParserResultJob(result,
context, revNumber);
resultModelJob.setSystem(true);
resultModelJob.schedule();
try {
......@@ -140,8 +140,11 @@ public class DocumentDidChangeJob extends Job {
lalrResult = LALRResult.Compute(context,
context.start_production);
} else {
System.out.println("LALRResult.Compute was not called, "
+ "because the parser has reported errors.");//TODO: REMOVE
/*
* System.out.println("LALRResult.Compute was not called, "
* + "because the parser has reported errors."); TODO:
* REMOVE
*/
}
} catch (internal_error e) {
e.printStackTrace();
......@@ -165,7 +168,7 @@ public class DocumentDidChangeJob extends Job {
errorReporter.pushToUIThread();
System.out.println(jobs);
/* System.out.println(jobs); TODO: REMOVE OUTPUT */
documentEvents.clear();
jobs.clear();
......@@ -197,9 +200,11 @@ public class DocumentDidChangeJob extends Job {
private ParserResult parserResult;
private CupContext context;
@SuppressWarnings("unused")
private long parserModelRevisionNumber;
public ParserResultJob(ParserResult result, CupContext context, long revisionNumber) {
public ParserResultJob(ParserResult result, CupContext context,
long revisionNumber) {
super("Parser Result UI Job");
this.context = context;
this.parserResult = result;
......
......@@ -7,5 +7,5 @@ import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
public interface IRegisterForControllerChanges {
EnumSet<JobsToDo> getRequiredJobs();
}
......@@ -11,14 +11,13 @@ import de.in.tum.www2.cup.LALRResult;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.model.Model;
public class LaLrResultJob extends UIJob {
private LALRResult lalrResult;
private long lalrResulRevisionNumber;
private CupContext lalrContext;
private CupTextEditor editor;
public LaLrResultJob(CupTextEditor editor, LALRResult result,
long revisionNumber, CupContext context) {
super("LaLr Result UI Job");
......@@ -33,12 +32,11 @@ public class LaLrResultJob extends UIJob {
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setLaLrResultModel(this.lalrResult,
lalrResulRevisionNumber, lalrContext);
model.setLaLrResultModel(this.lalrResult, lalrResulRevisionNumber,
lalrContext);
return Status.OK_STATUS;
}
return Status.CANCEL_STATUS;
}
}
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;
......@@ -7,7 +8,7 @@ public class BreakpointListener implements IBreakpointListener {
static BreakpointListener instance = null;;
static BreakpointMapper mapper = new BreakpointMapper();
static BreakpointListener getInstance() {
if (instance == null) {
instance = new BreakpointListener();
......@@ -21,19 +22,19 @@ public class BreakpointListener implements IBreakpointListener {
@Override
public void breakpointAdded(IBreakpoint breakpoint) {
if(breakpoint instanceof CupLineBreakpoint)
if (breakpoint instanceof CupLineBreakpoint)
mapper.add((CupLineBreakpoint) breakpoint);
}
@Override
public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
if(breakpoint instanceof CupLineBreakpoint)
if (breakpoint instanceof CupLineBreakpoint)
mapper.remove((CupLineBreakpoint) breakpoint);
}
@Override
public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
if(breakpoint instanceof CupLineBreakpoint)
if (breakpoint instanceof CupLineBreakpoint)
mapper.change((CupLineBreakpoint) breakpoint);
}
......
......@@ -25,7 +25,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
import de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.GeneratedFileLocator;
import de.tum.in.www2.cupplugin.PluginUtility;
public class BreakpointMapper {
private Map<CupLineBreakpoint, IBreakpoint> mappings;
......@@ -37,7 +36,7 @@ public class BreakpointMapper {
breakpoints = new HashSet<CupLineBreakpoint>();
locator = new GeneratedFileLocator();
}
public IBreakpoint getRemoteBreakpoint(CupLineBreakpoint breakpoint) {
return mappings.get(breakpoint);
}
......@@ -52,7 +51,7 @@ public class BreakpointMapper {
private void addRemoteBreakpoint(CupLineBreakpoint origin) {
IResource originResource = origin.getMarker().getResource();
if(originResource == null)
if (originResource == null)
return;
IDocument document = null;
......@@ -71,23 +70,24 @@ public class BreakpointMapper {
} else {
throw new RuntimeException("Unexpected resource type.");
}
Debugger dbg = Debugger.getInstance(document);
ParserResult astModel = dbg.getParserResult();
if(astModel == null) {
if (astModel == null) {
// TODO: warn
return;
}
IFile resource = locator.find((IFile) originResource, astModel);
if(resource == null) {
if (resource == null) {
// TODO: warn
return;
}
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(resource.getContents()));
reader = new BufferedReader(new InputStreamReader(
resource.getContents()));
} catch (CoreException e1) {
e1.printStackTrace();
return;
......@@ -95,12 +95,13 @@ public class BreakpointMapper {
SimpleDebugLineMatcher lineMatcher = new SimpleDebugLineMatcher(reader);
List<Integer> debugIds = new LinkedList<Integer>();
int originLineNumber = origin.getMarker().getAttribute(IMarker.LINE_NUMBER, -1);
if(originLineNumber == -1)
int originLineNumber = origin.getMarker().getAttribute(
IMarker.LINE_NUMBER, -1);
if (originLineNumber == -1)
return;
Mapping debugId = dbg.getDebugId(originLineNumber);
if(debugId == null) {
if (debugId == null) {
// TODO: warn
return;
}
......@@ -108,15 +109,15 @@ public class BreakpointMapper {
debugIds.add(debugId.getDebugId());
int remoteLineNumber = lineMatcher.debuggerFindCase(debugIds).get(0)
+ debugId.getLineOffsetFromId();
+ debugId.getLineOffsetFromId();
if (remoteLineNumber != -1)
doCreateTargetBreakpoint(origin, document, resource, remoteLineNumber);
doCreateTargetBreakpoint(origin, document, resource,
remoteLineNumber);
}
private void doCreateTargetBreakpoint(CupLineBreakpoint origin,
IDocument doc, IFile remoteFile, int remoteLineNumber)
{
private void doCreateTargetBreakpoint(CupLineBreakpoint origin,
IDocument doc, IFile remoteFile, int remoteLineNumber) {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IBreakpoint.PERSISTED, false);
IJavaLineBreakpoint remote = null;
......@@ -125,8 +126,8 @@ public class BreakpointMapper {
Debugger dbg = Debugger.getInstance(doc);
String targetClass = dbg.getGeneratedTargetClass(origin);
remote = JDIDebugModel.createLineBreakpoint(remoteFile,
targetClass, remoteLineNumber, -1, -1, 0,
true, attributes);
targetClass, remoteLineNumber, -1, -1, 0, true,
attributes);
remote.setEnabled(true);
DebugPlugin.getDefault().getBreakpointManager()
.addBreakpoint(remote);
......@@ -177,7 +178,7 @@ public class BreakpointMapper {
}
public void remap() {
System.err.println("DEBUGGER: remap called.");
/* System.err.println("DEBUGGER: remap called."); TODO: REMOVE OUTPUT */
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;
......@@ -11,23 +10,23 @@ import org.eclipse.debug.core.model.LineBreakpoint;
import org.eclipse.jdt.debug.core.JDIDebugModel;
public class CupLineBreakpoint extends LineBreakpoint {
private static final String MARKER_ID = "org.eclipse.debug.core.lineBreakpointMarker";
private IResource resource = null;
private int lineNumber = -1;
@Override
public int getLineNumber() throws CoreException {
if (lineNumber != -1)
return lineNumber;
return super.getLineNumber();
}
public IResource getResource(){
public IResource getResource() {
return resource;
}
public CupLineBreakpoint() {
super();
}
......@@ -61,9 +60,6 @@ public class CupLineBreakpoint extends LineBreakpoint {
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)));
BreakpointListener.getInstance();
Debugger.getBreakpointManager().addBreakpoint(this);
}
......@@ -71,6 +67,7 @@ public class CupLineBreakpoint extends LineBreakpoint {
public void setMarkerUnnoticed(IMarker marker) throws CoreException {
super.setMarker(marker);
}
@Override
public void delete() throws CoreException {
super.delete();
......
......@@ -3,18 +3,9 @@ package de.tum.in.www2.cupplugin.debug;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.editors.CupEditorErrorReporter;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.Model;
......@@ -62,14 +53,20 @@ public class Debugger {
/**
* Get the next useful location for a breakpointmarker
* @param line the line, the action was triggered on
*
* @param line
* the line, the action was triggered on
* @return the next useful line
*/
public int getNextCodeBlockForLineBreakpoint(int line) {
ParserResult astModel = getParserResult();
if (astModel == null) {
System.err.println("WARNING: did not use breakpoint snapping, because AST was not available.");
/*
* System.err .println(
* "WARNING: did not use breakpoint snapping, because AST was not available."
* ); TODO: REMOVE OUTPUT
*/
return line;
}
FindNextCodeBlockLineVisitor v = new FindNextCodeBlockLineVisitor(line);
......@@ -86,16 +83,24 @@ public class Debugger {
ParserResult result = getParserResult();
if (result == null) {
System.err.println("WARNING: No AST available. Using default class. Debugger may not work.");
/*
* System.err .println(
* "WARNING: No AST available. Using default class. Debugger may not work."
* );TODO: REMOVE OUTPUT
*/
return DEFAULT_CLASS;
}
String packageName = null;
if (result.pack != null)
packageName = result.pack.getNameStringOrNull();
if (packageName == null) {
System.err.println("WARNING: No package specified in cup file. Debugger might not work.");
/*
* System.err .println(
* "WARNING: No package specified in cup file. Debugger might not work."
* );TODO: REMOVE OUTPUT
*/
packageName = "";
} else {
packageName += ".";
......@@ -115,38 +120,39 @@ public class Debugger {
ParserResult astModel = getParserResult();
if (astModel == null)
return null;
// TODO: this is too expensive! -> pass all line numbers in array!
int lines[] = { lineNumber };
GetDebuggerMappingVisitor v = new GetDebuggerMappingVisitor(lines);
astModel.accept(v, null);
if(v.getMappings().size() < 1){
if (v.getMappings().size() < 1) {
return null;
}
return v.getMappings().get(0);
}
public ParserResult getParserResult() {
if(document == null)
System.out.println("document: NULL");
if (document == null) {
/* System.out.println("document: NULL");TODO: REMOVE OUTPUT */
}
if (!CupTextEditor.hasOpened(document)) {
// If the document is not opened in a text editor,
// If the document is not opened in a text editor,
// we need to create the parser result ourselves.
if (selfBuiltAstCache != null)
return selfBuiltAstCache;
InputStream in = new ByteArrayInputStream(document.get().getBytes());
CupParser parser = new CupParser(new NoopErrorReporter(), in);
try {
selfBuiltAstCache = parser.parse();
// TODO: manage revisions properly?
long revision = RevisionManager.increment(document);
Model.getInstanceForDocument(document).setASTModel(selfBuiltAstCache, parser.getContext(), revision);
Model.getInstanceForDocument(document).setASTModel(
selfBuiltAstCache, parser.getContext(), revision);
} catch (Exception e1) {
e1.printStackTrace();
......
......@@ -3,11 +3,12 @@ package de.tum.in.www2.cupplugin.debug;
import java.util.List;
public interface IDebugLineMatcher {
/**
* @param indexes A list of debug ids in the original CUP file.
* @param indexes
* A list of debug ids in the original CUP file.
* @return A list of matching line numbers in the generated file.
*/
List<Integer> debuggerFindCase(List<Integer> indexes);
}
package de.tum.in.www2.cupplugin.debug;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -13,40 +12,40 @@ public class SimpleDebugLineMatcher implements IDebugLineMatcher {
private static final int OFFSET = 2;
private BufferedReader reader;
public SimpleDebugLineMatcher (BufferedReader reader) {
public SimpleDebugLineMatcher(BufferedReader reader) {
this.reader = reader;
}
public List<Integer> debuggerFindCase(List<Integer> debugIds) {
if (debugIds == null)
return null;
HashMap<Integer,Integer> found = new HashMap<Integer,Integer> ();
HashMap<Integer, Integer> found = new HashMap<Integer, Integer>();
List<Integer> result = new ArrayList<Integer>();
try {
int lineNum = -1;
String line = null;
while ((line = reader.readLine()) != null) {
lineNum++;
for (int debugId : debugIds) {
if (line.trim().endsWith(DEBUG_SYMBOL_PREFIX + debugId)) {
found.put(debugId, lineNum + OFFSET);
continue;
}
}
for (int debugId : debugIds) {
if (line.trim().endsWith(DEBUG_SYMBOL_PREFIX + debugId)) {
found.put(debugId, lineNum + OFFSET);
continue;
}
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
for (int i=0; i < debugIds.size(); i++)
for (int i = 0; i < debugIds.size(); i++)
if (found.containsKey(debugIds.get(i)))
result.add(found.get(debugIds.get(i)));
else
result.add(-1);
return result;
}
}
......@@ -41,7 +41,7 @@ public class ToggleBreakpointFactory implements IToggleBreakpointsTargetFactory
ISelection selection) {
if (part instanceof CupTextEditor || part instanceof MultiPageEditor) {
return ToggleBreakpointsTarget.class.getName();
}
}
return "";
}
......
......@@ -41,7 +41,7 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
} else {
return;
}
lineNumber = lineNumber + 1;
// get doc identifier:
......@@ -55,24 +55,25 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
if (removeOldBreakpoints(resource, lineNumber))
return;
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource, lineNumber );
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource,
lineNumber);
Debugger.getBreakpointManager().addBreakpoint(lineBreakpoint);
}
}
private boolean removeOldBreakpoints(IResource resource, int lineNumber)
throws CoreException
{
private boolean removeOldBreakpoints(IResource resource, int lineNumber)
throws CoreException {
boolean didRemove = false;
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger
.getBreakpointManager().getBreakpoints();
if (breakpoints != null) {
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (breakpoint instanceof CupLineBreakpoint) {
if (resource.equals(breakpoint.getMarker().getResource())) {
int lnum = ((ILineBreakpoint) breakpoint).getLineNumber();
int lnum = ((ILineBreakpoint) breakpoint)
.getLineNumber();
if (lnum == lineNumber) {
// existing breakpoint; delete
Debugger.getBreakpointManager().removeBreakpoint(
......@@ -92,7 +93,8 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
// true, if we have an CupTextEditor
if (part instanceof CupTextEditor) {
if (selection instanceof ITextSelection) {
return (Debugger.getInstance(((CupTextEditor) part).getDocument())
return (Debugger.getInstance(
((CupTextEditor) part).getDocument())
.getNextCodeBlockForLineBreakpoint(
((ITextSelection) selection).getStartLine()) != -1);
} else {
......
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