Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference problem when building after a Clean
Cross reference problem when building after a Clean [message #769029] Wed, 21 December 2011 09:28 Go to next message
rjarana Missing name is currently offline rjarana Missing nameFriend
Messages: 12
Registered: November 2011
Junior Member
Hi!

My language has models in diferents files. It can have references from one to another, and this is working fine if the referenced model is already compiled (partial build). The problem comes when I do a Clean Project. What I have from the cross reference is a proxy class, so I can't validate neither infer Jvm, because I can't get the JvmTypeReference of the referenced model. I do this by getting the fullQualifiedName of the cross reference, but when it is a proxy, I get NULL.

How can I get the JvmTypeReference for cross references on this situation?

Thanks!
Re: Cross reference problem when building after a Clean [message #769157 is a reply to message #769029] Wed, 21 December 2011 13:47 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
The recommended way of creating Java from your own DSL is to implement
an IJvmModelInferrer and use the JvmModelGenerator to generate the Java
code from that model.

The JVM model can then be referred to form other models without the
actual Java code in place. Xtext's index should transparently handle
that for you.

If you're already using this setup, make sure your inferred JVM model is
indexed properly (IDefaultResourceDescriptionStrategy).

Am 21.12.11 10:28, schrieb rjarana:
> Hi!
>
> My language has models in diferents files. It can have references from
> one to another, and this is working fine if the referenced model is
> already compiled (partial build). The problem comes when I do a Clean
> Project. What I have from the cross reference is a proxy class, so I
> can't validate neither infer Jvm, because I can't get the
> JvmTypeReference of the referenced model. I do this by getting the
> fullQualifiedName of the cross reference, but when it is a proxy, I get
> NULL.
>
> How can I get the JvmTypeReference for cross references on this situation?
>
> Thanks!


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: Cross reference problem when building after a Clean [message #769163 is a reply to message #769157] Wed, 21 December 2011 14:01 Go to previous messageGo to next message
rjarana Missing name is currently offline rjarana Missing nameFriend
Messages: 12
Registered: November 2011
Junior Member
Maybe I'm inferring the JvmTypeReference of cross reference wrong. I'm doing this (superType is the cross reference to another Definition):

@Inject private TypeReferences references
...
def dispatch infer(Definition e, IAcceptor<JvmDeclaredType> acceptor, boolean prelinkingPhase) {
    var JvmTypeReference superType = references.getTypeForName(e.superType.fullyQualifiedName.toString, e);

    jvmClass.superTypes += superType;
...


So when it's a compilation after a Clean Project, e.superType.fullyQualifiedName is null.
Re: Cross reference problem when building after a Clean [message #769576 is a reply to message #769163] Thu, 22 December 2011 11:01 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You should not resolve cross-references during the JVM model inferrence.
Try use EcoreUtil2.cloneWithProxies() to create a copy of the proxied
superType and add this as superType instead.

If that does not work, try to debug the IQualifiedNameProvider of your
language.


Am 21.12.11 15:01, schrieb rjarana:
> Maybe I'm inferring the JvmTypeReference of cross reference wrong. I'm
> doing this (superType is the cross reference to another Definition):
>
>
> @Inject private TypeReferences references
> ..
> def dispatch infer(Definition e, IAcceptor<JvmDeclaredType> acceptor,
> boolean prelinkingPhase) {
> var JvmTypeReference superType =
> references.getTypeForName(e.superType.fullyQualifiedName.toString, e);
>
> jvmClass.superTypes += superType;
> ..
>
>
> So when it's a compilation after a Clean Project,
> e.superType.fullyQualifiedName is null.


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: Cross reference problem when building after a Clean [message #769594 is a reply to message #769576] Thu, 22 December 2011 11:47 Go to previous messageGo to next message
rjarana Missing name is currently offline rjarana Missing nameFriend
Messages: 12
Registered: November 2011
Junior Member
EcoreUtil2.cloneWithProxies() returns an EObject, and superTypes requires JvmTypeReference.
Re: Cross reference problem when building after a Clean [message #769603 is a reply to message #769594] Thu, 22 December 2011 12:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

downcasting should work

(JvmTypeReference)EcoreUtil2.cloneWithProxies(ref)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference problem when building after a Clean [message #769610 is a reply to message #769603] Thu, 22 December 2011 12:10 Go to previous messageGo to next message
rjarana Missing name is currently offline rjarana Missing nameFriend
Messages: 12
Registered: November 2011
Junior Member
Doesn't work:

java.lang.ClassCastException: org.dsl.mylang.impl.DefinitionImpl cannot be cast to org.eclipse.xtext.common.types.JvmTypeReference

Re: Cross reference problem when building after a Clean [message #769617 is a reply to message #769610] Thu, 22 December 2011 12:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are we talking about the supertype of the model or inferred supertype in the jvm world
jan actually meant something like in the domain model example

the cloned supertype in the model world is of course still a odd model object (in your case a definition)

so you might actually have to go the
"debugging" way

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 22 December 2011 12:19]

Report message to a moderator

Re: Cross reference problem when building after a Clean [message #769629 is a reply to message #769617] Thu, 22 December 2011 12:43 Go to previous messageGo to next message
rjarana Missing name is currently offline rjarana Missing nameFriend
Messages: 12
Registered: November 2011
Junior Member
I'm now totally lost.

My language is something like this:

Definition:
    'definition' name=ValidID ('extends' superType=[Definition|QualifiedName])? '{'
        features += Feature*
    '}'
;

Feature:
    Attribute | Property
;

Property:
    'property' name=ValidID ('{' 
        features+=Feature*
    '}')?
;

Attribute:
    id=ValidID '=' value=XTReference
;

Referenciable:
    Property | Definition
;

XTReference:
    'ref' value=[Referenciable|QualifiedName]
;



So as you can see, I have cross-reference in Definition super type and in Attribute, referring to a Definition or a Property (in the same or different Definition, that's why I use QualifiedName).

When I infer the Jvm model, I create a class for every Definition and Property. So I need to get the JvmTypeReference of the referenced element to generate the correct method signature in Java.

Any suggestion?
Re: Cross reference problem when building after a Clean [message #769636 is a reply to message #769629] Thu, 22 December 2011 12:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

since you have a refernce to a Definition
and not a JvmTypeReference there is no easy solution for that.
if you do not have imports in your dsl you
could use the NodeModelUtil to find out the actual text in the model file at the place of the refernce.

maybe jan has an idea how to do this nice without resolving the proxy.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext editor to insert single proposals automatically without showing content assist popup
Next Topic:IContainer.Manager returns weird things i've never imported???
Goto Forum:
  


Current Time: Fri Apr 26 10:22:04 GMT 2024

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

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

Back to the top