Commit 5b61aa48 authored by Sebastian Pretscher's avatar Sebastian Pretscher
Browse files

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents 9e971a39 d2721c77
......@@ -9,6 +9,7 @@ import de.in.tum.www2.cup.IErrorReporter;
import de.in.tum.www2.cup.ErrorManager;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.ComplexSymbolFactory.ComplexSymbol;
import java_cup.runtime.Symbol;
import de.in.tum.www2.java.internal.onefivelexer.Lexer;
public class JavaScanner
......@@ -33,20 +34,16 @@ public class JavaScanner
//
// Finally, there are types. These are not colored in eclipse anyway.
/*
private Lexer lexer;
public JavaScanner(IErrorReporter er, Reader r) {
ComplexSymbolFactory factory = new ComplexSymbolFactory();
ErrorManager errMan = new ErrorManager(er);
this.lexer = new Lexer(errMan, factory, r);
public JavaScanner(Reader r) {
this.lexer = new Lexer(r);
}
public JavaSymbol next_token() throws IOException {
ComplexSymbol symbol = (ComplexSymbol) lexer.next_token();
Symbol symbol = lexer.next_token();
return new JavaSymbol(symbol);
}
*/
}
package de.in.tum.www2.java;
import java.util.HashSet;
import de.in.tum.www2.java.internal.onefivelexer.Sym;
import java_cup.runtime.Symbol;
public class JavaSymbol {
private Symbol s;
public Object getValue() {
if (s == null)
return null;
return s.value;
}
public int getSymbolId() {
if (s == null)
return -1;
return s.sym;
}
// TODO: why not take this from xleft?
public int getLeft() {
if (s == null)
return -1;
return s.left;
}
// TODO: why not take this from xright?
public int getRight() {
if (s == null)
return -1;
return s.right;
}
private static final HashSet<Integer> keywords = new HashSet<Integer>();
static {
keywords.add(Sym.ABSTRACT);
keywords.add(Sym.ASSERT);
keywords.add(Sym.BOOLEAN);
keywords.add(Sym.BYTE);
keywords.add(Sym.BYTE);
keywords.add(Sym.CASE);
keywords.add(Sym.CATCH);
keywords.add(Sym.CHAR);
keywords.add(Sym.CLASS);
keywords.add(Sym.CONST);
keywords.add(Sym.CONTINUE);
keywords.add(Sym.DEFAULT);
keywords.add(Sym.DO);
keywords.add(Sym.DOUBLE);
keywords.add(Sym.ELSE);
keywords.add(Sym.ENUM);
keywords.add(Sym.EXTENDS);
keywords.add(Sym.FINAL);
keywords.add(Sym.FINALLY);
keywords.add(Sym.FLOAT);
keywords.add(Sym.FOR);
keywords.add(Sym.GOTO);
keywords.add(Sym.IF);
keywords.add(Sym.IMPLEMENTS);
keywords.add(Sym.IMPORT);
keywords.add(Sym.INSTANCEOF);
keywords.add(Sym.INT);
keywords.add(Sym.INTERFACE);
keywords.add(Sym.LONG);
keywords.add(Sym.NATIVE);
keywords.add(Sym.NEW);
keywords.add(Sym.PACKAGE);
keywords.add(Sym.PRIVATE);
keywords.add(Sym.PROTECTED);
keywords.add(Sym.PUBLIC);
keywords.add(Sym.RETURN);
keywords.add(Sym.SHORT);
keywords.add(Sym.STATIC);
keywords.add(Sym.STRICTFP);
keywords.add(Sym.SUPER);
keywords.add(Sym.SWITCH);
keywords.add(Sym.SYNCHRONIZED);
keywords.add(Sym.THIS);
keywords.add(Sym.THROW);
keywords.add(Sym.THROWS);
keywords.add(Sym.TRANSIENT);
keywords.add(Sym.TRY);
keywords.add(Sym.VOID);
keywords.add(Sym.VOLATILE);
keywords.add(Sym.WHILE);
}
public boolean isKeyword() {
if (s != null)
return keywords.contains(s.sym);
return false;
}
public JavaSymbol(Symbol s) {
this.s = s;
}
public boolean isEOF() {
return getSymbolId() == Sym.EOF;
}
}
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
}
......
......@@ -25,12 +25,17 @@ import de.in.tum.www2.cup.CupSymbol;
import de.in.tum.www2.cup.Declarations;
import de.in.tum.www2.cup.NoopErrorReporter;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.internal.sym;
import de.in.tum.www2.java.JavaScanner;
import de.in.tum.www2.java.JavaSymbol;
import de.tum.in.www2.cupplugin.model.CupParserASTChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
CupTextEditor editor;
private static final int AUTO_ACTIVATION_DELAY = 500;
public CupSourceViewerConfiguration(CupTextEditor editor) {
this.editor = editor;
}
......@@ -50,7 +55,7 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
IDocument.DEFAULT_CONTENT_TYPE);
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setAutoActivationDelay(AUTO_ACTIVATION_DELAY);
assistant
.setProposalPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
assistant
......@@ -60,19 +65,17 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
public class DeclarationPresentationObserver implements CupParserASTChangeObserver
{
private TokenScanner tokenScanner;
private CupTokenScanner tokenScanner;
private ISourceViewer sourceViewer;
public DeclarationPresentationObserver(
TokenScanner tokenScanner,
CupTokenScanner tokenScanner,
ISourceViewer sourceViewer) {
this.tokenScanner = tokenScanner;
this.sourceViewer = sourceViewer;
// TODO: correct to get the doc like that?
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Model model = Model.getInstanceForDocument(doc);
Model model = editor.getModel();
model.registerModelObserver(this);
// TODO: this model will likely be empty on first call?!
......@@ -101,13 +104,13 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
public PresentationReconciler getPresentationReconciler(
ISourceViewer sourceViewer) {
PresentationReconciler pr = new PresentationReconciler();
TokenScanner tokenScanner = new TokenScanner();
CupTokenScanner cupTokenScanner = new CupTokenScanner();
// will observe new declarations and trigger rescan of document
new DeclarationPresentationObserver(tokenScanner, sourceViewer);
CupDamagerRepairer cupDamagerRepairer = new CupDamagerRepairer(tokenScanner);
new DeclarationPresentationObserver(cupTokenScanner, sourceViewer);
CupDamagerRepairer cupDamagerRepairer = new CupDamagerRepairer(cupTokenScanner);
pr.setRepairer(cupDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
pr.setDamager(cupDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
......@@ -127,6 +130,8 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
pr.setDamager(sLCommentDamagerRepairer,
CupPartionScanner.SINGLE_COMMENT);
JavaTokenScanner javaTokenScanner = new JavaTokenScanner();
// DefaultDamagerRepairer javaCommentDamagerRepairer = new
// DefaultDamagerRepairer(new SingleTokenScanner(new
// TextAttribute(CupTextEditor.KEYWORD)));
......@@ -135,19 +140,67 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
// CupPartionScanner.JAVA_CODE);
// pr.setDamager(javaCommentDamagerRepairer,
// CupPartionScanner.JAVA_CODE);
// JavaColorProvider provider = new JavaColorProvider();
// DefaultDamagerRepairer javaDamagerRepairer = new
// DefaultDamagerRepairer(new JavaCodeScanner(provider));
// pr.setRepairer(javaDamagerRepairer, CupPartionScanner.JAVA_CODE);
// pr.setDamager(javaDamagerRepairer, CupPartionScanner.JAVA_CODE);
CupDamagerRepairer javaDamagerRepairer = new CupDamagerRepairer(javaTokenScanner);
pr.setRepairer(javaDamagerRepairer, CupPartionScanner.JAVA_CODE);
pr.setDamager(javaDamagerRepairer, CupPartionScanner.JAVA_CODE);
return pr;
}
static class JavaTokenScanner implements ITokenScanner {
private JavaScanner scanner;
private JavaSymbol last;
private int offset;
public JavaTokenScanner () {
}
public void setRange(IDocument document, int offset, int length) {
StringReader reader = new StringReader(document.get().substring(
offset, offset + length));
scanner = new JavaScanner(reader);
this.last = null;
this.offset = offset;
}
static final Token javaKeyword = new Token(new TextAttribute(
CupTextEditor.JAVA_KEYWORD));
public IToken nextToken() {
try {
last = scanner.next_token();
} catch (IOException e) {
last = null;
return Token.EOF;
}
if (last.isEOF())
return Token.EOF;
if (last.isKeyword())
return javaKeyword;
return Token.UNDEFINED;
}
public int getTokenOffset() {
return this.offset + (last.getLeft());
}