Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get location (#-th line) of EObject in original document?

The followings are my grammar rules:

Stmts: (stmts += Stmt ';')* ;
Stmt: Stmt1 | Stmt2 | Stmt3 ... ;

I want to know each Stmt# is #-th stmt in stmts and their exactly location (#-th line in original document). Such that I could point out the location when user make mistakes.

I override the validator constructor and store an HashMap <Stmt, Integer> to get each Stmt# is the #-th Stmt in stmts(Not sure if this is the correct way to do though...). However I have no idea how to get their line number.

Any help?

like image 774
Ray Wu Avatar asked Aug 22 '13 00:08

Ray Wu


People also ask

How do I get Google location?

From the settings menu scroll down to the Accounts section and tap on Google. In the next menu tap on Location settings. On the final location access page swipe the Off button to On. This will allow all of Google's Android apps installed on your phone to access your GPS location.


1 Answers

Given an EObject you can easily get the position in the source file using org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(EObject).

For example:

    INode node = NodeModelUtils.getNode(o);
    System.out.println(String.format("Node goes from line %s to line %s",node.getStartLine(), node.getEndLine()));
like image 55
stefan.schwetschke Avatar answered Oct 01 '22 16:10

stefan.schwetschke