Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Some comments disappear when model is manipulated(I am doing something wrong in my model manipulation or serialization or model definition in regards of comment? Or did I stumbled upon a Xtext bug?)
Some comments disappear when model is manipulated [message #1220761] Fri, 13 December 2013 13:08 Go to next message
Espinosa CZ is currently offline Espinosa CZFriend
Messages: 27
Registered: July 2009
Junior Member
Hi guys,

I am doing something wrong in my model manipulation/serialization code, or xtext model definition in regards of comment? Or did I stumbled upon a Xtext bug?

Basically comments disappears from my DSL at/around point of model modification, like adding or missing elements or removing wrong element.

Both // (double slash line comment) and /* */ (block comments) both courtesy of included Xbase grammar (right?).

I found this issue when I was testing my Quick Fix provider, I then extracted this unit test to demonstrate the issue:

	/** FAILS */
	@Test
	def void addFieldToModelAndSerializeBack_testCommentsHandling_simplestCase() {
		val sample = '''
		deepClone
		package my.home.cloners
		a.b.m.Magazine {
			// comment 1
		}
		'''
		
		val expectedModifiedSample = '''
		deepClone
		package my.home.cloners
		a.b.m.Magazine {
			// comment 1
			fooFoo
		}
		'''.toString
		
		val model = parser.parse(sample)
		val articleContainerField = (model as Body).cloners.get(0).asContainer
		articleContainerField.addFields(newArrayList("fooFoo"))  // do tested model manipulation 
		val result = model.serialize
		assertEquals(
			expectedModifiedSample,
			result
		)
	}


instead of expected:
		deepClone
		package my.home.cloners
		a.b.m.Magazine {
			// comment 1
			fooFoo
		}


I get:
		deepClone
		package my.home.cloners
		a.b.m.Magazine {
			fooFoo
		}


The comment completely disappears.

Same happens when I remove some elements from a Cloner; from root element or deeper in more complex structures.

Please check my complete unit test for further details, wat works and what does not:
https://bitbucket.org/espinosa/deepclone/src/218c858feb6c0d02a332dde598138089e57f765a/my.home.dsl.DeepClone.tests/src/my/home/dsl/deepclone/Test6DeepCloneModelManipulation.xtend?at=master

I did some further test, see my DeepCloneModelManipulationTest, and found that all comments following the spot where change in the model was made disappear when model is serialized.

I am still using Xtext 2.4.3; I have just spot you released a new version of Xtext and Xtend. 2.5.0. Great! I will give it a go and if the issue is still present I will submit a bug report.

[Updated on: Fri, 13 December 2013 13:09]

Report message to a moderator

Re: Some comments disappear when model is manipulated [message #1220789 is a reply to message #1220761] Fri, 13 December 2013 15:28 Go to previous messageGo to next message
Espinosa CZ is currently offline Espinosa CZFriend
Messages: 27
Registered: July 2009
Junior Member
So I have just updated my project to xtext 2.5.0 but the issue is still there.

https://bitbucket.org/espinosa/deepclone/src/83f8382a5e62300744f7ccf1647ff5c630e73057/my.home.dsl.DeepClone.tests/src/my/home/dsl/deepclone/Test6DeepCloneModelManipulation.xtend?at=master
Re: Some comments disappear when model is manipulated [message #1220835 is a reply to message #1220789] Fri, 13 December 2013 23:34 Go to previous messageGo to next message
Espinosa CZ is currently offline Espinosa CZFriend
Messages: 27
Registered: July 2009
Junior Member
The model modification code is here (extension method):

public void addFields(
   ContainerType parentContainer,
   List<String> fieldsToBeAdded) 
{
   DeepCloneFactory deepCloneFactory = DeepCloneFactory.eINSTANCE;
   for (String newfieldName : fieldsToBeAdded) {
      SimpleField field = deepCloneFactory.createSimpleField();
      field.setFieldName(newfieldName);
      parentContainer.getFields().add(field);
   }
}


Full code:
https://bitbucket.org/espinosa/deepclone/src/83f8382a5e62300744f7ccf1647ff5c630e73057/my.home.dsl.DeepClone/src/my/home/dsl/utils/DeepCloneUtils.java?at=master

The link to bugreport:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=424027
Re: Some comments disappear when model is manipulated [message #1239183 is a reply to message #1220835] Mon, 03 February 2014 15:23 Go to previous message
Sylvain Heraud is currently offline Sylvain HeraudFriend
Messages: 3
Registered: December 2012
Junior Member
Hi,

I have exactly the same problem, with an ISemanticModification
Foo foo = DSLFactory.eINSTANCE.createFoo();
bar.setFoo(foo);


If I serialize the EObject bar before the set, comments are in place, but after comments are moved.

I'm running Xtext 2.5.0.v201312110906

Thanks for your answer

Best Regard

Sylvain
Previous Topic:on OnChangeEvictingCache and JvmModelInferrer
Next Topic:Registering xtext to different file extensions at runtime
Goto Forum:
  


Current Time: Sun Nov 29 23:37:19 GMT 2020

Powered by FUDForum. Page generated in 0.01960 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top