Xcore - magic content assist for XBlockExpression [message #893997] |
Fri, 06 July 2012 11:22 |
|
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 |
Ed Merks Messages: 33142 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 |
|
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 #894177 is a reply to message #894093] |
Sat, 07 July 2012 11:46 |
|
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 |
|
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:
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03977 seconds