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

The following examples show how to use org.eclipse.xtext.GrammarUtil#isAssigned() . 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: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkRuleCallInUnorderedGroup(final RuleCall call) {
	if (call.getRule() == null || call.getRule().eIsProxy() || !(call.getRule() instanceof ParserRule))
		return;
	if (GrammarUtil.isDatatypeRule((ParserRule) call.getRule()))
		return;
	if (GrammarUtil.isAssigned(call))
		return;
	if (EcoreUtil2.getContainerOfType(call, UnorderedGroup.class) != null)
		error(
				"Unassigned rule calls may not be used in unordered groups.", 
				call, 
				null,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				null);
}
 
Example 2
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 3
Source File: SemanticNodeIterator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isEObjectNode(INode node) {
	if (node.getGrammarElement() instanceof AbstractRule)
		return true;
	if (node.getGrammarElement() instanceof Action)
		return true;
	if (GrammarUtil.isAssignedEObjectRuleCall(node.getGrammarElement())) {
		if (node.hasDirectSemanticElement())
			return true;
		AbstractRule rule = ((RuleCall) node.getGrammarElement()).getRule();
		node = node.getParent();
		while (node != null) {
			if (GrammarUtil.isAssigned(node.getGrammarElement()))
				return true;
			if (node.getGrammarElement() instanceof Action
					&& GrammarUtil.containingRule(node.getGrammarElement()) == rule)
				return false;
			node = node.getParent();
		}
		return true;
	}
	return false;
}
 
Example 4
Source File: ContextTypePDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EClass getInstantiatedType(AbstractElement element) {
	TypeRef type = null;
	if (GrammarUtil.isAssigned(element) || GrammarUtil.isEObjectFragmentRuleCall(element)) {
		type = GrammarUtil.containingRule(element).getType();
	} else if (element instanceof Action) {
		type = ((Action) element).getType();
	}
	if (type != null) {
		EClassifier classifier = type.getClassifier();
		if (classifier instanceof EClass && !classifier.eIsProxy()) {
			return (EClass) classifier;
		}
	}
	return null;
}
 
Example 5
Source File: SyntacticSequencerPDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isMandatoryAbsorber(AbstractElement ele) {
	if (ele == null)
		return true;
	if (GrammarUtil.isAssigned(ele))
		return true;
	if (GrammarUtil.isAssignedAction(ele))
		return true;
	//		if (GrammarUtil.isDatatypeRuleCall(ele))
	//			return true;
	return false;
}
 
Example 6
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 7
Source File: EmitterNodeIterator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isAbsorber(INode node) {
	return node.getGrammarElement() != null && GrammarUtil.isAssigned(node.getGrammarElement());
}
 
Example 8
Source File: EmitterNodeUtil.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean isAbsorber(EObject grammarElement) {
	return grammarElement != null && GrammarUtil.isAssigned(grammarElement);
}
 
Example 9
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String _ebnf2(final Keyword it, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  if ((!supportActions)) {
    _xifexpression = super._ebnf2(it, options, supportActions);
  } else {
    String _xifexpression_1 = null;
    boolean _isAssigned = GrammarUtil.isAssigned(it);
    if (_isAssigned) {
      StringConcatenation _builder = new StringConcatenation();
      String __ebnf2 = super._ebnf2(it, options, supportActions);
      _builder.append(__ebnf2);
      _builder.newLineIfNotEmpty();
      _builder.append("{");
      _builder.newLine();
      _builder.append("\t");
      CharSequence _newLeafNode = this.newLeafNode(it, this._grammarAccessExtensions.localVar(GrammarUtil.containingAssignment(it), it));
      _builder.append(_newLeafNode, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
      _builder.newLine();
      _xifexpression_1 = _builder.toString();
    } else {
      StringConcatenation _builder_1 = new StringConcatenation();
      String _localVar = this._grammarAccessExtensions.localVar(it);
      _builder_1.append(_localVar);
      _builder_1.append("=");
      String __ebnf2_1 = super._ebnf2(it, options, supportActions);
      _builder_1.append(__ebnf2_1);
      _builder_1.newLineIfNotEmpty();
      _builder_1.append("{");
      _builder_1.newLine();
      _builder_1.append("\t");
      CharSequence _newLeafNode_1 = this.newLeafNode(it, this._grammarAccessExtensions.localVar(it));
      _builder_1.append(_newLeafNode_1, "\t");
      _builder_1.newLineIfNotEmpty();
      _builder_1.append("}");
      _builder_1.newLine();
      _xifexpression_1 = _builder_1.toString();
    }
    _xifexpression = _xifexpression_1;
  }
  return _xifexpression;
}