Commit df2abecc authored by Johannes Roith's avatar Johannes Roith

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

parents 8b68d701 59387227
......@@ -3,12 +3,6 @@ package de.tum.in.www2.cupplugin.editors;
import java.util.ArrayList;
import java.util.List;
import javax.swing.text.Document;
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
import org.eclipse.jdt.internal.ui.text.java.JavaContentAssistHandler;
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocCompletionProcessor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
......@@ -18,9 +12,7 @@ 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;
import de.in.tum.www2.cup.Declarations;
import de.in.tum.www2.cup.analysis.DeclarationsExtractorVisitor;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.model.*;
......@@ -37,9 +29,12 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
Model model = Model.getInstanceForDocument(doc);
updateFromParserResult(model.getAstModel());
model.registerModelObserver(this);
// TODO: de-register on dispose!
}
private void updateFromParserResult(ParserResult result) {
System.out.println("CupContentAssistProcessor DECLARATIONS UPDATED!");
if (result == null)
......@@ -94,8 +89,9 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
return proposals.toArray(new CompletionProposal[0]);
}
String myWord = getWordatPosition(viewer, offset);
String myWord = getWordTillPosition(viewer, offset);
String myFullWord = getWordFromPosition(viewer,offset);
List<CompletionProposal> proposals = new ArrayList<CompletionProposal>();
if (myWord.length() >= 1) {
System.out.println(myWord.substring(myWord.length() - 1,
......@@ -121,7 +117,7 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
&& nonTerminalName.substring(0, myWord.length())
.equals(myWord)))) {
proposals.add(new CompletionProposal(nonTerminalName,
offset - myWord.length(), myWord.length(),
offset - myWord.length(), myFullWord.length(),
nonTerminalName.length()));
}
......@@ -131,7 +127,7 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
&& terminalName.substring(0, myWord.length() - 1)
.equals(myWord)))) {
proposals.add(new CompletionProposal(terminalName,
offset - myWord.length(), myWord.length(),
offset - myWord.length(), myFullWord.length(),
terminalName.length()));
}
......@@ -148,7 +144,33 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
}
private String getWordatPosition(ITextViewer viewer, int offset) {
private String getWordFromPosition(ITextViewer viewer, int offset) {
IDocument doc = viewer.getDocument();
String aWord = getWordTillPosition(viewer, offset);
if(aWord.equals("")){
return aWord;
}
try {
char aChar = doc.getChar(offset);
if (Character.isWhitespace(aChar)) {
return aWord;
}
while (!Character.isWhitespace(aChar)) {
aWord = aChar + aWord;
aChar = doc.getChar(++offset);
}
return aWord;
} catch (BadLocationException e) {
System.err
.println("Bad position [CupContentAssistProcessor.getWordatPosition]");
return aWord;
}
}
private String getWordTillPosition(ITextViewer viewer, int offset) {
offset--;
IDocument doc = viewer.getDocument();
try {
......
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