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

The following examples show how to use org.eclipse.xtext.GrammarUtil#isEObjectRule() . 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: 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 2
Source File: AbstractNFAState.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<T> getAllIncoming() {
	for (Adapter a : element.eResource().eAdapters())
		if (a instanceof IsInitializedMarker && ((IsInitializedMarker) a).builder == builder)
			return getIncoming();
	element.eResource().eAdapters().add(new IsInitializedMarker(builder));
	for (EObject root : element.eResource().getContents())
		if (root instanceof Grammar)
			for (AbstractRule rule : ((Grammar) root).getRules())
				if (GrammarUtil.isEObjectRule(rule))
					for (AbstractElement ele : EcoreUtil2.eAllOfType(rule, AbstractElement.class))
						if (!builder.filter(ele))
							builder.getState(ele).getOutgoing();
	return getIncoming();
}
 
Example 3
Source File: Context2NameFunction.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public String getContextName(Grammar grammar, EObject ctx) {
	if (GrammarUtil.isEObjectRule(ctx))
		return getContextName(grammar, (ParserRule) ctx);
	if (GrammarUtil.isAssignedAction(ctx))
		return getContextName(grammar, (Action) ctx);
	throw new RuntimeException("Invalid Context: " + EmfFormatter.objPath(ctx));
}
 
Example 4
Source File: NodeModelStreamer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.0
 */
protected ParserRule findRootRuleForRegion(INode node) {
	if (GrammarUtil.isEObjectRule(node.getGrammarElement()))
		return (ParserRule) node.getGrammarElement();
	if (node.hasDirectSemanticElement())
		return GrammarUtil.containingParserRule(node.getGrammarElement());
	if (node.getParent() != null)
		return findRootRuleForRegion(node.getParent());
	return null;
}
 
Example 5
Source File: AbstractNFAState.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean filter(AbstractElement ele) {
	AbstractRule rule = GrammarUtil.containingRule(ele);
	if (rule == null || !GrammarUtil.isEObjectRule(rule))
		return true;
	return builder.filter(ele);
}
 
Example 6
Source File: ContextFinder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected ISerializationContext getRootContext(EObject sem) {
	for (AbstractRule rule : ruleNames.getAllRules())
		if (GrammarUtil.isEObjectRule(rule))
			return SerializationContext.fromEObject(rule, sem);
	throw new RuntimeException("There is no parser rule in the grammar.");
}
 
Example 7
Source File: GrammarPDAProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isValidRule(ParserRule rule) {
	return GrammarUtil.isEObjectRule(rule) && !rule.isFragment();
}
 
Example 8
Source File: AbstractSemanticRegionsFinder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertNoEObjectRule(AbstractRule rule) {
	if (GrammarUtil.isEObjectRule(rule))
		throw new IllegalStateException("Only Enum, Datatype and Terminal Rule Calls allowed.");
}