org.eclipse.xtext.nodemodel.util
Class NodeModelUtils

java.lang.Object
  extended by org.eclipse.xtext.nodemodel.util.NodeModelUtils

public class NodeModelUtils
extends java.lang.Object

The NodeModelUtils are a collection of useful methods when dealing with the node model directly. They encapsulate the default construction semantics of the node model as it is created by the parser.

Author:
Sebastian Zarnekow - Initial contribution and API

Constructor Summary
NodeModelUtils()
           
 
Method Summary
static java.lang.String compactDump(INode node, boolean showHidden)
          Creates a string representation of the given node.
static ICompositeNode findActualNodeFor(org.eclipse.emf.ecore.EObject semanticObject)
          Returns the node that covers all assigned values of the given object.
static org.eclipse.emf.ecore.EObject findActualSemanticObjectFor(INode node)
          Returns the semantic object that is really associated with the actual container node of the given node.
static ILeafNode findLeafNodeAtOffset(INode node, int leafNodeOffset)
          Find the leaf node at the given offset.
static java.util.List<INode> findNodesForFeature(org.eclipse.emf.ecore.EObject semanticObject, org.eclipse.emf.ecore.EStructuralFeature structuralFeature)
          Returns the list of nodes that were used to assign values to the given feature for the given object.
static ICompositeNode getNode(org.eclipse.emf.ecore.EObject object)
          Returns the node that is directly associated with the given object by means of an EMF-Adapter.
static java.lang.String getTokenText(INode node)
          This method converts a node to text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeModelUtils

public NodeModelUtils()
Method Detail

findLeafNodeAtOffset

public static ILeafNode findLeafNodeAtOffset(INode node,
                                             int leafNodeOffset)
Find the leaf node at the given offset. May return null if the given offset is not valid for the node (sub-)tree. A node matches the leafNodeOffset if it fulfills the following condition:
  node.totalOffset <= leafNodeOffset &&
  node.totalEndOffset > leafNodeOffset 
 

Parameters:
node - the container node. May not be null.
leafNodeOffset - the offset that is covered by the searched node.
Returns:
the leaf node at the given offset or null.

getNode

public static ICompositeNode getNode(org.eclipse.emf.ecore.EObject object)
Returns the node that is directly associated with the given object by means of an EMF-Adapter.

Returns:
the node that is directly associated with the given object.
See Also:
findActualNodeFor(EObject)

findNodesForFeature

public static java.util.List<INode> findNodesForFeature(org.eclipse.emf.ecore.EObject semanticObject,
                                                        org.eclipse.emf.ecore.EStructuralFeature structuralFeature)
Returns the list of nodes that were used to assign values to the given feature for the given object.

Returns:
the list of nodes that were used to assign values to the given feature for the given object.

findActualNodeFor

public static ICompositeNode findActualNodeFor(org.eclipse.emf.ecore.EObject semanticObject)
Returns the node that covers all assigned values of the given object. It handles the semantics of actions and unassigned rule calls.

Returns:
the node that covers all assigned values of the given object.

findActualSemanticObjectFor

public static org.eclipse.emf.ecore.EObject findActualSemanticObjectFor(INode node)
Returns the semantic object that is really associated with the actual container node of the given node. It handles the structural semantics that results from Actions and unassigned rule calls.

Returns:
the semantic object that is really associated with the actual container node of the given node.

compactDump

public static java.lang.String compactDump(INode node,
                                           boolean showHidden)
Creates a string representation of the given node. Useful for debugging.

Returns:
a debug string for the given node.

getTokenText

public static java.lang.String getTokenText(INode node)
This method converts a node to text. Leading and trailing text from hidden tokens (whitespace/comments) is removed. Text from hidden tokens that is surrounded by text from non-hidden tokens is summarized to a single whitespace. The preferred use case of this method is to convert the ICompositeNode that has been created for a data type rule to text. This is also the recommended way to convert a node to text if you want to invoke IValueConverterService.toValue(String, String, INode)