mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xtext][contentAssist] Fixed and more tests for parameterized rules
This commit is contained in:
parent
68b8a035af
commit
69ffc7a3bd
1 changed files with 30 additions and 8 deletions
|
@ -45,6 +45,9 @@ import com.google.common.collect.Lists;
|
|||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/*
|
||||
* Initially copied from org.eclipse.xtext.ui.editor.contentassist.antlr.internal.AbstractInternalContentAssistParser
|
||||
*/
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
|
@ -111,6 +114,7 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
protected final List<EObject> grammarElements;
|
||||
protected final List<EObject> localTrace;
|
||||
protected final List<Integer> paramStack;
|
||||
protected final List<Integer> grammarElementsWithParams;
|
||||
protected int stackSize;
|
||||
protected final Set<FollowElement> followElements;
|
||||
protected ObservableXtextTokenStream.StreamListener delegate;
|
||||
|
@ -136,6 +140,7 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
this.grammarElements = new ArrayList<EObject>();
|
||||
this.localTrace = new ArrayList<EObject>();
|
||||
this.paramStack = new ArrayList<Integer>();
|
||||
this.grammarElementsWithParams = new ArrayList<Integer>();
|
||||
this.followElements = new LinkedHashSetWithoutNull<FollowElement>();
|
||||
}
|
||||
|
||||
|
@ -145,6 +150,7 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
this.localTrace = new ArrayList<EObject>();
|
||||
this.followElements = new LinkedHashSetWithoutNull<FollowElement>();
|
||||
this.paramStack = new ArrayList<Integer>();
|
||||
this.grammarElementsWithParams = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,17 +184,20 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
public void before(EObject grammarElement, int paramConfig) {
|
||||
before(grammarElement);
|
||||
paramStack.add(paramConfig);
|
||||
grammarElementsWithParams.add(stackSize);
|
||||
}
|
||||
|
||||
public void after(EObject grammarElement, int paramConfig) {
|
||||
int old = paramStack.remove(paramStack.size() - 1);
|
||||
int old = removeLast(paramStack);
|
||||
if (old != paramConfig) {
|
||||
throw new IllegalStateException(paramConfig + "!=" + old);
|
||||
}
|
||||
removeLast(grammarElementsWithParams);
|
||||
after(grammarElement);
|
||||
}
|
||||
|
||||
public void after(EObject grammarElement) {
|
||||
EObject foundGrammarElement = grammarElements.remove(grammarElements.size() - 1);
|
||||
EObject foundGrammarElement = removeLast(grammarElements);
|
||||
if (grammarElement != foundGrammarElement)
|
||||
throw new IllegalStateException("expected element: '" + grammarElement + "', but was: '"
|
||||
+ foundGrammarElement + "'");
|
||||
|
@ -219,8 +228,24 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
}
|
||||
|
||||
private void removeUnexpectedElements() {
|
||||
while (stackSize < grammarElements.size())
|
||||
grammarElements.remove(grammarElements.size() - 1);
|
||||
int dropParamAt = -1;
|
||||
if (!grammarElementsWithParams.isEmpty()) {
|
||||
dropParamAt = grammarElementsWithParams.get(grammarElementsWithParams.size() - 1);
|
||||
}
|
||||
while (stackSize < grammarElements.size()) {
|
||||
removeLast(grammarElements);
|
||||
if (dropParamAt == grammarElements.size()) {
|
||||
removeLast(paramStack);
|
||||
removeLast(grammarElementsWithParams);
|
||||
if (!grammarElementsWithParams.isEmpty()) {
|
||||
dropParamAt = grammarElementsWithParams.get(grammarElementsWithParams.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T removeLast(List<T> list) {
|
||||
return list.remove(list.size() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -679,10 +704,7 @@ public abstract class AbstractInternalContentAssistParser extends Parser impleme
|
|||
public void setStrict(boolean strict) {
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
|
||||
protected static short[][] unpackEncodedStringArray(String[] arr) {
|
||||
int numStates = arr.length;
|
||||
short[][] result = new short[numStates][];
|
||||
|
|
Loading…
Reference in a new issue