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

The following examples show how to use org.eclipse.xtext.GrammarUtil#isEnumRuleCall() . 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: 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 2
Source File: NodeModelBasedRegionAccessBuilder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean include(INode node) {
	if (node instanceof ILeafNode) {
		return true;
	} else if (node instanceof ICompositeNode) {
		EObject element = node.getGrammarElement();
		return GrammarUtil.isDatatypeRuleCall(element) || element instanceof CrossReference
				|| GrammarUtil.isEnumRuleCall(element);
	}
	return false;
}
 
Example 3
Source File: SyntacticSequencerPDAProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean apply(ISynState input) {
	AbstractElement ge = input.getGrammarElement();
	return ge instanceof Keyword || GrammarUtil.isDatatypeRuleCall(ge) || GrammarUtil.isEnumRuleCall(ge)
			|| GrammarUtil.isTerminalRuleCall(ge);
}
 
Example 4
Source File: ReorderingHiddenTokenSequencer.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Collects all the hidden tokens between two given nodes of the node model.
 *
 * @param from
 *          node that serves as a start point, must not be {@code null}
 * @param to
 *          search end point, must not be {@code null}
 * @param deletedSemanticElements
 *          set of the deleted semantic elements, must not be {@code null}
 * @return list of hidden tokens, never {@code null}, but can be empty
 */
private List<INode> getHiddenTokensBetween(final INode from, final INode to, final Set<EObject> deletedSemanticElements) {
  EObject fromElement = NodeModelUtils.findActualSemanticObjectFor(from);
  if (from.equals(NodeModelUtils.getNode(fromElement))) {
    // If the starting node represents some container, emit the comments that belong to it
    // This is needed to correctly handle some edge cases like ImportList in AvqScript
    // Logic for distinguishing between container's comments and the ones of first element is expected to be implemented in 'isLeadingCommentFor'
    emitContainerComments(from);
  }
  List<INode> result = Lists.newArrayList();
  boolean handleReordering = from.getTotalOffset() > to.getTotalOffset();
  if (!handleReordering) {
    // Elements are not reordered
    // Just going through the interval and collecting comments, unless they have already been emitted
    NodeIterator nodes = new NodeIterator(from);
    while (nodes.hasNext()) {
      INode next = nodes.next();
      if (tokenUtil.isWhitespaceOrCommentNode(next)) {
        if (!emittedComments.contains(next)) {
          result.add(next);
        }
      } else if (next.equals(to)) {
        // We have hit the 'to' node
        // If it is a composite one, we have to iterate through its children
        // and collect whitespaces/comments until we encounter first token (keyword, identifier...)
        if (next instanceof ICompositeNode && (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement())
            || GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference)) {
          while (nodes.hasNext()) {
            INode lastNodeChild = nodes.next();
            if (tokenUtil.isWhitespaceOrCommentNode(lastNodeChild)) {
              if (!emittedComments.contains(lastNodeChild)) {
                result.add(lastNodeChild);
              }
            } else if (lastNodeChild instanceof ILeafNode) {
              break;
            }
          }
          break;
        } else {
          // 'to' node is not a composite one, nothing to do here, just exit the loop
          break;
        }
      } else if (belongsToDeletedElement(next)) {
        handleDeletedElement(result, deletedSemanticElements, next);
        nodes.prune();
      } else if (tokenUtil.isToken(next)) {
        // We have encountered some token, but not the one we expected
        // Will be handled by invoking 'getLeadingCommentsIncludingWhitespace' method later
        handleReordering = true;
        break;
      }
    }
  }
  if (handleReordering) {
    return getLeadingCommentsIncludingWhitespace(to);
  }
  return result;
}