Commit a34379e3 authored by Johannes Roith's avatar Johannes Roith

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

parents 98b1d56c 99e9b26d
......@@ -19,11 +19,14 @@ import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.IDisposable;
import de.tum.in.www2.cupplugin.model.*;
public class CupContentAssistProcessor implements IContentAssistProcessor,
public class CupContentAssistProcessor implements IContentAssistProcessor,
IDisposable, ICupParserASTChangeObserver {
private Declarations decls;
private IDocument doc;
/*
* TODO: Find the way to get the Java Code assistant here
*/
private IContentAssistProcessor javaProcessor = null;
public CupContentAssistProcessor(IDocument doc) {
......@@ -33,11 +36,11 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
updateFromParserResult(model.getAstModel());
model.registerModelObserver(this);
}
public void dispose() {
Model.getInstanceForDocument(doc).unregisterModelObserver(this);
}
private void updateFromParserResult(ParserResult result) {
if (result == null)
return;
......@@ -89,8 +92,8 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
}
String myWord = getWordTillPosition(viewer, offset);
String myFullWord = getWordFromPosition(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,
......@@ -107,31 +110,31 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
default:
break;
}
}
if (decls != null) {
for (String nonTerminalName : decls.getNonTerminals())
if (nonTerminalName != null && ((myWord.equals("")) || (
nonTerminalName.length() >= myWord.length()
&& nonTerminalName.substring(0, myWord.length())
.equals(myWord)))) {
proposals.add(new CompletionProposal(nonTerminalName,
offset - myWord.length(), myFullWord.length(),
nonTerminalName.length()));
}
}
for (String terminalName : decls.getTerminals())
if (terminalName != null
&& ((myWord.equals("")) || (terminalName.length() >= myWord.length()
&& terminalName.substring(0, myWord.length() - 1)
.equals(myWord)))) {
proposals.add(new CompletionProposal(terminalName,
offset - myWord.length(), myFullWord.length(),
terminalName.length()));
if (decls != null) {
for (String nonTerminalName : decls.getNonTerminals()) {
if (nonTerminalName != null
&& ((myWord.equals("")) || (nonTerminalName.length() >= myWord
.length() && nonTerminalName.substring(0,
myWord.length()).equals(myWord)))) {
proposals.add(new CompletionProposal(nonTerminalName,
offset - myWord.length(), myFullWord.length(),
nonTerminalName.length()));
}
}
}
for (String terminalName : decls.getTerminals()) {
if (terminalName != null
&& ((myWord.equals("")) || (terminalName.length() >= myWord
.length() && terminalName.substring(0,
myWord.length()).equals(myWord)))) {
proposals.add(new CompletionProposal(terminalName,
offset - myWord.length(), myFullWord.length(),
terminalName.length()));
}
}
}
if (myWord.equals("")
|| (proposals.size() == 1 && proposals.get(0)
......@@ -146,7 +149,7 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
private String getWordFromPosition(ITextViewer viewer, int offset) {
IDocument doc = viewer.getDocument();
String aWord = getWordTillPosition(viewer, offset);
if(aWord.equals("")){
if (aWord.equals("")) {
return aWord;
}
try {
......@@ -166,7 +169,7 @@ public class CupContentAssistProcessor implements IContentAssistProcessor,
return aWord;
}
}
private String getWordTillPosition(ITextViewer viewer, int offset) {
offset--;
IDocument doc = viewer.getDocument();
......
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