Home » Modeling » M2T (model-to-text transformation) » How to Access All Elements
|
Re: How to Access All Elements [message #64326 is a reply to message #64281] |
Mon, 13 July 2009 13:24 |
Sven Efftinge Messages: 1823 Registered: July 2009 |
Senior Member |
|
|
Hi Markus,
there is some functionality in EcoreUtil doing what you're looking for:
EcoreUtil.getAllContents(resourceSet, true);
You'll have to write a JAVA extension and in Java do some conversion
from Iterator to List, because EcoreUtil returns iterators and in Xtend
you'll want a list.
This might be something for the standard-lib.
Cheers,
Sven
Markus Voelter schrieb:
> Hi,
>
> I am using a CheckValidator for my language.
>
> In the code generator workflow, I want to validate
> all elements in all models, including those imported
> into my language. In other words, I need the equivalent
> of 4.3.1's allElements() extension to get a collection
> of truly all model elements the generator will process.
>
> How can I do this in the 0.7 release?
>
> Thanks,
> Markus
>
|
|
|
Re: How to Access All Elements [message #64601 is a reply to message #64326] |
Fri, 17 July 2009 13:31 |
Markus Voelter Messages: 16 Registered: July 2009 |
Junior Member |
|
|
> You'll have to write a JAVA extension and in Java do some conversion
> from Iterator to List, because EcoreUtil returns iterators and in Xtend
> you'll want a list.
I have implemented this:
public static List<EObject> allElements( EObject anElementInRootResource ) {
ResourceSet rs = anElementInRootResource.eResource().getResourceSet();
TreeIterator<EObject> all = EcoreUtil.getAllContents(rs, true);
List<EObject> result = new ArrayList<EObject>();
while ( all.hasNext() ) {
result.add(all.next());
}
return result;
}
But if I run it, I get:
3234 [main] ERROR org.eclipse.xtend.XtendComponent - Error in Component of type org.eclipse.xtend.XtendComponent:
EvaluationException : java.lang.ClassCastException: org.eclipse.xtext.linking.lazy.LazyLinkingResource cannot be cast to org.eclipse.emf.ecore.EObject
bwin::ai::btarget::stresstest::vis::main.ext[656,13] on line 18 'file.allElements()'
bwin::ai::btarget::stresstest::vis::main.ext[556,21] on line 15 'toGraphVizmodel(file)'
nofile[0,10] on line 1 'top(model)'
> This might be something for the standard-lib.
Where is this standard-lib? I'd have a couple of other things to contribute.
Markus
>
> Cheers,
> Sven
>
> Markus Voelter schrieb:
>> Hi,
>>
>> I am using a CheckValidator for my language.
>>
>> In the code generator workflow, I want to validate
>> all elements in all models, including those imported
>> into my language. In other words, I need the equivalent
>> of 4.3.1's allElements() extension to get a collection
>> of truly all model elements the generator will process.
>>
>> How can I do this in the 0.7 release?
>>
>> Thanks,
>> Markus
>>
--
Markus Völter
voelter - ingenieurbüro für softwaretechnologie/itemis
Ötztaler Strasse 38, 70327 Stuttgart-Untertürkheim, Germany
Tel. +49 (0) 171 / 86 01 869
Email: voelter@acm.org
Web: http://www.voelter.de
Blog: http://www.voelter.de/blog
SE Radio Podcast: http://www.se-radio.net
omega tau podcast: http://www.omegataupodcast.net
|
|
|
Re: How to Access All Elements [message #64624 is a reply to message #64326] |
Fri, 17 July 2009 13:31 |
Markus Voelter Messages: 16 Registered: July 2009 |
Junior Member |
|
|
> You'll have to write a JAVA extension and in Java do some conversion
> from Iterator to List, because EcoreUtil returns iterators and in Xtend
> you'll want a list.
I have implemented this:
public static List<EObject> allElements( EObject anElementInRootResource ) {
ResourceSet rs = anElementInRootResource.eResource().getResourceSet();
TreeIterator<EObject> all = EcoreUtil.getAllContents(rs, true);
List<EObject> result = new ArrayList<EObject>();
while ( all.hasNext() ) {
result.add(all.next());
}
return result;
}
But if I run it, I get:
3234 [main] ERROR org.eclipse.xtend.XtendComponent - Error in Component of type org.eclipse.xtend.XtendComponent:
EvaluationException : java.lang.ClassCastException: org.eclipse.xtext.linking.lazy.LazyLinkingResource cannot be cast to org.eclipse.emf.ecore.EObject
bwin::ai::btarget::stresstest::vis::main.ext[656,13] on line 18 'file.allElements()'
bwin::ai::btarget::stresstest::vis::main.ext[556,21] on line 15 'toGraphVizmodel(file)'
nofile[0,10] on line 1 'top(model)'
> This might be something for the standard-lib.
Where is this standard-lib? I'd have a couple of other things to contribute.
Markus
>
> Cheers,
> Sven
>
> Markus Voelter schrieb:
>> Hi,
>>
>> I am using a CheckValidator for my language.
>>
>> In the code generator workflow, I want to validate
>> all elements in all models, including those imported
>> into my language. In other words, I need the equivalent
>> of 4.3.1's allElements() extension to get a collection
>> of truly all model elements the generator will process.
>>
>> How can I do this in the 0.7 release?
>>
>> Thanks,
>> Markus
>>
--
Markus Völter
voelter - ingenieurbüro für softwaretechnologie/itemis
Ötztaler Strasse 38, 70327 Stuttgart-Untertürkheim, Germany
Tel. +49 (0) 171 / 86 01 869
Email: voelter@acm.org
Web: http://www.voelter.de
Blog: http://www.voelter.de/blog
SE Radio Podcast: http://www.se-radio.net
omega tau podcast: http://www.omegataupodcast.net
|
|
| | |
Re: How to Access All Elements [message #64762 is a reply to message #64647] |
Tue, 21 July 2009 07:50 |
Markus Voelter Messages: 16 Registered: July 2009 |
Junior Member |
|
|
It seems the TreeIterator doesn't just contain the EObjects, but
also the Resources that contain them. In the following output ...
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ............................................................ ............................................................ ............................................................ ........................
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ................................................
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
.... each dot is an EObject, and the other ones you can see.
is this intended? Do I have to traverse the LazyLinkingResource
myself?
Markus
Sven Efftinge wrote:
> Hi Markus,
>
> Markus Voelter schrieb:
>> I have implemented this:
>>
>> public static List<EObject> allElements( EObject
>> anElementInRootResource ) {
>> ResourceSet rs =
>> anElementInRootResource.eResource().getResourceSet();
>> TreeIterator<EObject> all = EcoreUtil.getAllContents(rs, true);
>> List<EObject> result = new ArrayList<EObject>();
>> while ( all.hasNext() ) {
>> result.add(all.next());
>> }
>> return result;
>> }
>>
>> But if I run it, I get:
>>
>> 3234 [main] ERROR org.eclipse.xtend.XtendComponent - Error in
>> Component of type org.eclipse.xtend.XtendComponent:
>> EvaluationException : java.lang.ClassCastException:
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource cannot be cast to
>> org.eclipse.emf.ecore.EObject
>> bwin::ai::btarget::stresstest::vis::main.ext[656,13] on line 18
>> 'file.allElements()'
>> bwin::ai::btarget::stresstest::vis::main.ext[556,21] on line 15
>> 'toGraphVizmodel(file)'
>> nofile[0,10] on line 1 'top(model)'
>
> I cannot see where this ClassCastException could occur in the given
> code. Could it be that 'file' in the Xtend code is a Resource and not an
> EObject?
>
>>
>>> This might be something for the standard-lib.
>>
>> Where is this standard-lib? I'd have a couple of other things to
>> contribute.
>
> I'm talking of the std-lib project you initialized for Xpand.
> It is part of M2T/Xpand.
>
> Cheers,
> Sven
>
--
Markus Völter
voelter - ingenieurbüro für softwaretechnologie/itemis
Ötztaler Strasse 38, 70327 Stuttgart-Untertürkheim, Germany
Tel. +49 (0) 171 / 86 01 869
Email: voelter@acm.org
Web: http://www.voelter.de
Blog: http://www.voelter.de/blog
SE Radio Podcast: http://www.se-radio.net
omega tau podcast: http://www.omegataupodcast.net
|
|
|
Re: How to Access All Elements [message #64785 is a reply to message #64762] |
Tue, 21 July 2009 10:04 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Markus,
this seems to be intended even if is somewhat counter-intuitive.
Please use the Iterators and Lists classes from google collections for
your convenience:
Iterator<EObject> iter = Iterators.filter(
EcoreUtil.getAllContents(resourceSet, true), EObject.class);
return Lists.newArrayList(iter);
Hope that helps,
Sebastian
Am 21.07.2009 9:50 Uhr, schrieb Markus Voelter:
> It seems the TreeIterator doesn't just contain the EObjects, but
> also the Resources that contain them. In the following output ...
>
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ............................................................ ............................................................ ............................................................ ........................
>
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ................................................
>
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
>
> .... each dot is an EObject, and the other ones you can see.
>
> is this intended? Do I have to traverse the LazyLinkingResource
> myself?
>
> Markus
>
>
> Sven Efftinge wrote:
>> Hi Markus,
>>
>> Markus Voelter schrieb:
>>> I have implemented this:
>>>
>>> public static List<EObject> allElements( EObject
>>> anElementInRootResource ) {
>>> ResourceSet rs = anElementInRootResource.eResource().getResourceSet();
>>> TreeIterator<EObject> all = EcoreUtil.getAllContents(rs, true);
>>> List<EObject> result = new ArrayList<EObject>();
>>> while ( all.hasNext() ) {
>>> result.add(all.next());
>>> }
>>> return result;
>>> }
>>>
>>> But if I run it, I get:
>>>
>>> 3234 [main] ERROR org.eclipse.xtend.XtendComponent - Error in
>>> Component of type org.eclipse.xtend.XtendComponent:
>>> EvaluationException : java.lang.ClassCastException:
>>> org.eclipse.xtext.linking.lazy.LazyLinkingResource cannot be cast to
>>> org.eclipse.emf.ecore.EObject
>>> bwin::ai::btarget::stresstest::vis::main.ext[656,13] on line 18
>>> 'file.allElements()'
>>> bwin::ai::btarget::stresstest::vis::main.ext[556,21] on line 15
>>> 'toGraphVizmodel(file)'
>>> nofile[0,10] on line 1 'top(model)'
>>
>> I cannot see where this ClassCastException could occur in the given
>> code. Could it be that 'file' in the Xtend code is a Resource and not
>> an EObject?
>>
>>>
>>>> This might be something for the standard-lib.
>>>
>>> Where is this standard-lib? I'd have a couple of other things to
>>> contribute.
>>
>> I'm talking of the std-lib project you initialized for Xpand.
>> It is part of M2T/Xpand.
>>
>> Cheers,
>> Sven
>>
>
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Re: How to Access All Elements [message #64831 is a reply to message #64785] |
Wed, 22 July 2009 08:58 |
Markus Voelter Messages: 16 Registered: July 2009 |
Junior Member |
|
|
yes it helps, thanks.
Markus
Sebastian Zarnekow wrote:
> Hi Markus,
>
> this seems to be intended even if is somewhat counter-intuitive.
>
> Please use the Iterators and Lists classes from google collections for
> your convenience:
>
> Iterator<EObject> iter = Iterators.filter(
> EcoreUtil.getAllContents(resourceSet, true), EObject.class);
> return Lists.newArrayList(iter);
>
> Hope that helps,
> Sebastian
>
> Am 21.07.2009 9:50 Uhr, schrieb Markus Voelter:
>> It seems the TreeIterator doesn't just contain the EObjects, but
>> also the Resources that contain them. In the following output ...
>>
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ............................................................ ............................................................ ............................................................ ........................
>>
>>
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ................................................
>>
>>
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... ........
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
>> org.eclipse.xtext.linking.lazy.LazyLinkingResource.......... .............
>>
>> .... each dot is an EObject, and the other ones you can see.
>>
>> is this intended? Do I have to traverse the LazyLinkingResource
>> myself?
>>
>> Markus
>>
>>
>> Sven Efftinge wrote:
>>> Hi Markus,
>>>
>>> Markus Voelter schrieb:
>>>> I have implemented this:
>>>>
>>>> public static List<EObject> allElements( EObject
>>>> anElementInRootResource ) {
>>>> ResourceSet rs = anElementInRootResource.eResource().getResourceSet();
>>>> TreeIterator<EObject> all = EcoreUtil.getAllContents(rs, true);
>>>> List<EObject> result = new ArrayList<EObject>();
>>>> while ( all.hasNext() ) {
>>>> result.add(all.next());
>>>> }
>>>> return result;
>>>> }
>>>>
>>>> But if I run it, I get:
>>>>
>>>> 3234 [main] ERROR org.eclipse.xtend.XtendComponent - Error in
>>>> Component of type org.eclipse.xtend.XtendComponent:
>>>> EvaluationException : java.lang.ClassCastException:
>>>> org.eclipse.xtext.linking.lazy.LazyLinkingResource cannot be cast to
>>>> org.eclipse.emf.ecore.EObject
>>>> bwin::ai::btarget::stresstest::vis::main.ext[656,13] on line 18
>>>> 'file.allElements()'
>>>> bwin::ai::btarget::stresstest::vis::main.ext[556,21] on line 15
>>>> 'toGraphVizmodel(file)'
>>>> nofile[0,10] on line 1 'top(model)'
>>>
>>> I cannot see where this ClassCastException could occur in the given
>>> code. Could it be that 'file' in the Xtend code is a Resource and not
>>> an EObject?
>>>
>>>>
>>>>> This might be something for the standard-lib.
>>>>
>>>> Where is this standard-lib? I'd have a couple of other things to
>>>> contribute.
>>>
>>> I'm talking of the std-lib project you initialized for Xpand.
>>> It is part of M2T/Xpand.
>>>
>>> Cheers,
>>> Sven
>>>
>>
>>
>
>
--
Markus Völter
voelter - ingenieurbüro für softwaretechnologie/itemis
Ötztaler Strasse 38, 70327 Stuttgart-Untertürkheim, Germany
Tel. +49 (0) 171 / 86 01 869
Email: voelter@acm.org
Web: http://www.voelter.de
Blog: http://www.voelter.de/blog
SE Radio Podcast: http://www.se-radio.net
omega tau podcast: http://www.omegataupodcast.net
|
|
|
Goto Forum:
Current Time: Wed Dec 04 08:46:48 GMT 2024
Powered by FUDForum. Page generated in 0.03192 seconds
|