@ChainOverridable not working for transformations (same object is created multiple times)

24 views
Skip to first unread message

Torsten Juergeleit

unread,
Feb 23, 2014, 3:20:28 PM2/23/14
to sculptor...@googlegroups.com

Enabling @ChainOverridable for DslTransformation (issue #64) and using an extension for DslTransformation ends up in failing transformation tests:

Results :

Failed tests:
  DslTransformationTest.testTransformDslModel:100 Expected: [module1Name, module2Name], Actual: [module1Name, module2Name, module1Name, module2Name]
  DtoTransformationTest.assertModules:106 Expected: [media], Actual: [media, media]
  LibraryTransformationTest.assertModules:141 Expected: [media, person], Actual: [media, person, person, media]
  LibraryTransformationTest.assertPhysicalMediaRepository:451 null
  LibraryTransformationTest.assertMediaModule:151 Expected: [LibraryService, MediaService, MediaCharacterService, PhysicalMediaService], Actual: [LibraryService, MediaService, MediaCharacterService]
  RestTransformationTest.assertModules:137 Expected: [rest, person], Actual: [rest, person, rest, person]
  RestTransformationTest.assertRestModule:146 Expected: [CustomerService], Actual: []
  RestTransformationTest.assertCustomerScaffold:298 Expected: [createForm, create, show, showAll, delete], Actual: []
  UniverseTransformationTest.assertModules:111 Expected: [milkyway], Actual: [milkyway, milkyway]

Tests run: 74, Failures: 9, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Sculptor :: Generator :: Core ..................... SUCCESS [29.308s]
[INFO] Sculptor :: Generator :: Test support ............. SUCCESS [2.089s]
[INFO] Sculptor :: Generator :: Core tests ............... FAILURE [39.744s]

With the test case DslTransformationTest.testTransformDslModel() in the feature branch feature/transformation-override this issue can be tested in isolation.

Any ideas?

/Torsten

Torsten Juergeleit

unread,
Mar 3, 2015, 6:56:35 PM3/3/15
to sculptor...@googlegroups.com
I think I found the reason for multiple instances created in create methods in transformation classes, e.g. multiple modules in `DslTransformation`:

This is due to the inheritance hierarchy and chain of multiple instances created by Sculptors active annotation processor: The classes with create methods are stateful due to the cache implementation of Xtends create keyword via private members named _createCache_<method name>_<counter>. So we end up with a chain of instances of overriding classes with their state (due to extending the overridable class) and the instance of the overridable class (with their own state) in the end of the chain. Calling methods on one the overriding classes or the overridable class manipulates the state within separate instances.

@Pavel, Ron, does this make sense?

I've reopend #64. Maybe you have an idea on solving this issue.

Would it help to refactor the transformation classes into one class which holds all the non-overridable methods (create methods, private methods or methods calling other non-overridable methods) and another class (annotated with @ChainOverridable) which holds all the the other methods (the overridable ones)? The public methods of the overridable class would be injected as extension methods in the non-overridable class. This is similar to the base Java classes injected in the Xtend classes Properties or Helper.

/Torsten

Torsten Juergeleit

unread,
Mar 3, 2015, 7:24:51 PM3/3/15
to sculptor...@googlegroups.com
To illustrate the issue I've created screenshots from different stack frames with the same create method (but in different instances) from within a call stack from a test case with an overridden DslTransformation:

  

Here multiple instances of modules are created - the first one in the overriding class and the second one in the original / overridable class in the end of the chain.

/Torsten
Reply all
Reply to author
Forward
0 new messages