Java Code Examples for org.eclipse.xtext.GrammarUtil#isMultipleCardinality()
The following examples show how to use
org.eclipse.xtext.GrammarUtil#isMultipleCardinality() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseContentAssistParser.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) { EObject grammarElement = entryPoint.getGrammarElement(); if (grammarElement instanceof RuleCall) { AbstractRule rule = ((RuleCall) grammarElement).getRule(); if (rule instanceof ParserRule) { if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) { grammarElement = rule.getAlternatives(); } } } else if (grammarElement instanceof ParserRule) { grammarElement = ((ParserRule) grammarElement).getAlternatives(); } else if (grammarElement instanceof CrossReference) { grammarElement = GrammarUtil.containingAssignment(grammarElement); } AbstractElement result = (AbstractElement) grammarElement; if (result instanceof Action) { return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild()); } return result; }
Example 2
Source File: EntryPointFinder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected boolean shouldUseParent(ICompositeNode result, int offset, ILeafNode leaf) { if (leaf.getTotalEndOffset() == offset) { return true; } if (result.getGrammarElement() instanceof RuleCall) { RuleCall rc = (RuleCall) result.getGrammarElement(); if (!rc.getArguments().isEmpty()) { return true; } Assignment assignment = GrammarUtil.containingAssignment(rc); if (assignment != null && (GrammarUtil.isMultipleCardinality(assignment) || (assignment.eContainer() instanceof AbstractElement && GrammarUtil .isMultipleCardinality((AbstractElement) assignment.eContainer())))) { return true; } } return false; }
Example 3
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public Boolean caseKeyword(Keyword object) { boolean result = false; String value = object.getValue(); OUTER: do { if (input.getOffset() + value.length() > input.length()) break OUTER; if (value.equals(input.subSequence(input.getOffset(), input.getOffset() + value.length()).toString())) { input.incOffset(value.length()); result = true; continue OUTER; } break OUTER; } while(GrammarUtil.isMultipleCardinality(object)); return result || GrammarUtil.isOptionalCardinality(object); }
Example 4
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public Boolean caseNegatedToken(NegatedToken object) { boolean result = false; OUTER: do { if (eof()) break OUTER; IMarker marker = markerFactory.mark(); if (!doSwitch(object.getTerminal())) { result = true; input.incOffset(); continue OUTER; } marker.rollback(); break OUTER; } while(GrammarUtil.isMultipleCardinality(object)); return result || GrammarUtil.isOptionalCardinality(object); }
Example 5
Source File: CallHierarchyHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseRuleCall(RuleCall object) { if (!checkFurther(object)) return result; if (doSwitch(object.getRule())) return true; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; if (doSwitch(object.getRule())) return true; } return Boolean.FALSE; }
Example 6
Source File: OverriddenValueInspector.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAssignment(Assignment object) { if (GrammarUtil.isMultipleAssignment(object)) return Boolean.FALSE; checkAssignment(object, object.getFeature()); if (GrammarUtil.isMultipleCardinality(object)) checkAssignment(object, object.getFeature()); return Boolean.FALSE; }
Example 7
Source File: CallHierarchyHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAlternatives(Alternatives object) { if (!checkFurther(object)) return result; if (caseAlternatives(object.getElements())) return true; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; return caseAlternatives(object.getElements()); } return Boolean.FALSE; }
Example 8
Source File: ParserBasedContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseCrossReference(CrossReference object) { if (!checkFurther(object)) return result; if (doSwitch(object.getTerminal())) return true; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; if (doSwitch(object.getTerminal())) return true; } return Boolean.FALSE; }
Example 9
Source File: CallHierarchyHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAbstractElement(AbstractElement object) { if (!checkFurther(object)) return result; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; } return Boolean.FALSE; }
Example 10
Source File: ParserBasedContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAbstractElement(AbstractElement object) { if (!checkFurther(object)) return result; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; } return Boolean.FALSE; }
Example 11
Source File: ParserBasedContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAlternatives(Alternatives object) { if (!checkFurther(object)) return result; if (caseAlternatives(object.getElements())) return true; if (GrammarUtil.isMultipleCardinality(object)) { if (!checkFurther(object)) return result; return caseAlternatives(object.getElements()); } return Boolean.FALSE; }
Example 12
Source File: Xtext2RailroadFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected ISegmentFigure wrapCardinalitySegments(AbstractElement element, ISegmentFigure segment) { ISegmentFigure result = segment; if (GrammarUtil.isMultipleCardinality(element)) { result = new LoopSegment(element, result, primitiveFactory); } if (GrammarUtil.isOptionalCardinality(element)) { result = new BypassSegment(element, result, primitiveFactory); } return result; }
Example 13
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseUntilToken(UntilToken object) { if (GrammarUtil.isOptionalCardinality(object) || GrammarUtil.isMultipleCardinality(object)) throw new IllegalStateException("cardinality has to be default for until tokens"); IMarker marker = markerFactory.mark(); while (!eof()) { if (doSwitch(object.getTerminal())) { return true; } input.incOffset(); } marker.rollback(); return false; }
Example 14
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseRuleCall(RuleCall object) { boolean result = false; OUTER: do { if (doSwitch(object.getRule())) { result = true; continue OUTER; } break OUTER; } while(GrammarUtil.isMultipleCardinality(object)); return result || GrammarUtil.isOptionalCardinality(object); }
Example 15
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseWildcard(Wildcard object) { boolean result = false; OUTER: do { if (eof()) break OUTER; input.incOffset(); result = true; continue OUTER; } while(GrammarUtil.isMultipleCardinality(object)); return result || GrammarUtil.isOptionalCardinality(object); }
Example 16
Source File: BaseContentAssistParser.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.14 */ protected Collection<FE> getFollowElements(final InternalParser parser, final AbstractElement elementToParse, String[] ruleNames, final int startIndex) { try { EofListener listener = createEofListener(parser, elementToParse); int i = startIndex; Collection<FE> result = null; while (i < ruleNames.length && !listener.wasEof && listener.consumedSomething) { listener.reset(); String ruleName = ruleNames[i]; result = getFollowElements(parser, ruleName, true); if (i == ruleNames.length - 1 && !GrammarUtil.isMultipleCardinality(elementToParse)) { if (listener.consumedSomething || listener.announcedEofWithLA) return result; return Collections.emptyList(); } if (!listener.wasEof && ruleNames.length != 1) i++; if (ruleNames.length > 2) throw new IllegalArgumentException( "The following lines assume that we have at most two rules to call."); } return result; } catch (Exception e) { throw new RuntimeException(e); } }
Example 17
Source File: TerminalRuleInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean caseAlternatives(Alternatives object) { boolean result = false; OUTER: do { for (AbstractElement element: object.getElements()) { if (doSwitch(element)) { result = true; continue OUTER; } } break OUTER; } while(GrammarUtil.isMultipleCardinality(object)); return result || GrammarUtil.isOptionalCardinality(object); }
Example 18
Source File: ParamAwareEntryPointFinder.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean isMultipleCardinality(AbstractElement e) { if (GrammarUtil.isMultipleCardinality(e)) { return true; } if (e.eContainer() instanceof AbstractElement) { return isMultipleCardinality((AbstractElement) e.eContainer()); } return false; }
Example 19
Source File: CfgAdapter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public boolean isMany(AbstractElement ele) { return GrammarUtil.isMultipleCardinality(ele); }
Example 20
Source File: AbstractNFAState.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void collectOutgoing(AbstractElement element, Set<AbstractElement> visited, boolean isRuleCall, AbstractElement loopCenter) { if (element instanceof Group || element instanceof UnorderedGroup) { List<AbstractElement> elements = ((CompoundElement) element).getElements(); switch (builder.getDirection()) { case FORWARD: int j = 0; while (j < elements.size()) { addOutgoing(elements.get(j), visited, isRuleCall, loopCenter); if (!GrammarUtil.isOptionalCardinality(elements.get(j))) break; j++; } // add transitions to the next sibling of this element if all children are optional if (j >= elements.size()) collectOutgoingByContainer(element, visited, isRuleCall, loopCenter); break; case BACKWARD: int i = elements.size() - 1; while (i >= 0) { addOutgoing(elements.get(i), visited, isRuleCall, loopCenter); if (!GrammarUtil.isOptionalCardinality(elements.get(i))) break; i--; } // add transitions to the next sibling of this element if all children are optional if (i < 0) collectOutgoingByContainer(element, visited, isRuleCall, loopCenter); break; } } else if (element instanceof Alternatives) { boolean hasOptional = false; for (AbstractElement e : ((Alternatives) element).getElements()) { hasOptional |= GrammarUtil.isOptionalCardinality(e); addOutgoing(e, visited, isRuleCall, loopCenter); } if (hasOptional) collectOutgoingByContainer(element, visited, isRuleCall, loopCenter); } else if (element instanceof Assignment) addOutgoing(((Assignment) element).getTerminal(), visited, isRuleCall, loopCenter); else if (element instanceof CrossReference) addOutgoing(((CrossReference) element).getTerminal(), visited, isRuleCall, loopCenter); else if (GrammarUtil.isEObjectRuleCall(element)) { addOutgoing(((RuleCall) element).getRule().getAlternatives(), visited, true, loopCenter); collectOutgoingByContainer(element, visited, isRuleCall, loopCenter); } else { if (GrammarUtil.isMultipleCardinality(element) && !filter(element)) addOutgoing(element, visited, isRuleCall, element); collectOutgoingByContainer(element, visited, isRuleCall, loopCenter); } }