Java Code Examples for org.eclipse.xtext.nodemodel.INode#getPreviousSibling()

The following examples show how to use org.eclipse.xtext.nodemodel.INode#getPreviousSibling() . 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: NodeIterator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private INode findPrevious(INode node) {
	ICompositeNode parent = node.getParent();
	if (parent == null) {
		return null;
	}
	INode predecessor = node.getPreviousSibling();
	if (predecessor != null) {
		while (predecessor instanceof ICompositeNode && !prunedComposites.contains(predecessor)) {
			INode lastChild = ((ICompositeNode) predecessor).getLastChild();
			if (lastChild == null) {
				return predecessor;
			}
			predecessor = lastChild;
		}
		return predecessor;
	}
	return parent;
}
 
Example 2
Source File: ExtendedFormattingConfigBasedStream.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns predecessor of the given node in the parse tree.
 * Copied method from: org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator
 *
 * @param node
 *          for which predecessor should be found
 * @return predecessor
 */
private INode findPrevious(final INode node) {
  ICompositeNode parent = node.getParent();
  if (parent == null) {
    return null;
  }
  INode predecessor = node.getPreviousSibling();
  if (predecessor != null) {
    while (predecessor instanceof ICompositeNode) {
      INode lastChild = ((ICompositeNode) predecessor).getLastChild();
      if (lastChild == null) {
        return predecessor;
      }
      predecessor = lastChild;
    }
    return predecessor;
  }
  return parent;
}
 
Example 3
Source File: AbstractLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Searches for a keyword before the {@link EStructuralFeature} of the given {@link EObject} model element.
 *
 * @param modelElement
 *          the {@link EObject} model element
 * @param feature
 *          the {@link EStructuralFeature}
 * @return the keyword before the {@link EStructuralFeature} of the given {@link EObject} model element, or {@code null} if no keyword was found
 */
protected String findKeywordBeforeFeature(final EObject modelElement, final EStructuralFeature feature) {
  List<INode> nodes = NodeModelUtils.findNodesForFeature(modelElement, feature);
  if (!nodes.isEmpty()) {
    INode node = nodes.get(0);
    while (!(node.getGrammarElement() instanceof Keyword) && node.hasPreviousSibling()) {
      node = node.getPreviousSibling();
    }
    if (node.getGrammarElement() instanceof Keyword) {
      return node.getText();
    }
  }
  return null;
}