Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328055

Summary: Problem with stale line numbers.
Product: [Modeling] TMF Reporter: pgbackup
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jan, sebastian.zarnekow, sven.efftinge
Version: 1.0.1Flags: sebastian.zarnekow: indigo+
Target Milestone: M4   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description pgbackup CLA 2010-10-18 13:22:55 EDT
This problem is accurately described on this forum post. Please see

http://www.eclipse.org/forums/index.php?t=msg&th=198618&start=0&S=f0b48be00b6c5feb6c55ad616fb63f2f

Basically the issue is that the parse tree model doesn't seem to be updating line number properly when the file is being edited/saved. For example, say you have a DSL like this:

1. state A {
2.   do1();
3.  do2();
4. }
5.
6. state B {
7.  do3();
8.  do4();
9. }

If I write the following code:
  MyDSL model = (MyDSL) resource.getContents().get(0);
  EList<State> states = model.getStates();
  for (State s : states)
    System.out.println(s.getName() + " " + NodeUtil.getAdapter(s).getParserNode().getLine();

I should get this:

A 1
B 6

This works fine and is correct. However, now if I edit the file so it looks like this:
1. state A {
2.   do1();
3.   do2();
4.   do5();
5. }
6.
7. state B {
8.  do3();
9.  do4();
10. }

I save the file and run the above code, I get

A 1
B 6

The line numbers are now wrong. Should be 1 and 7 for A,B, respectively. Now say, I delete line 6 (empty line), reinserted it, saved the file, and ran the code. In that case, the line numbers would be correct and I get 1,7.

Basically, whenever I'm editing inside the state {} block the line numbers don't seem to be getting updated and are stale.

Hope this can be fixed soon and a release/patch made available. Thanks.
Comment 1 Sebastian Zarnekow CLA 2010-12-13 17:26:36 EST
Should be fixed with the new node model implementation.
Comment 2 Jan Koehnlein CLA 2011-01-03 05:22:08 EST
I cannot reproduce this in Xtext 1.0.1. Could you provide a sample grammar and a test case?

Please also make sure not to refer to a stale object: Check if the element with the wrong line information has eResource() != null. Are you using cross-resource containment?
Comment 3 Sven Efftinge CLA 2011-02-01 04:15:40 EST
setting this to fixed see comment #2 and #3
Comment 4 Karsten Thoms CLA 2017-09-19 17:58:46 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 18:09:30 EDT
Closing all bugs that were set to RESOLVED before Neon.0