Commit 6298321d authored by petter's avatar petter

first draft for a context sensitive Content-Assist - missing examples for tokens.....

parent 087902b5
......@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.jface.text,
org.eclipse.jface.text.contentassist,
org.eclipse.jface.text.hyperlink,
org.eclipse.jface.text.presentation,
org.eclipse.jface.text.rules,
......
package mjplugin.ast;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jface.text.Position;
......@@ -23,4 +27,11 @@ public class MiniJavaAST {
public List<Position> getCollapsables(){
return collapsables;
}
public Collection<Identifier> getIdentifiers() {
Set<Identifier> ids = new HashSet<>();
for (Decl decl: bindings.values()) {
ids.addAll(decl.varlist);
}
return ids;
}
}
......@@ -13,7 +13,16 @@ import miniparser.InMemoryParser.IFrontendObserver;
public class GUIErrorReporter implements IFrontendObserver {
private static final String MINIJAVA_MARKER = "minijava.problem";
public static class Expectation {
public Expectation(Location left, Location right, List expected) {
this.expected = expected;
this.left = left;
this.right = right;
}
public List expected;
public Location left, right;
}
public static class Message {
public Message(String message, Location left, Location right) {
this.message = message;
......@@ -26,6 +35,7 @@ public class GUIErrorReporter implements IFrontendObserver {
}
private List<Message> errors = new LinkedList<>();
private List<Expectation> expectations = new LinkedList<>();
private IFile file;
public void commitErrors() {
......@@ -60,8 +70,11 @@ public class GUIErrorReporter implements IFrontendObserver {
}
@Override
public void report(String message, Location left, Location right, List expect) {
public void report(String message, Location left, Location right, List expectedTokens) {
errors.add(new Message(message, left, right));
if (expectedTokens!=null){
expectations.add(new Expectation(left,right,expectedTokens));
}
}
@Override
......
package mjplugin.editors;
import java.util.LinkedList;
import java.util.List;
import minijava.Expr.Identifier;
import mjplugin.model.Model;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
public class MJContentAssistProcessor implements IContentAssistProcessor{
private Model model;
public MJContentAssistProcessor(Model instanceForDocument) {
this.model=instanceForDocument;
}
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
List<CompletionProposal> completions = new LinkedList<>();
for (Identifier id : model.getAstModel().getIdentifiers()){
completions.add(new CompletionProposal(id.i,offset,0,id.i.length()));
}
completions.add(new CompletionProposal("while",offset,0,"while".length()));
completions.add(new CompletionProposal("if",offset,0,"if".length()));
return completions.toArray(new ICompletionProposal[] {});
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
// TODO Auto-generated method stub
return null;
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer,int offset) {
return null;
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}
......@@ -9,9 +9,13 @@ import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.Symbol;
import miniparser.Lexer;
import miniparser.sym;
import mjplugin.model.Model;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
import org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter;
......@@ -36,7 +40,15 @@ public class MJSourceViewerConfiguration extends SourceViewerConfiguration {
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new MJHyperlinkDetector(editor) };
}
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistant assistant = new ContentAssistant();
IContentAssistProcessor processor = new MJContentAssistProcessor(Model.getInstanceForDocument(editor.getDocument()));
assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
assistant.setAutoActivationDelay(500);
assistant.enableAutoActivation(true);
return assistant;
}
public MJSourceViewerConfiguration(MJEditor mjEditor) {
this.editor=mjEditor;
......
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