groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Theodorou" <blackd...@gmx.org>
Subject Aw: Re: Calling 'each' on org.eclipse.emf.common.util.TreeIterator
Date Wed, 17 Oct 2018 07:44:08 GMT
<html><head></head><body><div style="font-family: Verdana;font-size:
12.0px;"><div>If it is chosen random it is wrong. It should be either always the
same or fail. This sounds like a bug
<div>&nbsp;
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px
solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b>&nbsp;Dienstag, 16.
Oktober 2018 um 23:36 Uhr<br/>
<b>Von:</b>&nbsp;&quot;Felix Dorner&quot; &lt;felix.dorner@gmail.com&gt;<br/>
<b>An:</b>&nbsp;users@groovy.apache.org<br/>
<b>Betreff:</b>&nbsp;Re: Calling &#39;each&#39; on org.eclipse.emf.common.util.TreeIterator</div>

<div name="quoted-content">
<div>
<div>
<div>Ok so to summarize, the trap is that I call each {} on an object that is both,
an List/Iterable and an Iterator at the same time. The result is that either of these two
is called, and it happens to be random which one.
<div><a href="http://docs.groovy-lang.org/docs/groovy-2.5.1/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#each-java.util.Iterator-groovy.lang.Closure-"
target="_blank">http://docs.groovy-lang.org/docs/groovy-2.5.1/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#each-java.util.Iterator-groovy.lang.Closure-</a></div>

<div><a href="http://docs.groovy-lang.org/docs/groovy-2.5.1/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#each-java.lang.Iterable-groovy.lang.Closure-"
target="_blank">http://docs.groovy-lang.org/docs/groovy-2.5.1/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#each-java.lang.Iterable-groovy.lang.Closure-</a></div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;</div>
</div>
</div>
</div>
&nbsp;

<div class="gmail_quote">
<div>On Tue, Oct 16, 2018 at 6:59 PM Felix Dorner &lt;<a href="mailto:felix.dorner@gmail.com"
onclick="parent.window.location.href=&#39;mailto:felix.dorner@gmail.com&#39;; return
false;" target="_blank">felix.dorner@gmail.com</a>&gt; wrote:</div>

<blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204)
solid;padding-left: 1.0ex;">
<div>I think I &quot;know&quot; what&#39;s going on.. I have a hard time
trying to figure actually out which &#39;each&#39; implementation is called, but if
it is &quot;DefaultGroovyMethods.each&quot;, this will not work: The default groovy
methods each calls &#39;iterator&#39; on the argument, which happens to be defined
in the iterator that I am testing, because that iterator is also a list... (But the tree iterator
contents are actually more than the contents of that list, because the list is a list of root
elements, just imagine a dom tree, it&#39;s the same thing). I&#39;ll figure something
out.</div>

<div>
<div>
<div>&nbsp;
<div>&nbsp;</div>
</div>
</div>
</div>
&nbsp;

<div class="gmail_quote">
<div>On Tue, Oct 16, 2018 at 6:17 PM Felix Dorner &lt;<a href="mailto:felix.dorner@gmail.com"
onclick="parent.window.location.href=&#39;mailto:felix.dorner@gmail.com&#39;; return
false;" target="_blank">felix.dorner@gmail.com</a>&gt; wrote:</div>

<blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204)
solid;padding-left: 1.0ex;">
<div>
<div>
<div>If I use hasNext/next in a while loop, I get at the content as expected, but not
if I use the collection extensions such as &#39;each&#39;. I don&#39;t know where
the magic fails, but I want to find out.. The iterator that is being used is created here:
<div>&nbsp;</div>

<div><a href="http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/impl/BasicEObjectImpl.java#n832"
target="_blank">http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/impl/BasicEObjectImpl.java#n832</a>
and that is an anonymous subtype of&nbsp;</div>

<div><a href="http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.common/src/org/eclipse/emf/common/util/AbstractTreeIterator.java"
target="_blank">http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.common/src/org/eclipse/emf/common/util/AbstractTreeIterator.java</a></div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;</div>
</div>
</div>
</div>
&nbsp;

<div class="gmail_quote">
<div>On Tue, Oct 16, 2018 at 3:21 PM Paul King &lt;<a href="mailto:paulk@asert.com.au"
onclick="parent.window.location.href=&#39;mailto:paulk@asert.com.au&#39;; return false;"
target="_blank">paulk@asert.com.au</a>&gt; wrote:</div>

<blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204)
solid;padding-left: 1.0ex;">
<div>I&#39;d expect that to work the same as if you used a while loop with hasNext()
and next(). If your data structure has further containers and next() doesn&#39;t normally
walk through the containers, then I&#39;d expect you to have more work to do. Is that
not what you are seeing?
<div>&nbsp;</div>

<div>Cheers, Paul.</div>
</div>
&nbsp;

<div class="gmail_quote">
<div>On Tue, Oct 16, 2018 at 8:23 PM Felix Dorner &lt;<a href="mailto:felix.dorner@gmail.com"
onclick="parent.window.location.href=&#39;mailto:felix.dorner@gmail.com&#39;; return
false;" target="_blank">felix.dorner@gmail.com</a>&gt; wrote:</div>

<blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204)
solid;padding-left: 1.0ex;">
<div>Hi,
<div>&nbsp;</div>

<div>I can do:</div>

<div>def a = [1,2,3].iterator()
<div>a.each {</div>

<div>&nbsp; &nbsp;println it</div>

<div>}</div>

<div>&nbsp;</div>

<div>Cool, I can walk EMF EObject trees like this, I thought:</div>

<div>&nbsp;</div>

<div>Iterator i = anEObject.eAllContents() // this gives a TreeIterator, a subinterface
of Iterator</div>

<div>it.each {</div>

<div>&nbsp; println it</div>

<div>}</div>

<div>&nbsp;</div>

<div>But that doesn&#39;t work :(. It only prints anEObject, not the whole content
tree. Anyone can explain why?</div>

<div>&nbsp;</div>

<div>&nbsp;</div>
--

<div class="m_-4727836138658384103m_1931446383947396775m_-7329654928673691595m_-3566910685123159176m_4472695335077671128gmail_signature">Linux.
The choice of a GNU generation.</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
&nbsp;

<div>&nbsp;</div>
--

<div class="m_-4727836138658384103m_1931446383947396775m_-7329654928673691595gmail_signature">Linux.
The choice of a GNU generation.</div>
</blockquote>
</div>
&nbsp;

<div>&nbsp;</div>
--

<div class="m_-4727836138658384103m_1931446383947396775gmail_signature">Linux. The choice
of a GNU generation.</div>
</blockquote>
</div>
&nbsp;

<div>&nbsp;</div>
--

<div class="gmail_signature">Linux. The choice of a GNU generation.</div>
</div>
</div>
</div>
</div></div></body></html>

Mime
View raw message