use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project n4js by eclipse.
the class PatchedFollowElementComputer method computeFollowElements.
@Override
protected void computeFollowElements(FollowElementCalculator calculator, FollowElement element, Multimap<Integer, List<AbstractElement>> visited) {
List<AbstractElement> currentState = Lists.newArrayList(element.getLocalTrace());
currentState.add(element.getGrammarElement());
if (!visited.put(element.getLookAhead(), currentState))
return;
if (element.getLookAhead() <= 1) {
for (AbstractElement abstractElement : currentState) {
Assignment ass = EcoreUtil2.getContainerOfType(abstractElement, Assignment.class);
if (ass != null)
calculator.doSwitch(ass);
else {
if (abstractElement instanceof UnorderedGroup && abstractElement == element.getGrammarElement()) {
calculator.doSwitch((UnorderedGroup) abstractElement, element.getHandledUnorderedGroupElements());
} else {
calculator.doSwitch(abstractElement);
if (GrammarUtil.isOptionalCardinality(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (idx == group.getElements().size() - 1) {
if (!currentState.contains(group) && GrammarUtil.isMultipleCardinality(group)) {
calculator.doSwitch(group);
}
} else if (idx < group.getElements().size() - 1 && "?".equals(abstractElement.getCardinality())) {
// loops are fine
AbstractElement nextElement = group.getElements().get(idx + 1);
if (!currentState.contains(nextElement)) {
calculator.doSwitch(nextElement);
}
}
}
} else if (isAlternativeWithEmptyPath(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (!currentState.contains(group) && idx != group.getElements().size() - 1) {
AbstractElement next = group.getElements().get(idx + 1);
if (!currentState.contains(next)) {
calculator.doSwitch(next);
}
}
}
}
}
}
}
// we need a synthetic rule call
if (element.getTrace().equals(element.getLocalTrace())) {
ParserRule parserRule = GrammarUtil.containingParserRule(element.getGrammarElement());
if (parserRule != null) {
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
ruleCall.setRule(parserRule);
calculator.doSwitch(ruleCall);
}
}
return;
}
Collection<FollowElement> followElements = parser.getFollowElements(element);
for (FollowElement newElement : followElements) {
if (newElement.getLookAhead() != element.getLookAhead() || newElement.getGrammarElement() != element.getGrammarElement()) {
if (newElement.getLookAhead() == element.getLookAhead()) {
int originalTraceSize = element.getLocalTrace().size();
List<AbstractElement> newTrace = newElement.getLocalTrace();
if (newTrace.size() > originalTraceSize) {
if (Collections.indexOfSubList(element.getLocalTrace(), newTrace.subList(originalTraceSize, newTrace.size())) != -1) {
continue;
}
}
}
computeFollowElements(calculator, newElement, visited);
}
}
}
use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project n4js by eclipse.
the class ContentAssistContextFactory method handleLastCompleteNodeIsAtEndOfDatatypeNode.
@Override
protected void handleLastCompleteNodeIsAtEndOfDatatypeNode() {
String prefix = getPrefix(lastCompleteNode);
INode previousNode = getLastCompleteNodeByOffset(rootNode, lastCompleteNode.getOffset());
EObject previousModel = previousNode.getSemanticElement();
INode currentDatatypeNode = getContainingDatatypeRuleNode(currentNode);
Collection<FollowElement> followElements = getParser().getFollowElements(rootNode, 0, lastCompleteNode.getOffset(), true);
int prevSize = contextBuilders.size();
doCreateContexts(previousNode, currentDatatypeNode, prefix, previousModel, followElements);
if (lastCompleteNode instanceof ILeafNode && lastCompleteNode.getGrammarElement() == null && contextBuilders.size() != prevSize) {
handleLastCompleteNodeHasNoGrammarElement(contextBuilders.subList(prevSize, contextBuilders.size()), previousModel);
}
}
use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project n4js by eclipse.
the class ContentAssistContextFactory method handleLastCompleteNodeAsPartOfDatatypeNode.
@Override
protected void handleLastCompleteNodeAsPartOfDatatypeNode() {
String prefix = getPrefix(datatypeNode);
Collection<FollowElement> followElements = getParser().getFollowElements(rootNode, 0, datatypeNode.getOffset(), true);
INode lastCompleteNodeBeforeDatatype = getLastCompleteNodeByOffset(rootNode, datatypeNode.getTotalOffset());
doCreateContexts(lastCompleteNodeBeforeDatatype, datatypeNode, prefix, currentModel, followElements);
}
Aggregations