Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xcore - magic content assist for XBlockExpression
Xcore - magic content assist for XBlockExpression [message #893997] Fri, 06 July 2012 11:22 Go to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi,

i am impressed about the content assist of Xcores XBlockExpression.
Inside an operation (XBlockExpression) xReferences can be accessed by contentassist. For normal JVMTypeReference are addressed by content assist of a XBlockExpression.

class Library {
	contains Book[*] books opposite library
	
	op Int getBooksCount(){
		return books.size
	}


But i wonder how it works. I spent hours to find out and have been setting a lot of breakpoints in the code to find the proper piece of code that is responsible to provide an XReference instead of a JVMTypeReference.

First i thought that the generated java code is used... But i suppressed the code generation by a "compile error" in the xcore file and the content assist still works.

I think there will be done some kind of mapping or something.

Can anybody give me a hint which parts of the code are responsible doing this? Then i can continue browsing the underlying source.

Thanks in advance for your help.
And thanks to Xcore team providing such an interesting and really reusable issue!

Best,
Florian Pirchner
Re: Xcore - magic content assist for XBlockExpression [message #894009 is a reply to message #893997] Fri, 06 July 2012 11:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Florian,

A *.xcore resources infers the Jvm* things that will be generated
(XcoreJvmInferrer) and those things are in scope within the bodies of
operations. You can see all the inferred things in the hover
information for any construct in the Xcore source. So, for example, the
resource knows there is a generated interface and implementations for an
XClass with accessor methods like getX which in Xbase can be accessed as
if it were a field. If you open the *.xcore resource with EMF's
reflective editor, (Open With->Other...->Sample Reflective Ecore Model
Editor) you can see all the inferred content, e.g., the Ecore model, the
GenModel, and all the Jvm types model instances; it's quite a useful and
interesting feature.


On 06/07/2012 1:22 PM, Florian Pirchner wrote:
> Hi,
>
> i am impressed about the content assist of Xcores XBlockExpression.
> Inside an operation (XBlockExpression) xReferences can be accessed by
> contentassist. For normal JVMTypeReference are addressed by content
> assist of a XBlockExpression.
>
>
> class Library {
> contains Book[*] books opposite library
>
> op Int getBooksCount(){
> return books.size
> }
>
>
> But i wonder how it works. I spent hours to find out and have been
> setting a lot of breakpoints in the code to find the proper piece of
> code that is responsible to provide an XReference instead of a
> JVMTypeReference.
>
> First i thought that the generated java code is used... But i
> suppressed the code generation by a "compile error" in the xcore file
> and the content assist still works.
>
> I think there will be done some kind of mapping or something.
>
> Can anybody give me a hint which parts of the code are responsible
> doing this? Then i can continue browsing the underlying source.
>
> Thanks in advance for your help.
> And thanks to Xcore team providing such an interesting and really
> reusable issue!
>
> Best,
> Florian Pirchner


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xcore - magic content assist for XBlockExpression [message #894081 is a reply to message #894009] Fri, 06 July 2012 14:50 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi Ed,

thanks a lot for that input.
I explored the created .xcore file with the reflective editor and could find the JVMElements.
Really interesting approach. You are creating JVMElements that are related with the Xcore elements on the fly, add them to the resource and sync them.

So Xbase just uses them without any concern.

Thanks a lot,
Florian
Re: Xcore - magic content assist for XBlockExpression [message #894093 is a reply to message #894081] Fri, 06 July 2012 15:32 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
That is in fact the standard Xtext way of creating a JVM language.
For most cases you only have to write a grammar and a JvmModelInferrer
and you're done. You'll get JDT integration for free.

Am 06.07.12 16:50, schrieb Florian Pirchner:
> Hi Ed,
>
> thanks a lot for that input.
> I explored the created .xcore file with the reflective editor and could
> find the JVMElements.
> Really interesting approach. You are creating JVMElements that are
> related with the Xcore elements on the fly, add them to the resource and
> sync them.
>
> So Xbase just uses them without any concern.
>
> Thanks a lot,
> Florian


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Xcore - magic content assist for XBlockExpression [message #894177 is a reply to message #894093] Sat, 07 July 2012 11:46 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Thanks for the hint. I found the section "Xtext and Java" in the Xtext documentation. Now got an understanding how JVM languages can be built on top of Xtext.
Really great job!

Now i am going to implement a ModelInferrer that allows Xbase to reference my LReferences of EntityModel.

Thanks again for you help.

Best,
Florian
Re: Xcore - magic content assist for XBlockExpression [message #894847 is a reply to message #894177] Tue, 10 July 2012 18:29 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

For now i spent many hours browsing the possibilities of the model inferrer.

And i am really impressed.

But i am not sure how to handle "NOT inferred jvm elements". "NOT inferred jvm elements" are elements that do not have any counterpart in the semantic model.
For instance an entity model; and i would like to add a boolean property called "disposed" to the resulting java code.

dsl code:
entity MyEntity {

}


resulting java code:
public class MyEntity {

private boolean disposed;


} 


This JVMField does not have any counterpart in the semantic model. It is just an implementation detail in the resulting java source code.

My question:
I would like to add the JVMField "disposed" to the JVM-model using the model inferrer. But it will not be related to the semantic model. It is only contained in the JVM model.

Is that good practice or should i use a generator to do such stuff?
I am asking since i did not see any methods in JvmTypesBuilder that can be called without a sourceElement.

Thanks again,
Florian

Re: Xcore - magic content assist for XBlockExpression [message #894849 is a reply to message #894847] Tue, 10 July 2012 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this should be perfectly solveable in the inferrer.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xcore - magic content assist for XBlockExpression [message #894857 is a reply to message #894849] Tue, 10 July 2012 19:31 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi,

good to know...

Thanks,
Florian
Re: Xcore - magic content assist for XBlockExpression [message #894959 is a reply to message #894847] Wed, 11 July 2012 09:00 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 07/10/2012 08:29 PM, Florian Pirchner wrote:
> For now i spent many hours browsing the possibilities of the model
> inferrer.
>
> And i am really impressed.
>
> But i am not sure how to handle "NOT inferred jvm elements". "NOT
> inferred jvm elements" are elements that do not have any counterpart in
> the semantic model.
> For instance an entity model; and i would like to add a boolean property
> called "disposed" to the resulting java code.
>
> dsl code:
>
> entity MyEntity {
>
> }
>
>
> resulting java code:
>
> public class MyEntity {
>
> private boolean disposed;
>
>
> }
>
> This JVMField does not have any counterpart in the semantic model. It is
> just an implementation detail in the resulting java source code.
>
> My question:
> I would like to add the JVMField "disposed" to the JVM-model using the
> model inferrer. But it will not be related to the semantic model. It is
> only contained in the JVM model.
>
> Is that good practice or should i use a generator to do such stuff?
> I am asking since i did not see any methods in JvmTypesBuilder that can
> be called without a sourceElement.

You can still use JvmTypesBuilder method toField, using as the source
element the entity class

note that the 'disposed' field generated by the inferrer will be visible
and accessible in possible xbase expressions even if it is not in the
original program, if I'm not wrong :)

I did some experiments with the inferrer where the mapping to Java
elements is not direct http://www.rcp-vision.com/?p=4089

hope it helps

cheers
Lorenzo


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: Xcore - magic content assist for XBlockExpression [message #894971 is a reply to message #894959] Wed, 11 July 2012 09:38 Go to previous message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Thanks a lot.

Passing the entity class as the source element will make it really straight forward.
And thanks for your blog too. Very useful!

Thanks,
Florian
Previous Topic:problems with the OnTheFlyJavaCompiler
Next Topic:JVMField with primitive type
Goto Forum:
  


Current Time: Sat Apr 20 09:34:36 GMT 2024

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

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

Back to the top