Commit b8b3fa9a authored by Johannes Roith's avatar Johannes Roith

- Error reporter is now limited to 1000 messages.

- Added tooltips in the editor.
- Adapted outline to new notification model.
- Various fixes.
parent aa0bd9f6
......@@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.debug;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0"
org.eclipse.ant.core;bundle-version="3.3.0",
org.eclipse.text
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
package de.tum.in.www2.cupplugin.editors;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.eclipse.jface.resource.JFaceResources;
......@@ -33,11 +34,14 @@ import de.in.tum.www2.cup.Utility;
import de.in.tum.www2.cup.analysis.*;
import de.in.tum.www2.cup.ast.*;
import de.in.tum.www2.cup.ast.Package;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.RegisterForControllerChanges;
import de.tum.in.www2.cupplugin.model.*;
// TODO: try changing to IContentOutlinePage and using a virtual view!
public class CupContentOutlinePage extends ContentOutlinePage implements
CupParserASTChangeObserver {
CupParserASTChangeObserver, RegisterForControllerChanges {
private static final int AUTO_EXPAND_L3_MAX_ITEMS = 100;
private static final int AUTO_EXPAND_L2_MAX_ITEMS = 500;
......@@ -49,6 +53,7 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
public CupContentOutlinePage(CupTextEditor editor) {
this.editor = editor;
Controller.getInstance(editor).registerObserver(this);
doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Model.getInstanceForDocument(doc).registerModelObserver(this);
}
......@@ -89,7 +94,12 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
if (root != null)
doJumpToPosition(root, pos);
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
return EnumSet.of(JobsToDo.locationPatch, JobsToDo.parseCode);
}
@Override
public void modelChanged(Model model) {
ParserResult result = model.getAstModel();
......
......@@ -16,6 +16,8 @@ import de.in.tum.www2.cup.Position;
public class CupEditorErrorReporter implements IErrorReporter {
private static final int MAX_DISPLAYED_ERRORS = 1000;
static class BufferedMessage {
public ErrorType errorType;
public ErrorSource source;
......@@ -35,10 +37,29 @@ public class CupEditorErrorReporter implements IErrorReporter {
}
public void pushToUIThread() {
List<BufferedMessage> copy = new ArrayList<BufferedMessage>(lst);
List<BufferedMessage> copy;
if (lst.size() < MAX_DISPLAYED_ERRORS) {
copy = new ArrayList<BufferedMessage>(lst);
} else {
copy = new ArrayList<BufferedMessage> ();
for (int i=0; i < MAX_DISPLAYED_ERRORS; i++)
copy.add(lst.get(i));
BufferedMessage msg = new BufferedMessage();
msg.errorType = ErrorType.Fatal;
msg.source = ErrorSource.Unknown;
msg.errorCode = null;
int removedCount = lst.size() - MAX_DISPLAYED_ERRORS;
msg.message = "TOO MANY ERRORS TO DISPLAY IN IDE. "
+ removedCount + " Errors not shown.";
msg.start = null;
msg.end = null;
copy.add(msg);
}
lst.clear();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
......
......@@ -4,8 +4,12 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
......@@ -51,16 +55,21 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
}
@Override
public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer)
{
public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer) {
return new MultipleHyperlinkPresenter(CupTextEditor.HYPERLINK.getRGB());
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new CupHyperlinkDetector(editor) };
}
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer,
String contentType) {
return new CupTextHover(editor);
}
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistant assistant = new ContentAssistant();
......@@ -88,10 +97,9 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
private JavaTokenScanner javaTokenScanner;
private ISourceViewer sourceViewer;
private boolean updatedFromModelOnce;
public PresentationModelObserver(CupTokenScanner cupTokenScanner,
JavaTokenScanner javaTokenScanner,
ISourceViewer sourceViewer) {
JavaTokenScanner javaTokenScanner, ISourceViewer sourceViewer) {
this.cupTokenScanner = cupTokenScanner;
this.javaTokenScanner = javaTokenScanner;
......@@ -105,13 +113,13 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
if (result != null)
cupTokenScanner.updateDeclarations(result.findDeclarations());
}
@Override
public void modelChanged(Model model) {
ParserResult result = model.getAstModel();
if (result != null) {
javaTokenScanner.updateParserResult(result);
Declarations newDecls = result.findDeclarations();
if (newDecls != null) {
if (!newDecls.equals(cupTokenScanner.getDeclarations())) {
......@@ -140,7 +148,8 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
// will observe new declarations and trigger rescan of document
// also handles changes to declared cup symbols in java blocks.
new PresentationModelObserver(cupTokenScanner, javaTokenScanner, sourceViewer);
new PresentationModelObserver(cupTokenScanner, javaTokenScanner,
sourceViewer);
CupDamagerRepairer cupDamagerRepairer = new CupDamagerRepairer(
cupTokenScanner);
......@@ -178,14 +187,14 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
private JavaSymbol last;
private int offset;
private Range previousCodeBlockRange;
private HashSet<String> currentLabels = null;
public JavaTokenScanner() {
this.currentLabels = new HashSet<String> ();
this.currentLabels = new HashSet<String>();
}
public void updateParserResult(ParserResult result) {
System.out.println("UPDATING PARSER RESULT");
this.ast = result;
......@@ -193,9 +202,9 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
}
private void refreshSpecialSymbols(Position pos) {
// System.out.println("TRYING TO FIND POSITION: " + pos);
// System.out.println("TRYING TO FIND POSITION: " + pos);
this.currentLabels.clear();
AbstractNode node = ast.findAtPosition(pos);
if (node == null)
return;
......@@ -235,11 +244,11 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
if (ast == null) {
this.currentLabels.clear();
} else {
// TODO: we convert offset to line number / position.
// TODO: centralize this type of code, so we have our bugs in
// one place :-)
int line;
int column;
try {
......@@ -253,10 +262,12 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
column += 2; // TODO: adding two here is a hack!
Position pos = new Position(line, column, -1);
if (previousCodeBlockRange != null && previousCodeBlockRange.contains(pos)) {
// the old AST is till valid and we are within the same code block.
if (previousCodeBlockRange != null
&& previousCodeBlockRange.contains(pos)) {
// the old AST is till valid and we are within the same code
// block.
// -> just keep the existing labels.
return;
......@@ -268,10 +279,10 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
static final Token javaComment = new Token(new TextAttribute(
CupTextEditor.COMMENT));
static final Token javaKeyword = new Token(new TextAttribute(
CupTextEditor.JAVA_KEYWORD));
static final Token javaTextualLiteral = new Token(new TextAttribute(
CupTextEditor.JAVA_TEXTUAL));
......@@ -292,21 +303,22 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
if (last.isEOF())
return Token.EOF;
if (last.isComment())
return javaComment;
if (last.isKeyword() || last.isBooleanLiteral() || last.isNullLiteral())
if (last.isKeyword() || last.isBooleanLiteral()
|| last.isNullLiteral())
return javaKeyword;
if (last.isTextualLiteral())
return javaTextualLiteral;
if (last.getValue() instanceof String) {
String lastValueStr = (String) last.getValue();
if (lastValueStr.equals("RESULT")
|| currentLabels.contains(lastValueStr))
return cupDefinedVariable;
if (lastValueStr.equals("RESULT")
|| currentLabels.contains(lastValueStr))
return cupDefinedVariable;
}
return Token.UNDEFINED;
......
package de.tum.in.www2.cupplugin.editors;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.action.IAction;
......@@ -86,7 +87,10 @@ public class CupTextEditor extends TextEditor {
}
public IDocument getDocument() {
return getDocumentProvider().getDocument(getEditorInput());
IDocumentProvider provider = getDocumentProvider();
if (provider != null)
return provider.getDocument(getEditorInput());
return null;
}
// adapted from http://javadude.googlecode.com/svn/trunk/com.javadude.antxr.eclipse.ui/src/com/javadude/antxr/eclipse/ui/editor/AntxrEditor.java
......
package de.tum.in.www2.cupplugin.editors;
import java.util.EnumSet;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.analysis.FindAtPositionVisitor;
import de.in.tum.www2.cup.ast.AbstractNode;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.RegisterForControllerChanges;
import de.tum.in.www2.cupplugin.model.CupParserASTChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupTextHover implements ITextHover,
CupParserASTChangeObserver,
RegisterForControllerChanges {
private AbstractNode prevRequestedNode;
private ParserResult ast;
public CupTextHover (CupTextEditor editor) {
Model model = Model.getInstanceForDocument(editor.getDocument());
model.registerModelObserver(this);
}
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
if (hoverRegion == null)
return null;
if (prevRequestedNode != null) {
if (hoverRegion.getLength() == prevRequestedNode.getRange().getLength()
&& prevRequestedNode.getBegin().getOffsetFromStart() == hoverRegion.getOffset()) {
return prevRequestedNode.toString();
} else {
System.err.println("UNEXPECTED: The hoverRegion does " +
"not match the previously requested getHoverRegion.");
}
}
return null;
}
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
if (this.ast == null)
return null;
System.out.println("offset: " + offset);
// TODO: visiting on every hover is a bit expensive ...
Position pos = Position.fromOffset(offset);
FindAtPositionVisitor visitor = new FindAtPositionVisitor(pos);
this.ast.accept(visitor, null);
AbstractNode result = visitor.getResult();
if (result != null) {
prevRequestedNode = result;
return new Region(result.getBegin().getOffsetFromStart(),
result.getRange().getLength());
}
return null;
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
return EnumSet.of(JobsToDo.locationPatch, JobsToDo.parseCode);
}
@Override
public void modelChanged(Model model) {
System.out.println("MODEL CHANGED!");
this.ast = model.getAstModel();
}
}
......@@ -242,14 +242,13 @@ public class MultiPageEditor extends MultiPageEditorPart implements
}
boolean addHooksToMainTextEditor(ITextEditor editor) {
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
IDocumentProvider dp = editor.getDocumentProvider();
if (dp == null)
return false;
IDocument doc = dp.getDocument(getEditorInput());
if (doc == null)
return false;
doc.addDocumentListener(new CTEDocumentListener(file));
doc.addDocumentListener(new CTEDocumentListener());
if (editor instanceof CupTextEditor) {
if (!Debugger.addDebugHooksToTextEditor((CupTextEditor) editor)) {
......
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