Discussion:
XML: Methods on class groovy.util.Node
Detering Dirk
2005-11-05 10:00:16 UTC
Permalink
Hello all,

I actually stumbled over a thing where I
was unfortunately 'suprised' by Groovy:

Trying to read an XML file via XmlParser
and iterate over the Node tree, I intuitively
wrote this code but branches were never executed.
I tried to debug with println statements:

First variant:

(content is the result of new XmlParser.parse('filename'))

println content // => all seems fine, content is shown as
// nested list.

content.children.each { node ->
// => Never reached ...
println "INSIDE NODE"
println node
}

Second variant:

println content
println content.children // => Empty list: []
println content.iterator.toString() // => Emtpy list: []
println content.text // => Empty list: []
println content.value // => NullPointerException !?

.... Well, it took me one recreative night
to realise, that I used Property syntax instead of
method calls ...

Last variant:

println content
println content.value()
println content.text()
println content.children()
println content.iterator().toString()

content.children().each { node ->
...

and all works fine.

The first point here is, that handling of nodes
would be groovier if the methods would be named
getValue(), getChildren(), getIterator(), getText()
and so could be called without the braces (especially
as they take no arguments), just like a Path expression.
Or in another way: If the Node class would contain
Properties instead of methods.

Second it was very misleading that the access
without braces did not result in a 'no such property'
message but in a return value of the correct type
(but without the correct content).

Indeed I expected (without logical reason, I know!) to be
able to call the methods without parameters listed in:
http://groovy.codehaus.org/apidocs/groovy/util/Node.html
without the braces.

My question now: Is it correct as it is (and the problem
is my wrong intuitive expectation)?
Should Node contain Properties instead?
Anything else?

Bye
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
Dierk Koenig
2005-11-05 11:34:36 UTC
Permalink
+1 for supporting the bean style access

You can link you issue to GROOVY-1121.

cheers
Mittie
-----Original Message-----
Sent: Samstag, 5. November 2005 11:00
Subject: [groovy-user] XML: Methods on class groovy.util.Node
Hello all,
I actually stumbled over a thing where I
Trying to read an XML file via XmlParser
and iterate over the Node tree, I intuitively
wrote this code but branches were never executed.
(content is the result of new XmlParser.parse('filename'))
println content // => all seems fine, content is shown as
// nested list.
content.children.each { node ->
// => Never reached ...
println "INSIDE NODE"
println node
}
println content
println content.children // => Empty list: []
println content.iterator.toString() // => Emtpy list: []
println content.text // => Empty list: []
println content.value // => NullPointerException !?
.... Well, it took me one recreative night
to realise, that I used Property syntax instead of
method calls ...
println content
println content.value()
println content.text()
println content.children()
println content.iterator().toString()
content.children().each { node ->
...
and all works fine.
The first point here is, that handling of nodes
would be groovier if the methods would be named
getValue(), getChildren(), getIterator(), getText()
and so could be called without the braces (especially
as they take no arguments), just like a Path expression.
Or in another way: If the Node class would contain
Properties instead of methods.
Second it was very misleading that the access
without braces did not result in a 'no such property'
message but in a return value of the correct type
(but without the correct content).
Indeed I expected (without logical reason, I know!) to be
http://groovy.codehaus.org/apidocs/groovy/util/Node.html
without the braces.
My question now: Is it correct as it is (and the problem
is my wrong intuitive expectation)?
Should Node contain Properties instead?
Anything else?
Bye
Det
***********************************************************************
Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.
***********************************************************************
Detering Dirk
2005-11-05 13:12:14 UTC
Permalink
Post by Dierk Koenig
You can link you issue to GROOVY-1121.
Created issue GROOVY-1134
(Sorry for the first comment on 1121, I'm not
used to JIRA tracking tool).
Post by Dierk Koenig
Second it was very misleading that the access
without braces did not result in a 'no such property'
message but in a return value of the correct type
(but without the correct content).
Can somebody declare this to me?

TNX
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
John Wilson
2005-11-05 13:44:22 UTC
Permalink
Post by Detering Dirk
Indeed I expected (without logical reason, I know!) to be
http://groovy.codehaus.org/apidocs/groovy/util/Node.html
without the braces.
My question now: Is it correct as it is (and the problem
is my wrong intuitive expectation)?
Should Node contain Properties instead?
Anything else?
The behaviour of Node is correct. I'm sorry you were surprised but I
think it *has* to work this way.

What would happen if you had a document with am element <children>?

You would them expect

"content.children.each {" to iterate through all the <children> nodes
wouldn't you?

The system can on;y know what you have typed not what you mean:)



John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Dierk Koenig
2005-11-05 14:08:15 UTC
Permalink
how about this:

if there are 'children' elements, they have precedence
and you have to fall back to getChildren() to call the method.

in other words:
always use getChildren() and if you use property-style
access do on your own risk :-)

otherwise we would have to rename the methods to some
non-conflicting name like
listChildren()
allChildren()
or such...

cheers
Mittie
-----Original Message-----
Sent: Samstag, 5. November 2005 14:44
Subject: Re: [groovy-user] XML: Methods on class groovy.util.Node
Post by Detering Dirk
Indeed I expected (without logical reason, I know!) to be
http://groovy.codehaus.org/apidocs/groovy/util/Node.html
without the braces.
My question now: Is it correct as it is (and the problem
is my wrong intuitive expectation)?
Should Node contain Properties instead?
Anything else?
The behaviour of Node is correct. I'm sorry you were surprised but I
think it *has* to work this way.
What would happen if you had a document with am element <children>?
You would them expect
"content.children.each {" to iterate through all the <children> nodes
wouldn't you?
The system can on;y know what you have typed not what you mean:)
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
John Wilson
2005-11-05 16:28:02 UTC
Permalink
Post by Dierk Koenig
if there are 'children' elements, they have precedence
and you have to fall back to getChildren() to call the method.
always use getChildren() and if you use property-style
access do on your own risk :-)
otherwise we would have to rename the methods to some
non-conflicting name like
listChildren()
allChildren()
Personally I'm perfect;y happy with the way things are. The names
have been the same for a couple of years and are in daily use in the
field.

Why lay traps for people to fall into?


John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Dierk Koenig
2005-11-05 17:20:17 UTC
Permalink
That's also ok for me.

cheers
Mittie
-----Original Message-----
Sent: Samstag, 5. November 2005 17:28
Subject: Re: [groovy-user] XML: Methods on class groovy.util.Node
Post by Dierk Koenig
if there are 'children' elements, they have precedence
and you have to fall back to getChildren() to call the method.
always use getChildren() and if you use property-style
access do on your own risk :-)
otherwise we would have to rename the methods to some
non-conflicting name like
listChildren()
allChildren()
Personally I'm perfect;y happy with the way things are. The names
have been the same for a couple of years and are in daily use in the
field.
Why lay traps for people to fall into?
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Ken Pelletier
2005-11-05 22:18:02 UTC
Permalink
How can I use GPath when element names in the xml I'm using collide
with groovy reserved words or tokens?

I'm parsing an xml generated with a test coverage tool, cobertura
(which is quite good, btw), and it has elements such as 'package' and
'class', etc.

The xml contains elements for 'package' and 'class', which collide
with Java keywords, and so groovy as well.

Here's a simplified outline of the xml:

<coverage src="/blah/foo/project/src">
<packages>
<package name="foo">
<classes>
<class name="foo.Class1"/>
<class name="foo.Class2"/>
</classes>
<package name="bar">
<class name="bar.Class1"/>
</package>
</package>
</packages>
</coverage>

Assuming 'coverage' is the parsed xml doc, a GPath for all class
nodes might be:

coverage.packages.package.classes.class

The use of 'package' causes a parse error, of course:

unexpected token: . @ line 8, column 19.

This is the '.' following 'package'. Ok, so I discovered that i can
quote the steps in the GPath:

coverage.packages.'package'.classes.class

'class' is another collision, so the result of that expression is
'java.util.ArrayList' since the class of that step in the GPath is an
ArrayList.

However, quoting 'class' doesn't give me the element at that step,
but still gives me the Class of that step: 'java.util.ArrayList'

I like the notion of slinging XML with groovy in an XPath-y way,
without all the fuss, but I feel like I'm missing something (a lot,
probably) fundamental about GPath that's preventing me from really
getting on with it. I've looked for the answers but can't quite find
the examples that enlighten me.

- Ken
John Wilson
2005-11-05 22:55:10 UTC
Permalink
Post by Ken Pelletier
How can I use GPath when element names in the xml I'm using collide
with groovy reserved words or tokens?
I'm parsing an xml generated with a test coverage tool, cobertura
(which is quite good, btw), and it has elements such as 'package'
and 'class', etc.
The xml contains elements for 'package' and 'class', which collide
with Java keywords, and so groovy as well.
<coverage src="/blah/foo/project/src">
<packages>
<package name="foo">
<classes>
<class name="foo.Class1"/>
<class name="foo.Class2"/>
</classes>
<package name="bar">
<class name="bar.Class1"/>
</package>
</package>
</packages>
</coverage>
Assuming 'coverage' is the parsed xml doc, a GPath for all class
coverage.packages.package.classes.class
This is the '.' following 'package'. Ok, so I discovered that i
coverage.packages.'package'.classes.class
'class' is another collision, so the result of that expression is
'java.util.ArrayList' since the class of that step in the GPath is
an ArrayList.
However, quoting 'class' doesn't give me the element at that step,
but still gives me the Class of that step: 'java.util.ArrayList'
I like the notion of slinging XML with groovy in an XPath-y way,
without all the fuss, but I feel like I'm missing something (a lot,
probably) fundamental about GPath that's preventing me from really
getting on with it. I've looked for the answers but can't quite
find the examples that enlighten me.
I presume you are using XmlParser not XmlSlurper?

Your GPath expression (once you have used quotes to avoid clashes
with keywords) will evaluate to all the class elements inside classes
elements inside package elements inside packages elements. I count
three of these. Applying your GPath expression to the object returned
by running XmlParser on your document will produce a List of the
elements.

What did you expect to get?

If you add ".each { some code }" to your GPath expression you can do
something with each of the three elements.

However I supect that this isn't what you want to do/ Could you
please tell is what you are trying to do to this document?




John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Ken Pelletier
2005-11-05 23:17:23 UTC
Permalink
Thanks for the quick reply.

I'm finding that when I refer to the 'class' step of that path, it
returns a Class object for java.util.ArrayList rather than an
ArrayList instance containing the 'class' element nodes from the doc.

coverage.packages.'package'.classes.'class'.each { println it }
==> class java.util.ArrayList

coverage.packages.'package'.classes.'class'.each { println it.class }
==> class java.lang.Class

So, where I would expect 'class' to be the ArrayList of Node
containing one per 'class' element, it's actually the Class object of
ArrayList itself.

That's with or without the quotes on 'class'; it behaves as if the
escaping of 'class' isn't applied and calls 'getClass()' on the
object produced by the GPath up to that step - an ArrayList.

Yes, I am using XmlParser to get the doc.

What I'm trying to do is get my feet wet with groovy's xml handling
to see if it can help me transform and combine a load of xml coverage
artifacts into a single summary doc - as an alternative to an xslt
solution.

As a first step along the way I'm just trying to walk around the
document and select elems and attrs with groovy to understand what it
can do here.

Regards,

- Ken
Post by John Wilson
Post by Ken Pelletier
How can I use GPath when element names in the xml I'm using
collide with groovy reserved words or tokens?
I'm parsing an xml generated with a test coverage tool, cobertura
(which is quite good, btw), and it has elements such as 'package'
and 'class', etc.
The xml contains elements for 'package' and 'class', which collide
with Java keywords, and so groovy as well.
<coverage src="/blah/foo/project/src">
<packages>
<package name="foo">
<classes>
<class name="foo.Class1"/>
<class name="foo.Class2"/>
</classes>
<package name="bar">
<class name="bar.Class1"/>
</package>
</package>
</packages>
</coverage>
Assuming 'coverage' is the parsed xml doc, a GPath for all class
coverage.packages.package.classes.class
This is the '.' following 'package'. Ok, so I discovered that i
coverage.packages.'package'.classes.class
'class' is another collision, so the result of that expression is
'java.util.ArrayList' since the class of that step in the GPath is
an ArrayList.
However, quoting 'class' doesn't give me the element at that step,
but still gives me the Class of that step: 'java.util.ArrayList'
I like the notion of slinging XML with groovy in an XPath-y way,
without all the fuss, but I feel like I'm missing something (a
lot, probably) fundamental about GPath that's preventing me from
really getting on with it. I've looked for the answers but can't
quite find the examples that enlighten me.
I presume you are using XmlParser not XmlSlurper?
Your GPath expression (once you have used quotes to avoid clashes
with keywords) will evaluate to all the class elements inside
classes elements inside package elements inside packages elements.
I count three of these. Applying your GPath expression to the
object returned by running XmlParser on your document will produce
a List of the elements.
What did you expect to get?
If you add ".each { some code }" to your GPath expression you can
do something with each of the three elements.
However I supect that this isn't what you want to do/ Could you
please tell is what you are trying to do to this document?
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
John Wilson
2005-11-05 23:24:22 UTC
Permalink
Post by Ken Pelletier
Thanks for the quick reply.
I'm finding that when I refer to the 'class' step of that path, it
returns a Class object for java.util.ArrayList rather than an
ArrayList instance containing the 'class' element nodes from the doc.
coverage.packages.'package'.classes.'class'.each { println it }
==> class java.util.ArrayList
coverage.packages.'package'.classes.'class'.each { println it.class }
==> class java.lang.Class
So, where I would expect 'class' to be the ArrayList of Node
containing one per 'class' element, it's actually the Class object
of ArrayList itself.
That's with or without the quotes on 'class'; it behaves as if the
escaping of 'class' isn't applied and calls 'getClass()' on the
object produced by the GPath up to that step - an ArrayList.
Yes, I am using XmlParser to get the doc.
What I'm trying to do is get my feet wet with groovy's xml handling
to see if it can help me transform and combine a load of xml
coverage artifacts into a single summary doc - as an alternative to
an xslt solution.
As a first step along the way I'm just trying to walk around the
document and select elems and attrs with groovy to understand what
it can do here.
OK - you may well have hit an interesting problem:)

It's rather late here in the UK so I'm going to bed.

I'll look into it in detail when i wake up - I'll get back to you
within 24 hours.


John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Ken Pelletier
2005-11-05 23:35:33 UTC
Permalink
Thanks, John.

It will likely be helpful to you to know that I'm using jsr-03.

I'm building from cvs now to see if it exhibits the same behaviour.
- K
Post by John Wilson
Post by Ken Pelletier
Thanks for the quick reply.
I'm finding that when I refer to the 'class' step of that path, it
returns a Class object for java.util.ArrayList rather than an
ArrayList instance containing the 'class' element nodes from the doc.
coverage.packages.'package'.classes.'class'.each { println it }
==> class java.util.ArrayList
coverage.packages.'package'.classes.'class'.each { println it.class }
==> class java.lang.Class
So, where I would expect 'class' to be the ArrayList of Node
containing one per 'class' element, it's actually the Class object
of ArrayList itself.
That's with or without the quotes on 'class'; it behaves as if the
escaping of 'class' isn't applied and calls 'getClass()' on the
object produced by the GPath up to that step - an ArrayList.
Yes, I am using XmlParser to get the doc.
What I'm trying to do is get my feet wet with groovy's xml
handling to see if it can help me transform and combine a load of
xml coverage artifacts into a single summary doc - as an
alternative to an xslt solution.
As a first step along the way I'm just trying to walk around the
document and select elems and attrs with groovy to understand what
it can do here.
OK - you may well have hit an interesting problem:)
It's rather late here in the UK so I'm going to bed.
I'll look into it in detail when i wake up - I'll get back to you
within 24 hours.
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Siegfried Heintze
2005-11-06 05:32:09 UTC
Permalink
I'm trying to follow the instructions at
http://groovy.codehaus.org/Eclipse+Plugin as carefully as I can. I get 100
warnings and no errors when I use CVS to download! (The web page said 45
warnings).

I click on the plugin.xml and then "Launch an Eclipse Application". I create
a new java project called groovy_test with a package called groovy.test.
When I try to add a class however, I get his error:

"Unable to create this part due to an internal error. Reason for the
failure: The editor class could not be instantiated. This usually indicates
that the editor's class name was mistyped in plugin.xml.

I get this same error when I unzip the directory in the binary directory and
copy the contents of the plugin directory to the plugin directory in the
eclipse installation.

What am I doing wrong?

Thanks,
Siegfried


java.lang.NoClassDefFoundError: org/eclipse/ui/texteditor/ExtendedTextEditor
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.defineClass(Defau
ltClassLoader.java:370)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.defineClass(EclipseClass
Loader.java:233)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.findClassImpl(Def
aultClassLoader.java:343)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.findClass(Default
ClassLoader.java:235)
at
org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.findLocalClass(A
bstractClassLoader.java:183)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.basicFindLocalClass(Ecli
pseClassLoader.java:141)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.findLocalClass(EclipseCl
assLoader.java:68)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleL
oader.java:337)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader
.java:389)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader
.java:350)
at
org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(Abstra
ctClassLoader.java:78)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader
.java:275)
at
org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.jav
a:227)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBu
ndle.java:1248)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:152)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:142)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:129)
at
org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutab
leExtension(ConfigurationElementHandle.java:48)
at
org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java
:232)
at
org.eclipse.ui.internal.registry.EditorDescriptor.createEditor(EditorDescrip
tor.java:252)
at
org.eclipse.ui.internal.EditorManager.createPart(EditorManager.java:842)
at
org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.jav
a:562)
at
org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:384)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReferenc
e.java:552)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:283)
at
org.eclipse.ui.internal.presentations.PresentablePart.setVisible(Presentable
Part.java:126)
at
org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(Pres
entablePartFolder.java:268)
at
org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftTo
RightTabOrder.java:65)
at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPar
t(TabbedStackPresentation.java:391)
at
org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.jav
a:1102)
at
org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1051)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1256)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:442)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:109)
at
org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.ja
va:60)
at
org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:2
12)
at
org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:202
)
at
org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:758
)
at
org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager
.java:665)
at
org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:628)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.ja
va:2360)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2295
)
at
org.eclipse.ui.internal.WorkbenchPage.access$9(WorkbenchPage.java:2287)
at
org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:2273)
at
org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2268)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2249)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:371)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:334)
at
org.eclipse.jdt.internal.ui.wizards.NewElementWizard$1.run(NewElementWizard.
java:71)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
at
org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3057)
at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2716)
at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at
org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.
java:226)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
Hein Meling
2005-11-06 08:08:33 UTC
Permalink
Post by Siegfried Heintze
I'm trying to follow the instructions at
http://groovy.codehaus.org/Eclipse+Plugin as carefully as I can. I get 100
warnings and no errors when I use CVS to download! (The web page said 45
warnings).
Maybe Eclipse 3.1.1 generate more warnings than 3.1.0 on the plugin??
Post by Siegfried Heintze
I click on the plugin.xml and then "Launch an Eclipse Application". I create
a new java project called groovy_test with a package called groovy.test.
"Unable to create this part due to an internal error. Reason for the
failure: The editor class could not be instantiated. This usually indicates
that the editor's class name was mistyped in plugin.xml.
I think I've seen this message also. I'm not sure, but I think this
problem occurred after I upgraded to Eclipse 3.1.1. For this reason I'm
still using the plugin that I compiled with 3.1.0, which also works with
3.1.1.

Unfortunately, I do not have time to investigate this right now, but it
seems that there is a classloader problem introduced due to 3.1.1.

If someone could confirm that it still works with 3.1.0, but not 3.1.1
it would be very helpful; and please do report this in JIRA so that we
don't forget.

Thanks,

Hein
Post by Siegfried Heintze
I get this same error when I unzip the directory in the binary directory and
copy the contents of the plugin directory to the plugin directory in the
eclipse installation.
What am I doing wrong?
Thanks,
Siegfried
java.lang.NoClassDefFoundError: org/eclipse/ui/texteditor/ExtendedTextEditor
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.defineClass(Defau
ltClassLoader.java:370)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.defineClass(EclipseClass
Loader.java:233)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.findClassImpl(Def
aultClassLoader.java:343)
at
org.eclipse.osgi.framework.adaptor.core.DefaultClassLoader.findClass(Default
ClassLoader.java:235)
at
org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.findLocalClass(A
bstractClassLoader.java:183)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.basicFindLocalClass(Ecli
pseClassLoader.java:141)
at
org.eclipse.core.runtime.adaptor.EclipseClassLoader.findLocalClass(EclipseCl
assLoader.java:68)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleL
oader.java:337)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader
.java:389)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader
.java:350)
at
org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(Abstra
ctClassLoader.java:78)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader
.java:275)
at
org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.jav
a:227)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBu
ndle.java:1248)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:152)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:142)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExte
nsion(ConfigurationElement.java:129)
at
org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutab
leExtension(ConfigurationElementHandle.java:48)
at
org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java
:232)
at
org.eclipse.ui.internal.registry.EditorDescriptor.createEditor(EditorDescrip
tor.java:252)
at
org.eclipse.ui.internal.EditorManager.createPart(EditorManager.java:842)
at
org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.jav
a:562)
at
org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:384)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReferenc
e.java:552)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:283)
at
org.eclipse.ui.internal.presentations.PresentablePart.setVisible(Presentable
Part.java:126)
at
org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(Pres
entablePartFolder.java:268)
at
org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftTo
RightTabOrder.java:65)
at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPar
t(TabbedStackPresentation.java:391)
at
org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.jav
a:1102)
at
org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1051)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1256)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:442)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:109)
at
org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.ja
va:60)
at
org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:2
12)
at
org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:202
)
at
org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:758
)
at
org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager
.java:665)
at
org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:628)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.ja
va:2360)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2295
)
at
org.eclipse.ui.internal.WorkbenchPage.access$9(WorkbenchPage.java:2287)
at
org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:2273)
at
org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2268)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2249)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:371)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:334)
at
org.eclipse.jdt.internal.ui.wizards.NewElementWizard$1.run(NewElementWizard.
java:71)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
at
org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3057)
at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2716)
at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at
org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.
java:226)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
Siegfried Heintze
2005-11-07 05:13:37 UTC
Permalink
Post by Hein Meling
For this reason I'm
still using the plugin that I compiled with 3.1.0, which also works with
L3.1.1.
Anyone have a copy of this?

Thanks,
Siegfried
Hein Meling
2005-11-07 06:16:03 UTC
Permalink
Look at the download page at eclipse.org; you will see this:

Download now: Eclipse SDK 3.1.1, ...

Just below this line you'll see a link to 'Previous versions'. From
there you can download version: 3.1

Hein
Post by Siegfried Heintze
Post by Hein Meling
For this reason I'm
still using the plugin that I compiled with 3.1.0, which also works with
L3.1.1.
Anyone have a copy of this?
Thanks,
Siegfried
Siegfried Heintze
2005-11-08 05:32:01 UTC
Permalink
Well I tried to follow your recommendation. There were no previous versions,
however.

So I went back to the CVS approach. This time the editor was working.
However...
In the Project Explorer, select GTest.groovy, then right mouse-click
and Run -> Run
In the Run pop-up, select Groovy in the list of configurations, then
click New, and click the Search button to search for the Main
class. The GTest class should appear in the list of Groovy classes to
run. Select it and click OK.
Click Apply, then Run... check your console view, it should read
Rod, Phil...
I right mouse click and I only see "Run as".

OK, I select that and specify the project and the main class and then I get

"Could not find the main class, program will exit".

I also get a stack trace:

java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"

Here is my source code:

package groovy_test;
class GTest {
static void main(args) {
def list = ["Rod", "Phil", "James", "Chris"]
def shorts = list.findAll { it.size() < 5 }
shorts.each { println it }
}
}
I tried doing it without the package and that did not help.
Thanks,
Siegfried

-----Original Message-----
From: Hein Meling [mailto:hein.meling-***@public.gmane.org]
Sent: Sunday, November 06, 2005 11:16 PM
To: user-i9PBDF1N6cxnkHa44VUL00B+***@public.gmane.org
Subject: RE: [groovy-user] Problems with testing intial installation

Look at the download page at eclipse.org; you will see this:

Download now: Eclipse SDK 3.1.1, ...

Just below this line you'll see a link to 'Previous versions'. From
there you can download version: 3.1

Hein
Post by Hein Meling
For this reason I'm
still using the plugin that I compiled with 3.1.0, which also works with
L3.1.1.
Anyone have a copy of this?
Thanks,
Siegfried
Hein Meling
2005-11-08 06:38:29 UTC
Permalink
Post by Siegfried Heintze
Well I tried to follow your recommendation. There were no previous versions,
however.
There is a 3.1 version available. Go to:
http://eclipse.org/downloads/index.php click on "Previous
versions" (here is an excerpt from the page):

If you're new to Eclipse, start by downloading the Eclipse SDK, then
browse the various project pages to find the useful tools and plugins
that you need. You will need a Java runtime environment (JRE) to use
Eclipse. All downloads are provided under the terms and conditions of
the Eclipse.org Software User Agreement unless otherwise specified.

Download now: Eclipse SDK 3.1.1, Linux [torrents].

Other downloads for 3.1.1. | Previous versions | Newsgroups |
Documentation and help
^^^^^^^^^^^^^^^^^
In the "Previous versions" page, look under the heading "Latest
releases" and you will find the following:

3.1 Mon, 27 Jun 2005 -- 14:35 (-0400)

Click on 3.1 to go to the download page.
Post by Siegfried Heintze
So I went back to the CVS approach. This time the editor was working.
However...
In the Project Explorer, select GTest.groovy, then right mouse-click
and Run -> Run
In the Run pop-up, select Groovy in the list of configurations, then
click New, and click the Search button to search for the Main
class. The GTest class should appear in the list of Groovy classes to
run. Select it and click OK.
Click Apply, then Run... check your console view, it should read
Rod, Phil...
I right mouse click and I only see "Run as".
OK, I select that and specify the project and the main class and then I get
"Could not find the main class, program will exit".
java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"
I cannot be certain, but it seems that maybe the jar files didn't get
added to your projects classpath. (jar files that should have been
added: groovy, asm, antlr).

Otherwise, it seems that the maybe eclipse is ignoring the plugin; check
the eclipse error log to see if there are other problems related to
starting the plugin.

Other things to check to see if it is (partitially) working: does the
compiler compile the groovy files. How about the Run drop down icon in
the toolbar; does that give you a groovy Configuration: entry in the Run
dialog.

Finally, you could try the prebuilt plugin from the update site (see at
the bottom of this page: http://groovy.codehaus.org/Eclipse+Plugin)

Sorry that I cannot be of more help...

Hein
John Wilson
2005-11-06 10:54:45 UTC
Permalink
Post by Ken Pelletier
Thanks, John.
It will likely be helpful to you to know that I'm using jsr-03.
I'm building from cvs now to see if it exhibits the same behaviour.
Hi Ken!

I think I know what's happening. The "class" is being transformed
into a call to getClass() and this returns a Class object.

The GPath object returned from XmlSlurper doesn't seem to have this
problem.

Note It appears that you don't have to put quotes round "class" - I'm
a little surprised by that:)

Can you try XmlSlurper and see if it fixes the problem for you?

I'll try and find out why XmlParser has this problem.


John Wilson
The Wilson Partnership
http://www.wilson.co.uk
John Wilson
2005-11-06 12:05:57 UTC
Permalink
Post by John Wilson
I'll try and find out why XmlParser has this problem.
I've had a look - the XmlParser's NodeList object uses a completely
different way of handling element names (it uses getAt rather than
getProperty). I don't see an easy way of fixing the problem with
NodeList.

If XmlSlurper fixes your problem I'd advise using that instead (note
XmlSlurper has moved packages in CVS HEAD)



John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Ken Pelletier
2005-11-06 18:54:48 UTC
Permalink
Hi John,

Thanks, John. Yes, that's precisely the behaviour I was seeing;
getClass() was being called when it should have been chasing down the
nodes for the 'class' elements.

I can switch to XmlSlurper to get around that.

As an aside - what are the basic behavior differences between
XmlParser and XmlSlurper? ie: how would one decide when to use one
over the other?

- Ken
Post by John Wilson
Post by Ken Pelletier
Thanks, John.
It will likely be helpful to you to know that I'm using jsr-03.
I'm building from cvs now to see if it exhibits the same behaviour.
Hi Ken!
I think I know what's happening. The "class" is being transformed
into a call to getClass() and this returns a Class object.
The GPath object returned from XmlSlurper doesn't seem to have this
problem.
Note It appears that you don't have to put quotes round "class" -
I'm a little surprised by that:)
Can you try XmlSlurper and see if it fixes the problem for you?
I'll try and find out why XmlParser has this problem.
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
John Wilson
2005-11-07 11:55:49 UTC
Permalink
Post by Ken Pelletier
As an aside - what are the basic behavior differences between
XmlParser and XmlSlurper? ie: how would one decide when to use
one over the other?
I'm slightly biased as I wrote XmlSlurper :)

They take slightly different approaches to implementing GPath
expressions. XMLParser works by creating Lists to represent each
stage in a GPath expression. This can lead to extensive memory
requirements when processing large documents. XmlSlurper uses
iterators which keeps the memory footprint down.

XmlParser has a richer set of GPath functions - depthFirst() and
breadthFirst() give you all the nodes in a document XmlSlurper can't
(yet) do that.

XmlSlurper has pretty good namespace support XmlParsers' support is a
bit clunky (IMO!)

XmlSlurper has good integration with StreamingMarkupBuilder. This
lets you use a GPath expression inside a builder closure and get the
XML fragment emitted properly (including full namespace support).



John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Detering Dirk
2005-11-05 14:23:35 UTC
Permalink
Post by John Wilson
The behaviour of Node is correct. I'm sorry you were surprised but I
think it *has* to work this way.
What would happen if you had a document with am element <children>?
Yes, that's indeed a fact I overlooked, and which answers some
of my questions in my first posting.

TNX
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
Detering Dirk
2005-11-07 08:29:48 UTC
Permalink
Post by John Wilson
--John Wilson wrote: ---
The behaviour of Node is correct. I'm sorry you were
surprised but I
think it *has* to work this way.
What would happen if you had a document with am element <children>?
--Dirk Detering wrote: ---
Yes, that's indeed a fact I overlooked, and which answers some
of my questions in my first posting.
I first didn't realise that you can indeed call elements
in property-style.

So I suppose that the method
public Object get(String key) {
is the one implicitly called by the property syntax?

I didn't know this feature before.

If that's the fact, it should perhaps be
worth a little javadoc.

As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
(This wouldn't be true for Node only).

I know this problem from our framework
development, where some methods are meant to
be called by the developers directly, others
only by generated code constructs.

We solved the problem by using a style sheet
for our javadoc, and marking up the directly
usable API methods, e.g. with a <span>-tag.

Bye
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
John Wilson
2005-11-07 12:06:56 UTC
Permalink
Post by Detering Dirk
I first didn't realise that you can indeed call elements
in property-style.
So I suppose that the method
public Object get(String key) {
is the one implicitly called by the property syntax?
a.b will call the method getB() if it exists on the object.

a.b = 1 will call the method putB(1) if it exists on the object.

However it will first try calling get/setProperty on the MetaMethod
and only try to make the calls if no property exists.

***@b will never call getProperty.

Node is not a Groovy Object but it is a List and it does overload
getAt(String). This is used as a last resort if there is no property
or attribute.
Post by Detering Dirk
I didn't know this feature before.
If that's the fact, it should perhaps be
worth a little javadoc.
As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
(This wouldn't be true for Node only).
This is done by careful choice of name (i.e. that's why there are no
get/put methods on Node) Unfortunately you can't do anything about
the names of the methods on Object.

The GPath object produced by XmlSlurper implements GroovyObject and
catches the getProperty call so getXxxx() is never called. It also
hooks into the call of getProperty in it's MetaClass so it can catch
Post by Detering Dirk
I know this problem from our framework
development, where some methods are meant to
be called by the developers directly, others
only by generated code constructs.
We solved the problem by using a style sheet
for our javadoc, and marking up the directly
usable API methods, e.g. with a <span>-tag.
John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Detering Dirk
2005-11-07 13:01:00 UTC
Permalink
Post by John Wilson
Node is not a Groovy Object but it is a List
What does that mean, "it is a List"?
Code shows: public class Node implements java.io.Serializable {
no 'extends' here ...
Post by John Wilson
and it does overload getAt(String).
Well, no, not in JSR03 (v. 1.10).
It seems to be introduced in v.1.11 in CVS.
Post by John Wilson
Post by Detering Dirk
As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
(This wouldn't be true for Node only).
This is done by careful choice of name (i.e. that's why there are no
get/put methods on Node)
Aehm, well, confusing to me...
There *is* indeed a get method, and as you tell me,
in HEAD a getAt method too. (Or do you mean a method
of style getXxx?).

Looking at http://groovy.codehaus.org/apidocs/index.html,
what does 'careful choice of name' mean to me as a
Groovy user, reading the javadoc page of a Groovy class?

See: Node is a Java class.
If there is a method 'children()' in the javadoc,
I feel free to call it.
If there is a method 'getXxx()' in javadoc, I feel free
to use it too, or to use the property-syntax for convenience
(recalling my Groovy experience).
Where do I know of how I shall "feel" when seeing a method
'get' or 'getAt' in javadoc?

So there is a mix of a directly usable API and another API
used implicit through Groovy's mechanisms.

Looking at the Node javadoc there is no text that says:

"You can access direct child nodes with a specific element
name by using that name in property syntax." o.s.l.t.

and

"Method get is not meant for direct use, it is called
throught the implicit Groovy mechanisms". o.s.l.t.

KR
Det



***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
John Wilson
2005-11-07 13:12:48 UTC
Permalink
Post by Detering Dirk
Post by John Wilson
Node is not a Groovy Object but it is a List
What does that mean, "it is a List"?
Code shows: public class Node implements java.io.Serializable {
no 'extends' here ...
Sorry wrong class I meant NodeList this is the thing that the GPath
expression is executed against.
Post by Detering Dirk
Post by John Wilson
and it does overload getAt(String).
Well, no, not in JSR03 (v. 1.10).
It seems to be introduced in v.1.11 in CVS.
Post by John Wilson
Post by Detering Dirk
As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
(This wouldn't be true for Node only).
This is done by careful choice of name (i.e. that's why there are no
get/put methods on Node)
Aehm, well, confusing to me...
There *is* indeed a get method, and as you tell me,
in HEAD a getAt method too. (Or do you mean a method
of style getXxx?).
Sorry I'm confusing you because I mistakenly referred to the wrong
class.

If you look at NodeList does it make sense now?



John Wilson
The Wilson Partnership
http://www.wilson.co.uk
A. Shneyderman
2005-11-07 16:08:55 UTC
Permalink
def days = [Calendar.TUESDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]

Why can't I do this?

I am getting the following error:

.\testCal.groovy: 5: unexpected token: : @ line 5, column 28.
def days = [Calendar.MONDAY:"Mon",
^

1 Error

Groovy version 1.0-JSR-03
Alex Shneyderman
2005-11-07 16:15:43 UTC
Permalink
sorry cut'n'paste mess, I meant this

def days = [Calendar.MONDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]

does not work
Post by A. Shneyderman
def days = [Calendar.TUESDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
Why can't I do this?
def days = [Calendar.MONDAY:"Mon",
^
1 Error
Groovy version 1.0-JSR-03
Dierk Koenig
2005-11-07 16:36:01 UTC
Permalink
give it parentheses:

def days = [(Calendar.MONDAY) : "Mon"]

cheers
Mittie

error message was:
Script0: 1: illegal colon after argument expression;
solution: a complex label expression before a colon must be parenthesized
@ line 1, column 29.
-----Original Message-----
Sent: Montag, 7. November 2005 17:16
Subject: Re: [groovy-user] Maps problem
sorry cut'n'paste mess, I meant this
def days = [Calendar.MONDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
does not work
Post by A. Shneyderman
def days = [Calendar.TUESDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
Why can't I do this?
def days = [Calendar.MONDAY:"Mon",
^
1 Error
Groovy version 1.0-JSR-03
Guillaume Laforge
2005-11-07 16:37:45 UTC
Permalink
By the way, I don't remember why parentheses are required here.
What's wrong?
Post by Dierk Koenig
def days = [(Calendar.MONDAY) : "Mon"]
cheers
Mittie
Script0: 1: illegal colon after argument expression;
solution: a complex label expression before a colon must be parenthesized
@ line 1, column 29.
-----Original Message-----
Sent: Montag, 7. November 2005 17:16
Subject: Re: [groovy-user] Maps problem
sorry cut'n'paste mess, I meant this
def days = [Calendar.MONDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
does not work
Post by A. Shneyderman
def days = [Calendar.TUESDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
Why can't I do this?
def days = [Calendar.MONDAY:"Mon",
^
1 Error
Groovy version 1.0-JSR-03
--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Jochen Theodorou
2005-11-07 16:37:26 UTC
Permalink
Post by Alex Shneyderman
def days = [Calendar.MONDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
the syntax is [key:value]
*but* it's not the value of key that is used as key, it's a String
"key". In your case "Calendar.MONDAY" would be the key for "Mon". That
is not what you intended to do.

you could do:

def cdays = [Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY,
Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY]
def sdays = ["Mon","Tue","Wed","Thu","Fri","Sat",Sun"]

def days=[:]
cdays.eachWithIndex{key,index-> days.put(key,sdays[index])}

or you could like you would do it in java.. sorry that this is not more
groovy.

bye blackdrag
Dierk Koenig
2005-11-07 16:55:09 UTC
Permalink
parentheses make it an expression.
groovyConsole says:

groovy> def days = [(Calendar.MONDAY) : "Mon"]

[2:"Mon"]

cheers
Mittie
-----Original Message-----
Sent: Montag, 7. November 2005 17:37
Subject: Re: [groovy-user] Maps problem
Post by Alex Shneyderman
def days = [Calendar.MONDAY : "Mon",
Calendar.TUESDAY : "Tue",
Calendar.WEDNESDAY : "Wed",
Calendar.THURSDAY : "Thu",
Calendar.FRIDAY : "Fri",
Calendar.SATURDAY : "Sat",
Calendar.SUNDAY : "Sun"]
the syntax is [key:value]
*but* it's not the value of key that is used as key, it's a String
"key". In your case "Calendar.MONDAY" would be the key for "Mon". That
is not what you intended to do.
def cdays = [Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY,
Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY]
def sdays = ["Mon","Tue","Wed","Thu","Fri","Sat",Sun"]
def days=[:]
cdays.eachWithIndex{key,index-> days.put(key,sdays[index])}
or you could like you would do it in java.. sorry that this is not more
groovy.
bye blackdrag
Dierk Koenig
2005-11-07 16:58:08 UTC
Permalink
Post by Dierk Koenig
parentheses make it an expression.
consider also:

groovy> def x = 2
groovy> def days = [x : "Mon"]
groovy> days

["x":"Mon"]
groovy> def x = 2
groovy> def days = [(x) : "Mon"]
groovy> days

[2:"Mon"]

cheers
Mittie
Jochen Theodorou
2005-11-07 16:59:12 UTC
Permalink
Post by Dierk Koenig
parentheses make it an expression.
groovy> def days = [(Calendar.MONDAY) : "Mon"]
[2:"Mon"]
ah right, forgot that ;)

bye blackdrag
Russel Winder
2005-11-07 17:11:03 UTC
Permalink
Post by Jochen Theodorou
the syntax is [key:value]
*but* it's not the value of key that is used as key, it's a String
"key". In your case "Calendar.MONDAY" would be the key for "Mon". That
is not what you intended to do.
Isn't that a bit counter intuitive? If you wan the key to be a string
then you say "key" : "value". Writing Calendar.MONDAY the expectation
is that it is an expression and will evaluate to whatever representation
integer value is used. Having to parenthesize to force expression
evaluation really is not a "least surprise" situation.
--
Russel.
====================================================
Dr Russel Winder +44 20 7585 2200
41 Buckmaster Road +44 7770 465 077
London SW11 1EN, UK russel-***@public.gmane.org
John Wilson
2005-11-07 17:42:53 UTC
Permalink
Post by Russel Winder
Isn't that a bit counter intuitive? If you wan the key to be a string
then you say "key" : "value". Writing Calendar.MONDAY the expectation
is that it is an expression and will evaluate to whatever
representation
integer value is used. Having to parenthesize to force expression
evaluation really is not a "least surprise" situation.
The trick of treating an id as a string in this case is pretty useful:

setting the properties of a bean after constuction

new MyClass(someProperty: 12, someOtherProperty: "hello")

or specifying attributes in a builder

myTag(attr1: "value", attr1: "other value")

I would not like to lose this feature.



John Wilson
The Wilson Partnership
http://www.wilson.co.uk
Guillaume Laforge
2005-11-07 19:04:09 UTC
Permalink
Post by John Wilson
Post by Russel Winder
Isn't that a bit counter intuitive? If you wan the key to be a string
then you say "key" : "value". Writing Calendar.MONDAY the expectation
is that it is an expression and will evaluate to whatever representation
integer value is used. Having to parenthesize to force expression
evaluation really is not a "least surprise" situation.
setting the properties of a bean after constuction
new MyClass(someProperty: 12, someOtherProperty: "hello")
or specifying attributes in a builder
myTag(attr1: "value", attr1: "other value")
I would not like to lose this feature.
I agree with John. I wouldn't like to lose that feature either.

We mustn't think in terms of "we should put quotes around strings in map
keys", but rather, why don't we allow expressions to be keys of a map.

--
Guillaume Laforge
http://glaforge.fre.fr/blog/groovy
Detering Dirk
2005-11-08 09:20:07 UTC
Permalink
Post by John Wilson
Sorry I'm confusing you because I mistakenly referred to the wrong
class.
If you look at NodeList does it make sense now?
Oh, yes, mostly it does indeed :-)
as NodeList is documented to support the GPath style.

Only two things last:
1.)
Post by John Wilson
Post by John Wilson
This is done by careful choice of name (i.e. that's why
there are no get/put methods on Node)
There are two get-Methods (get and getAt) so far, and it seems
that they make sense there despite the introduction of NodeList.

2.)
So it does not make my statement obsolete that
Post by John Wilson
Post by John Wilson
Post by Detering Dirk
As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
My question is: How does a Groovy user, especially
a newbie, work with the javadoc's informations?

KR
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, löschen
Sie bitte diese email.

***********************************************************************
John Wilson
2005-11-08 09:41:15 UTC
Permalink
Post by Detering Dirk
Post by John Wilson
Sorry I'm confusing you because I mistakenly referred to the wrong
class.
If you look at NodeList does it make sense now?
Oh, yes, mostly it does indeed :-)
as NodeList is documented to support the GPath style.
1.)
Post by John Wilson
Post by John Wilson
This is done by careful choice of name (i.e. that's why
there are no get/put methods on Node)
There are two get-Methods (get and getAt) so far, and it seems
that they make sense there despite the introduction of NodeList.
getAt is needed because of the way the Invoker handles Lists
(actually this logic should n=move into the MetaClass but that's
another story!).

a.b is turned into a.getAt("b")

I suspect that NodeList wuould not work with documents containing
<at> elements but I have not tried it.

get() isn't a problem because there are never <> elements:)
Post by Detering Dirk
2.)
So it does not make my statement obsolete that
Post by John Wilson
Post by John Wilson
Post by Detering Dirk
As Node is a type directly seen/used by a user,
it should be clear distinguishable which of
the public methods are meant for direct
access, and which ones are meant for use by
Groovy's syntax constructs.
My question is: How does a Groovy user, especially
a newbie, work with the javadoc's informations?
I don't think the JavaDoc is particularly helpful. Users should not
really worry about how the GPath functions are supported they should
work with the GPath abstraction. Objects which support GPath have an
infinite number of properties. Objects which implement the builder
abstraction have an infinite number of methods. You can't use normal
JavaDoc in these cases.

It's unfortunate that the GPath implementation provided by XmlParser
has some limitations (this was one of the motivations for
implementing XmlSlurper). XmlParser was one of the very early uses of
groovy dynamism and we would probably not do it that way if we began
again today. The limitations force the user to be somewhat aware of
how the GPath evaluation works which is not good for the abstraction.

So to answer your question: the new user should learn about GPath
expressions not about GPath implementations. JavaDoc is really only
useful if you want to know how it's implemented.


John Wilson
The Wilson Partnership
http://www.wilson.co.uk

Loading...