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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: checking type conformance in Xbase 2.4 [message #1041571 is a reply to message #1040951] |
Mon, 15 April 2013 09:01 |
Sebastian Zarnekow Messages: 3118 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: checking type conformance in Xbase 2.4 [message #1041676 is a reply to message #1041575] |
Mon, 15 April 2013 12:04 |
Sebastian Zarnekow Messages: 3118 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Goto Forum:
Current Time: Fri Mar 29 00:32:06 GMT 2024
Powered by FUDForum. Page generated in 0.04540 seconds
|