xtextxtend

How to determine the index of the line a keyword of my language belongs to in the Eclipse editor?


I'm using Xtext to design an image building language. For that purpose, the index of the line in which a token is found in the Eclipse editor matters. Is there a way to find out this line index in the Xtend code of my code generator? I'm using Xtext/Xtend 2.12.0


Solution

  • the information is available though the node model.

    you can use org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(EObject) to obtain the node of an EObject. org.eclipse.xtext.nodemodel.INode.getOffset() to get an offset. org.eclipse.xtext.nodemodel.util.NodeModelUtils.getLineAndColumn(INode, int) to get the line information.

    you may also have a look at ILocationInFileProvider and ITextRegionWithLineInformation