Package org.eclipse.xtext.nodemodel.util
Class NodeModelUtils
- java.lang.Object
-
- org.eclipse.xtext.nodemodel.impl.InternalNodeModelUtils
-
- org.eclipse.xtext.nodemodel.util.NodeModelUtils
-
public class NodeModelUtils extends InternalNodeModelUtils
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. This API is quite low level and internal functionality of the framework relies on the implemented contracts. Clients should rather use the language specific APIs that provide almost the same functionality, e.g.ILocationInFileProviderandEObjectAtOffsetHelperif they want to access the region of asemantic object.
-
-
Constructor Summary
Constructors Constructor Description NodeModelUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcompactDump(INode node, boolean showHidden)Creates a string representation of the given node.static ICompositeNodefindActualNodeFor(org.eclipse.emf.ecore.EObject semanticObject)Returns the node that covers all assigned values of the given object.static org.eclipse.emf.ecore.EObjectfindActualSemanticObjectFor(INode node)Returns the semantic object that is really associated with the actual container node of the given node.static ILeafNodefindLeafNodeAtOffset(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 ParserRulegetEntryParserRule(INode node)static org.eclipse.xtext.util.LineAndColumngetLineAndColumn(INode anyNode, int documentOffset)Compute the line and column information at the given offset from any node that belongs to the document.static ICompositeNodegetNode(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.StringgetTokenText(INode node)This method converts a node to text.-
Methods inherited from class org.eclipse.xtext.nodemodel.impl.InternalNodeModelUtils
basicGetFirstChild, basicGetLastChild, basicGetParent, computeLineBreaks, getLineAndColumn
-
-
-
-
Method Detail
-
findLeafNodeAtOffset
public static ILeafNode findLeafNodeAtOffset(INode node, int leafNodeOffset)
Find the leaf node at the given offset. May returnnullif the given offset is not valid for the node (sub-)tree. A node matches theleafNodeOffsetif it fulfills the following condition:node.totalOffset <= leafNodeOffset && node.totalEndOffset > leafNodeOffset
- Parameters:
node- the container node. May not benull.leafNodeOffset- the offset that is covered by the searched node.- Returns:
- the leaf node at the given offset or
null.
-
getLineAndColumn
public static org.eclipse.xtext.util.LineAndColumn getLineAndColumn(INode anyNode, int documentOffset)
Compute the line and column information at the given offset from any node that belongs to the document. The line is one-based, e.g. the first line has the line number '1'. The line break belongs to the line that it breaks. In other words, the first line break in the document also has the line number '1'. The column number starts at '1', too. In effect, the document offset '0' will always return line '1' and column '1'. If the given documentOffset points exactly toanyNode.root.text.length, it's assumed to be a virtual character thus the offset is valid and the column and line information is returned as if it was there. This contract is in sync withResource.Diagnostic.- Throws:
java.lang.IndexOutOfBoundsException- if the document offset does not belong to the document,documentOffset < 0 || documentOffset > anyNode.rootNode.text.length
-
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.- Parameters:
object- the semantic object whose direct node should be provided.- 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
actionsandunassigned rule calls. The returned node will include unassigned surrounding leafs, e.g. if you use something likeParenthesized expressionsredundant parentheses will be part of the returned node.Consider the following simple expression (a number literal):
((1))
Assuming it was parsed from a grammar like this:Expression: Number | Parentheses; Parentheses: '(' Expression ')'; Number: value=INTThe actual node for the only semantic object that was produced from the input((1))is the root node even though the minimal node would be the one with the text1.- Parameters:
semanticObject- the semantic object whose node should be provided.- 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 fromActionsandunassigned 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 theICompositeNodethat 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 invokeIValueConverterService.toValue(String, String, INode)
-
getEntryParserRule
public static ParserRule getEntryParserRule(INode node)
-
-