modify the code generated from def create method

39 views
Skip to first unread message

nguyenvi...@gmail.com

unread,
Feb 17, 2015, 5:01:24 AM2/17/15
to xtend...@googlegroups.com
Hi, Is there any solution for modifying the code generated from the create method?. I would like to add some code to the generated method. I tried to use Active annotation but i cannot use active annotation for create methods, there is always the error "Cannot use inferred type as parameter type."

Thanks

Sven Efftinge

unread,
Feb 17, 2015, 5:45:19 AM2/17/15
to xtend...@googlegroups.com
Could you outline what you want to achieve?

On 17 Feb 2015, at 11:01, nguyenvi...@gmail.com wrote:

Hi, Is there any solution for modifying the code generated from the create method?. I would like to add some code to the generated method. I tried to use Active annotation but i cannot use active annotation for create methods, there is always the error "Cannot use inferred type as parameter type."

Thanks

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nguyenvi...@gmail.com

unread,
Feb 17, 2015, 5:56:20 AM2/17/15
to xtend...@googlegroups.com, efft...@itemis.de
Hi Sven Efftinge,

I woud like to access to the traces of the transformation ( the generated Maps is also considered the traces) after the transformation 's execution. However,
in the generated code, the traces of the transformation are stocked in private final Map ( for e.g, private final HashMap<ArrayList<?>, Model> _createCache_transform = CollectionLiterals.newHashMap(); )
So, i want to add a specific trace object of type TraceRegistry (the class that i create for the tracing purpose) to stock the traces of the transformation.


Thanks

Message has been deleted

Nguyen Viet Hoa

unread,
Feb 17, 2015, 10:25:36 AM2/17/15
to xtend...@googlegroups.com, efft...@itemis.de
For example :

synchronized (_createCache_transform) {
      if (_createCache_transform.containsKey(_cacheKey)) {
        return _createCache_transform.get(_cacheKey);
      }
      Model _createModel = UMLFactory.eINSTANCE.createModel();
      _result = _createModel;
      _createCache_transform.put(_cacheKey, _result);
     
      traceRegistry.put(_cacheKey, _result);

Franz Becker

unread,
Feb 18, 2015, 10:18:56 AM2/18/15
to xtend...@googlegroups.com
Hi,

it seems like you may want to write your own active annotation in order to customize the generated code.

This way you could also change the computation of the cache key, if that is needed (I had this use case once).

Best regards,
Franz

Nguyen Viet Hoa

unread,
Feb 18, 2015, 12:45:05 PM2/18/15
to xtend...@googlegroups.com, becker...@gmail.com
Hi Franz,

      Thank you so much for your answer. I've tried many way to modify the generated code of the create method with active annotation, but there are always exceptions raised "java.util.ConcurrentModificationException". It seems like i cannot modify the method.body of the create method.

Could you please share the code snippet that you have succeed to change the computation of the cache key please?

Best Regard,

Hoa

becker...@gmail.com

unread,
Feb 18, 2015, 12:56:25 PM2/18/15
to xtend...@googlegroups.com
Hi Hoa,

don't try to alter the behavior of create methods and apply your active annotation to a regular method and you should be fine.

For example:

@CustomCreate
def Z createZ(X x, Y y) {
  // ...
}

The you would program your active annotation in a way that it creates the same code as the built-in mechanism with the additional line of your trace registry.

Best regards,
Franz


PS: Sorry that I can't share the code snippet with you as this was not in an open source project.

Nguyen Viet Hoa

unread,
Feb 19, 2015, 4:17:18 AM2/19/15
to xtend...@googlegroups.com, becker...@gmail.com
Hi Franz,
     
          Thank you so much for you response. In fact, i want to reuse the mecanism de create method, but i think we can not change the behavior of the create method. I will think about your solution (use regular methods with annotations).

Best Regards,

Hoa
Reply all
Reply to author
Forward
0 new messages