Xtext Node Position

The model classes don't contain any information about their position in the source code. This can be retrieved with the org.eclipse.xtext.nodemodel.util.NodeModelUtils class.

var node = NodeModelUtils.getNode(modelObject);
System.out.println("Offsets: " + node.offset + " - " + node.endOffset);
System.out.println("Length: " + node.length);