Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body
JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143822] Fri, 18 October 2013 12:53 Go to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

I'm writing a JvmModelInferrer in which I create classes with methods with bodies.

In these body, I would like to declare variables of a given type, so I do something like that:

body = [
  aType.newTypeRef().serializeSafely(it)
  append(" varName = methodCall();")
]


newTypeRef comes from JvmTypesBuilder and serializeSafely comes from ErrorSafeExtensions.

The problem is that because this JvmTypeReference does not have any eContainer, when serialize (from TypeReferenceSerializer) is called by ErrorSafeExtensions with context set to the JvmTypeReference's eContainer which is null, I get a NPE...

Question:
1) is that the correct way of serializing a JvmTypeReference?
2) is there a better way to generate the body of the method? For example by building an XEpression instead of doing it by hand? How to build such an XEpression?

Thank you Smile

Victor

[Updated on: Fri, 18 October 2013 12:53]

Report message to a moderator

Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143873 is a reply to message #1143822] Fri, 18 October 2013 13:30 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
Hi where does a type come from and what type is it?
And why don't you simply write the type down?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143879 is a reply to message #1143822] Fri, 18 October 2013 13:38 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
BTW if atype is a jvmtype you can call

Append(atype)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143911 is a reply to message #1143879] Fri, 18 October 2013 14:06 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

This type reference has type arguments: it is a reference, not a type, that's why I want to use serialize.

The type itself is a class generated with JvmModelInferrer.

Let's say I did in the infer method:

anObjectOfMyModel.toClass(name) [
  typeParameters += ...
]


I thus got a JvmGenericType, and then, I want to have a reference to this type, but with specific arguments.
Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143922 is a reply to message #1143911] Fri, 18 October 2013 14:12 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
Sorry have no idea on that

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1143980 is a reply to message #1143922] Fri, 18 October 2013 15:04 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
maybe you can use one of org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(JvmTypeReference, EObject, IAppendable)
and put your model object as context.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmModelInferrer: Serializing a JvmTypeReference and Generating a method body [message #1144012 is a reply to message #1143980] Fri, 18 October 2013 15:27 Go to previous message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

Thank you, that works perfectly yes :)

If anybody comes around and knows the answer to the second question, it would be nice.
That would be much more elegant I think, but I guess xtext is not ready for meta-programming (yet ;).
Previous Topic:Documenting the Grammar to use it in the DSL-Editor
Next Topic:ClusteringBuilderState - Error validating
Goto Forum:
  


Current Time: Fri Nov 27 18:50:18 GMT 2020

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

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

Back to the top