Java Code Examples for org.eclipse.xtext.GrammarUtil#isEObjectRuleCall()

The following examples show how to use org.eclipse.xtext.GrammarUtil#isEObjectRuleCall() . 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: SemanticNodeIterator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected Triple<INode, AbstractElement, EObject> findNext(INode node, boolean prune) {
	INode current = next(node, prune);
	while (current != null) {
		if (current instanceof ILeafNode && ((ILeafNode) current).isHidden()) {
			current = next(current, true);
			continue;
		}
		EObject ge = current.getGrammarElement();
		if (ge instanceof AbstractElement && isEObjectNode(current))
			return Tuples.create(current, (AbstractElement) ge, getEObjectNodeEObject(current));
		else if (GrammarUtil.isAssigned(ge) && !GrammarUtil.isEObjectRuleCall(ge)) {
			if (ge instanceof CrossReference)
				return Tuples.create(current, ((CrossReference) ge).getTerminal(), null);
			else
				return Tuples.create(current, (AbstractElement) ge, null);
		} else
			current = next(current, false);
	}
	return null;
}
 
Example 2
Source File: TokenUtil.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public EObject getTokenOwner(INode node) {
	if (node.hasDirectSemanticElement())
		return node.getSemanticElement();
	if (node.getParent() != null) {
		if (node.getParent().hasDirectSemanticElement())
			return node.getParent().getSemanticElement();
		EObject parentGrammarElement = node.getParent().getGrammarElement();
		boolean isParser = GrammarUtil.isEObjectRule(parentGrammarElement) || GrammarUtil.isEObjectRuleCall(parentGrammarElement);
		for (INode sibling : node.getParent().getChildren())
			if (sibling.hasDirectSemanticElement() && (isParser || sibling.getGrammarElement() instanceof Action))
				return sibling.getSemanticElement();
	}
	return node.getSemanticElement();
}
 
Example 3
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getToken(RuleCall rc, Object value, INode node) {
	CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
	Assignment assignment = GrammarUtil.containingAssignment(rc);
	if (crossRef != null)
		return provider.crossRefSerializer.serializeCrossRef(semanticObject, crossRef, (EObject) value, node,
				errorAcceptor);
	else if (GrammarUtil.isEObjectRuleCall(rc) || GrammarUtil.isBooleanAssignment(assignment))
		return null;
	else if (GrammarUtil.isEnumRuleCall(rc))
		return provider.enumLiteralSerializer.serializeAssignedEnumLiteral(semanticObject, rc, value, node,
				errorAcceptor);
	else
		return provider.valueSerializer.serializeAssignedValue(semanticObject, rc, value, node, errorAcceptor);
}
 
Example 4
Source File: GrammarPDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AbstractElement getCall(AbstractElement ele) {
	if (GrammarUtil.isEObjectRuleCall(ele) && !GrammarUtil.isAssigned(ele)) {
		return ((RuleCall) ele).getRule().getAlternatives();
	}
	return null;
}
 
Example 5
Source File: SerializerFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isUnassignedRuleCall(final RuleCall c) {
  boolean _isEObjectRuleCall = GrammarUtil.isEObjectRuleCall(c);
  if (_isEObjectRuleCall) {
    return false;
  }
  final Assignment ass = GrammarUtil.containingAssignment(c);
  return ((ass == null) || GrammarUtil.isBooleanAssignment(ass));
}
 
Example 6
Source File: TreeConstState.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isConsumingElement() {
	return element instanceof Assignment
			|| GrammarUtil.isEObjectRuleCall(element)
			|| element instanceof Action;
}
 
Example 7
Source File: AbstractNFAState.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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);
	}
}
 
Example 8
Source File: MatcherState.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isParserRuleCall() {
	return GrammarUtil.isEObjectRuleCall(element);
}