Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » checking type conformance in Xbase 2.4
checking type conformance in Xbase 2.4 [message #1040951] Sun, 14 April 2013 11:08 Go to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1356
Registered: July 2009
Senior Member
Hi

in 2.3.1 one could use
org.eclipse.xtext.common.types.util.TypeConformanceComputer to check
conformance between two JvmTypeReferences

this is deprecated in Xtext 2.4.0, in favor, I seem to understand, of
org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer
where isConformat wants two LightweightTypeReference instances which are
not compliant with JvmTypeReferences...

by looking at XbaseValidator I seem to understand that to use it with
JvmTypeReferences one should something like

@Inject CommonTypeComputationServices services;

def isConformant(JvmTypeReference t1, JvmTypeReference t2) {
t1.toLightweightTypeReference.isAssignableFrom
(t2.toLightweightTypeReference)
}

def toLightweightTypeReference(JvmTypeReference typeRef) {
val converter =
new OwnedConverter
(new StandardTypeReferenceOwner
(services, typeRef))
converter.toLightweightReference(typeRef)
}

is that correct? or is there a better way?

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Re: checking type conformance in Xbase 2.4 [message #1041571 is a reply to message #1040951] Mon, 15 April 2013 09:01 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2832
Registered: July 2009
Senior Member
Hi Lorenzo,

LightweightTypeReference.isAssignableFrom is the way to go. Where do you
need that functionality specifically?

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 14.04.13 13:08, schrieb Lorenzo Bettini:
> Hi
>
> in 2.3.1 one could use
> org.eclipse.xtext.common.types.util.TypeConformanceComputer to check
> conformance between two JvmTypeReferences
>
> this is deprecated in Xtext 2.4.0, in favor, I seem to understand, of
> org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer
> where isConformat wants two LightweightTypeReference instances which are
> not compliant with JvmTypeReferences...
>
> by looking at XbaseValidator I seem to understand that to use it with
> JvmTypeReferences one should something like
>
> @Inject CommonTypeComputationServices services;
>
> def isConformant(JvmTypeReference t1, JvmTypeReference t2) {
> t1.toLightweightTypeReference.isAssignableFrom
> (t2.toLightweightTypeReference)
> }
>
> def toLightweightTypeReference(JvmTypeReference typeRef) {
> val converter =
> new OwnedConverter
> (new StandardTypeReferenceOwner
> (services, typeRef))
> converter.toLightweightReference(typeRef)
> }
>
> is that correct? or is there a better way?
>
> thanks in advance
> Lorenzo
>
Re: checking type conformance in Xbase 2.4 [message #1041575 is a reply to message #1041571] Mon, 15 April 2013 09:09 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1356
Registered: July 2009
Senior Member
On 04/15/2013 11:01 AM, Sebastian Zarnekow wrote:
> Hi Lorenzo,
>
> LightweightTypeReference.isAssignableFrom is the way to go. Where do you
> need that functionality specifically?
>
> Regards,
> Sebastian

Hi Sebastian

in my custom validator I need to check whether two types are conformant,
and I have JvmTypeReference instances, for instance, they are part of a
method method definition in my DSL, e.g.,

Method:
type=JvmTypeReference name=ValidID
'(' (params+=FullJvmFormalParameter (','
params+=FullJvmFormalParameter)*)? ')'
';' ;

thus I don't have LightweightTypeReference available.

Thus, I was wondering whether this code to convert a JvmTypeReference to
a LightweightTypeReference is the way to go or whether there are better
solutions:

@Inject CommonTypeComputationServices services;

def isConformant(JvmTypeReference t1, JvmTypeReference t2) {
t1.toLightweightTypeReference.isAssignableFrom
(t2.toLightweightTypeReference)
}

def toLightweightTypeReference(JvmTypeReference typeRef) {
val converter =
new OwnedConverter
(new StandardTypeReferenceOwner
(services, typeRef))
converter.toLightweightReference(typeRef)
}

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Re: checking type conformance in Xbase 2.4 [message #1041676 is a reply to message #1041575] Mon, 15 April 2013 12:04 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2832
Registered: July 2009
Senior Member
Am 15.04.13 11:09, schrieb Lorenzo Bettini:
> On 04/15/2013 11:01 AM, Sebastian Zarnekow wrote:
>> Hi Lorenzo,
>>
>> LightweightTypeReference.isAssignableFrom is the way to go. Where do you
>> need that functionality specifically?
>>
>> Regards,
>> Sebastian
>
> Hi Sebastian
>
> in my custom validator I need to check whether two types are conformant,
> and I have JvmTypeReference instances, for instance, they are part of a
> method method definition in my DSL, e.g.,
>
> Method:
> type=JvmTypeReference name=ValidID
> '(' (params+=FullJvmFormalParameter (','
> params+=FullJvmFormalParameter)*)? ')'
> ';' ;
>
> thus I don't have LightweightTypeReference available.
>
> Thus, I was wondering whether this code to convert a JvmTypeReference to
> a LightweightTypeReference is the way to go or whether there are better
> solutions:
>
> @Inject CommonTypeComputationServices services;
>
> def isConformant(JvmTypeReference t1, JvmTypeReference t2) {
> t1.toLightweightTypeReference.isAssignableFrom
> (t2.toLightweightTypeReference)
> }
>
> def toLightweightTypeReference(JvmTypeReference typeRef) {
> val converter =
> new OwnedConverter
> (new StandardTypeReferenceOwner
> (services, typeRef))
> converter.toLightweightReference(typeRef)
> }
>
> thanks in advance
> Lorenzo
>

In 2.4, type checks are (usually) done as part of the model inference.
Why do you need to do that in the validator manually? If you use an
infered JVM model, those things will work transparently. Anyway, it's
easy to convert between JvmTypeReference and LightweightTypeReference as
you already sketched in you initial question.

Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: checking type conformance in Xbase 2.4 [message #1041701 is a reply to message #1041676] Mon, 15 April 2013 12:39 Go to previous message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1356
Registered: July 2009
Senior Member
On 04/15/2013 02:04 PM, Sebastian Zarnekow wrote:
> Am 15.04.13 11:09, schrieb Lorenzo Bettini:
>> On 04/15/2013 11:01 AM, Sebastian Zarnekow wrote:
>>> Hi Lorenzo,
>>>
>>> LightweightTypeReference.isAssignableFrom is the way to go. Where do you
>>> need that functionality specifically?
>>>
>>> Regards,
>>> Sebastian
>>
>> Hi Sebastian
>>
>> in my custom validator I need to check whether two types are conformant,
>> and I have JvmTypeReference instances, for instance, they are part of a
>> method method definition in my DSL, e.g.,
>>
>> Method:
>> type=JvmTypeReference name=ValidID
>> '(' (params+=FullJvmFormalParameter (','
>> params+=FullJvmFormalParameter)*)? ')'
>> ';' ;
>>
>> thus I don't have LightweightTypeReference available.
>>
>> Thus, I was wondering whether this code to convert a JvmTypeReference to
>> a LightweightTypeReference is the way to go or whether there are better
>> solutions:
>>
>> @Inject CommonTypeComputationServices services;
>>
>> def isConformant(JvmTypeReference t1, JvmTypeReference t2) {
>> t1.toLightweightTypeReference.isAssignableFrom
>> (t2.toLightweightTypeReference)
>> }
>>
>> def toLightweightTypeReference(JvmTypeReference typeRef) {
>> val converter =
>> new OwnedConverter
>> (new StandardTypeReferenceOwner
>> (services, typeRef))
>> converter.toLightweightReference(typeRef)
>> }
>>
>> thanks in advance
>> Lorenzo
>>
>
> In 2.4, type checks are (usually) done as part of the model inference.
> Why do you need to do that in the validator manually? If you use an
> infered JVM model, those things will work transparently. Anyway, it's

because I need to check for consistencies two elements of my DSL which
represent methods (defined using JvmTypeReference)... would it be
possible to do that in the JvmModelInferrer? Wouldn't it be too late?

> easy to convert between JvmTypeReference and LightweightTypeReference as
> you already sketched in you initial question.

OK :)

thanks
Lorenzo


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Previous Topic:extending scoping for Xbase 2.4.0
Next Topic:Xtext 2.3.1: Deploy generated DSL on JBoss (Debugging)
Goto Forum:
  


Current Time: Tue Sep 23 06:31:27 GMT 2014

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

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