Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to Access All Elements
How to Access All Elements [message #64281] Mon, 13 July 2009 10:23 Go to next message
Markus Voelter is currently offline Markus Voelter
Messages: 16
Registered: July 2009
Junior Member
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 #64326 is a reply to message #64281] Mon, 13 July 2009 13:24 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1762
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
>


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: How to Access All Elements [message #64601 is a reply to message #64326] Fri, 17 July 2009 13:31 Go to previous messageGo to next message
Markus Voelter is currently offline 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 Go to previous messageGo to next message
Markus Voelter is currently offline 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 #64647 is a reply to message #64601] Fri, 17 July 2009 14:07 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1762
Registered: July 2009
Senior Member
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


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: How to Access All Elements [message #64739 is a reply to message #64647] Tue, 21 July 2009 07:29 Go to previous messageGo to next message
Markus Voelter is currently offline Markus Voelter
Messages: 16
Registered: July 2009
Junior Member
> 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?

"file" is an instance of an EClass called Resource (yes, bad name,
but it is an EObject).

I can send you the code privately....?

> I'm talking of the std-lib project you initialized for Xpand.
> It is part of M2T/Xpand.

ah, ok, I see.

I was asking because at some point you also talked about a
stdlib for TMF/Xtext. Is this also in the works?

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 Go to previous messageGo to next message
Markus Voelter is currently offline 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 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2832
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 Go to previous message
Markus Voelter is currently offline 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
Previous Topic:Re: JET2 in emft project
Next Topic:[EMF] use annotation in "body" of EOperation
Goto Forum:
  


Current Time: Thu Sep 18 22:00:51 GMT 2014

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

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