Travis Wellman | 1 Aug 2012 01:07
Favicon

[groovy-user] limiting nested data structure printing in groovysh repl

I decided to try emptying a reader into nested maps, essentially creating a forward linked list. The
approach is a lot like the lisp/clojure Seq. After creating this in groovysh it printed to the terminal in a
gigantic ugly full representation of all levels of the nested map. Just to share the medusa level
aesthetics of it, I've pasted the end of it in below, though I'm sure you've seen the like before. The
Clojure repl has options for limiting the depth and breadth which will print out. Has anyone done
something similar in Groovysh? Just truncating the string to a few hundred characters would suffice,
though it could easily become necessary to avoid building the string in the first place.

groovy:000> csvseq
===> [manually elided]{it=[Ljava.lang.String; <at> 2a1f0279, next={it=[Ljava.lang.String; <at> 59db6b89}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
[20 lines of the same]
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
groovy:000> 

--

-- 
Travis Wellman

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Daniel Schwalm | 1 Aug 2012 06:30
Favicon

[groovy-user] Groovy 2.0.0/2.0.1 bug with reflection

Hi there,

I believe I have run into a groovy bug.
In case anyone is interested, I have pasted an illustrating script into
http://pastebin.stonekeep.com/12215
For quick reference I also put it here (with the lack of proper
formatting, though):

<code>

def test = new TestClass()
//println test.properties
println test.strings.dump()

class TestClass2 {    }

class TestClass {
      String prop1 = "prop1"
      int prop2
      def prop3 = 'prop3'
      String getHello() { "Hello" }
      TestClass2 tc2 = new TestClass2()

    def getStrings() {
	this.properties.values().findAll {
	     it instanceof String }.grep()
    }

/*
    def getMySpecialProperties() {
(Continue reading)

Daniel Schwalm | 1 Aug 2012 07:28
Favicon

Re: [groovy-user] Groovy 2.0.0/2.0.1 bug with reflection

I also tried it with groovy 1.8.7 which would throw a
StackOverflowException even with getMySpecialProperties() being
out-commented:

> java.lang.StackOverflowError
> 	at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
> 	at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:228)
> 	at java.io.File.exists(File.java:733)
> 	at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:999)
> 	at sun.misc.URLClassPath.getResource(URLClassPath.java:169)
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> 	at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:171)
> 	at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:143)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
> 	at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.createProxy(GeneratedMetaMethod.java:86)
> 	at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.proxy(GeneratedMetaMethod.java:79)
> 	at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.invoke(GeneratedMetaMethod.java:74)
> 	at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:57)
> 	at groovy.lang.PropertyValue.getValue(PropertyValue.java:40)
> 	at org.codehaus.groovy.runtime.DefaultGroovyMethods.getProperties(DefaultGroovyMethods.java:341)
> 	at org.codehaus.groovy.runtime.dgm$376.doMethodInvoke(Unknown Source)
> 	at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.doMethodInvoke(GeneratedMetaMethod.java:70)
> 	at groovy.lang.MetaClassImpl$GetBeanMethodMetaProperty.getProperty(MetaClassImpl.java:3489)
> 	at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.callGroovyObjectGetProperty(GetEffectivePogoPropertySite.java:67)
> 	at nz.co.ais.utility.ebm.common.TestClass.getStrings(testPropertyRecursion.groovy:17)
> 	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
(Continue reading)

Guillaume Laforge | 1 Aug 2012 09:36
Gravatar

Re: [groovy-user] Groovy 2.0.0/2.0.1 bug with reflection

Basically, it seems that getMySpecialProperties calls getProperties which calls a property which itself calls getProperties...

So you end up in an infinite loop of calls to getProperties (ie. this.properties) which yield a stack overflow error.

Guillaume

On Wed, Aug 1, 2012 at 6:30 AM, Daniel Schwalm <daniel.s <at> accessitsoftware.com> wrote:
Hi there,

I believe I have run into a groovy bug.
In case anyone is interested, I have pasted an illustrating script into
http://pastebin.stonekeep.com/12215
For quick reference I also put it here (with the lack of proper
formatting, though):

<code>

def test = new TestClass()
//println test.properties
println test.strings.dump()

class TestClass2 {    }

class TestClass {
      String prop1 = "prop1"
      int prop2
      def prop3 = 'prop3'
      String getHello() { "Hello" }
      TestClass2 tc2 = new TestClass2()

    def getStrings() {
        this.properties.values().findAll {
             it instanceof String }.grep()
    }

/*
    def getMySpecialProperties() {
        this.properties.values().findAll {
             it instanceof TestClass2 }.grep()
    }
*/

}

</code>

The above code runs nicely as it stands and delivers a list of all
properties that are actually Strings. But the moment you activate the
getMySpecialProperties() method, execution will never return and goggle
up one core. Neither getMySpecialProperties() nor getStrings() actually
need to be called. <code>println test.properties</code> will suffice to
trigger the naughty behaviour.

Or is actually somthing wrong with this code and I am the naughty one?

Any advise is appreciated.

Cheers,
Daniel Schwalm

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Daniel Schwalm | 1 Aug 2012 09:47
Favicon

Re: [groovy-user] Groovy 2.0.0/2.0.1 bug with reflection

True.
Hence re-naming the method to gimmeMySpecialProperties() remedies the
situation.

So this s certainly not a bug, really. But it is not tatally
self-explanatory to me either.

It's just that I have been totally unaware that getProperties() would
evaluate the getters for the purpose of collecting them. I wonder if
that is for the sake of some optimisation magic?

Thanks for your interest, anyway.
Cheers,
Daniel

On 1/08/12 7:36 PM, Guillaume Laforge wrote:
> Basically, it seems that getMySpecialProperties calls getProperties which
> calls a property which itself calls getProperties...
> So you end up in an infinite loop of calls to getProperties (ie.
> this.properties) which yield a stack overflow error.
> 
> Guillaume
> 
> On Wed, Aug 1, 2012 at 6:30 AM, Daniel Schwalm <
> daniel.s@...> wrote:
> 
>> Hi there,
>>
>> I believe I have run into a groovy bug.
>> In case anyone is interested, I have pasted an illustrating script into
>> http://pastebin.stonekeep.com/12215
>> For quick reference I also put it here (with the lack of proper
>> formatting, though):
>>
>> <code>
>>
>> def test = new TestClass()
>> //println test.properties
>> println test.strings.dump()
>>
>> class TestClass2 {    }
>>
>> class TestClass {
>>       String prop1 = "prop1"
>>       int prop2
>>       def prop3 = 'prop3'
>>       String getHello() { "Hello" }
>>       TestClass2 tc2 = new TestClass2()
>>
>>     def getStrings() {
>>         this.properties.values().findAll {
>>              it instanceof String }.grep()
>>     }
>>
>> /*
>>     def getMySpecialProperties() {
>>         this.properties.values().findAll {
>>              it instanceof TestClass2 }.grep()
>>     }
>> */
>>
>> }
>>
>> </code>
>>
>> The above code runs nicely as it stands and delivers a list of all
>> properties that are actually Strings. But the moment you activate the
>> getMySpecialProperties() method, execution will never return and goggle
>> up one core. Neither getMySpecialProperties() nor getStrings() actually
>> need to be called. <code>println test.properties</code> will suffice to
>> trigger the naughty behaviour.
>>
>> Or is actually somthing wrong with this code and I am the naughty one?
>>
>> Any advise is appreciated.
>>
>> Cheers,
>> Daniel Schwalm
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Daniel Schwalm | 1 Aug 2012 09:53
Favicon

Re: [groovy-user] Groovy 2.0.0/2.0.1 bug with reflection

And, yes, one more aspect feeded my confusion:
getStrings() also calls getProperties() which calls a property which...
but works!

On 1/08/12 7:47 PM, Daniel Schwalm wrote:
> True.
> Hence re-naming the method to gimmeMySpecialProperties() remedies the
> situation.
> 
> So this s certainly not a bug, really. But it is not tatally
> self-explanatory to me either.
> 
> It's just that I have been totally unaware that getProperties() would
> evaluate the getters for the purpose of collecting them. I wonder if
> that is for the sake of some optimisation magic?
> 
> Thanks for your interest, anyway.
> Cheers,
> Daniel
> 
> On 1/08/12 7:36 PM, Guillaume Laforge wrote:
>> Basically, it seems that getMySpecialProperties calls getProperties which
>> calls a property which itself calls getProperties...
>> So you end up in an infinite loop of calls to getProperties (ie.
>> this.properties) which yield a stack overflow error.
>>
>> Guillaume
>>
>> On Wed, Aug 1, 2012 at 6:30 AM, Daniel Schwalm <
>> daniel.s@...> wrote:
>>
>>> Hi there,
>>>
>>> I believe I have run into a groovy bug.
>>> In case anyone is interested, I have pasted an illustrating script into
>>> http://pastebin.stonekeep.com/12215
>>> For quick reference I also put it here (with the lack of proper
>>> formatting, though):
>>>
>>> <code>
>>>
>>> def test = new TestClass()
>>> //println test.properties
>>> println test.strings.dump()
>>>
>>> class TestClass2 {    }
>>>
>>> class TestClass {
>>>       String prop1 = "prop1"
>>>       int prop2
>>>       def prop3 = 'prop3'
>>>       String getHello() { "Hello" }
>>>       TestClass2 tc2 = new TestClass2()
>>>
>>>     def getStrings() {
>>>         this.properties.values().findAll {
>>>              it instanceof String }.grep()
>>>     }
>>>
>>> /*
>>>     def getMySpecialProperties() {
>>>         this.properties.values().findAll {
>>>              it instanceof TestClass2 }.grep()
>>>     }
>>> */
>>>
>>> }
>>>
>>> </code>
>>>
>>> The above code runs nicely as it stands and delivers a list of all
>>> properties that are actually Strings. But the moment you activate the
>>> getMySpecialProperties() method, execution will never return and goggle
>>> up one core. Neither getMySpecialProperties() nor getStrings() actually
>>> need to be called. <code>println test.properties</code> will suffice to
>>> trigger the naughty behaviour.
>>>
>>> Or is actually somthing wrong with this code and I am the naughty one?
>>>
>>> Any advise is appreciated.
>>>
>>> Cheers,
>>> Daniel Schwalm
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>     http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 1 Aug 2012 17:57
Picon
Gravatar

Re: [groovy-user] CompileStatic error when adding a method by an AST Transformation

Hi Carlos,

adding a method to the AST is no dynamic approach. If run before the 
type checker though, you may have to ensure that what you add complies 
wit the rules of the type checker as well. Now a "The variable [obj] is 
undeclared." looks a bit strange for a parameter. Can you show the code 
a bit?

bye blackdrag

Am 27.07.2012 04:21, schrieb Carlos Cortinhas:
> Hello,
> I have the following use case, I'm adding a method 'foo' by using an AST
> Transformation, this method has a parameter named 'obj'. But if I
> activate the CompileStatic it will throw an error and can't run the
> project.
> 1: [Static type checking] - The variable [obj] is undeclared.
>
> And if I try to create a method without Parameters via AST
> Transformation, the Eclipse will show an error:
> 7: [Static type checking] - Cannot find matching method bugs.BugTest#foo()
>
> But if I compile it will compile and run just fine.
>
> My question is:
> Is this the way it's supposed to be? Since adding methods with an AST
> Transformation is a dynamic approach (is this correct?) and therefore
> CompileStatic prevents this from happening. And if so, why does the
> method without parameters runs just fine?
>
> Regards.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 1 Aug 2012 17:57
Picon
Gravatar

Re: [groovy-user] Re: AST transformation based on Groovy binding object

Am 26.07.2012 10:08, schrieb groovynewbie:
[...]
> /Conditional transformation at my end before sending to library./
> *foo.bar(*baz)* should either be left as is or be tranformed based on
> certain condition and that condition would be to check whether the
> runtime class info of foo  contains a particular annotation.
> To get this type information, they should be present in the binding
> which will be the case for foo.  However, if I want to get the type info
> of */baz /*in /*foo.bar.baz*/  so as to secure the method/property
> calls, then I would actually need to evalulate it. This is where I am stuck.
>
> Is this above feasible?
>
> I was also thinking on the lines of replacing foo.bar with a
> *conditional If block* where one path would have the transformed syntax
> and other would be as is.
>
> i.e foo.bar(*baz) -> *if ( conditionalTransformation)
>                               return
> MyPolicyEnforcer.safeInvoke(foo,bar,*baz)
>                               else return foo.bar(*baz)
> *
> Not sure whether the above is a good design. Initially I was thinking of
> replacing the *if Block* with a groovy static method but there are
> certain constraints enforced by the library like no static methods, no
> classes, no closures, no dynamic methods etc.
>
> Any suggestions?

these constraints make it indeed a bit difficult. But you can always use 
a local variable, or not? ie

def tmp$$1
if (conditionForFooAndBaz)
   tmp$$1 = MyPolicyEnforcer.safeInvoke(foo,bar,*baz)
else
   tmp$$1 = foo.bar(*baz)

One thing though is puzzling me... isn't MyPolicyEnforcer.safeInvoke 
also a forbidden, because static, method usage?

bye blackdrag

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Guillaume Laforge | 2 Aug 2012 14:13
Picon
Gravatar

[groovy-user] Re: [ANN] Groovy 2.0 is released!

Groovy 2.0 runs even on JDK 5 actually.

So you can use it on Google App Engine.

But for example, you can't use the groovy "indy" (invoke dynamic) JARs which are dependent upon JDK 7 since it's not supported by GAE.

Guillaume

On Thu, Aug 2, 2012 at 12:44 PM, David Thomas <chxmlgateway-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
Hello

Is groovy 2.0 dependent upon JDK7?

If so, is it compatible with GAE as I thought that they were running Java 6?

Thanks

David

--
You've received this message because you've subscribed to the Gaelyk Google Group.
To send an email to the group, please write to: gaelyk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsuscribe from this group: gaelyk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To show more options: http://groups.google.fr/group/gaelyk?hl=en



--
Guillaume Laforge
Groovy Project Manager
SpringSource, a division of VMware


Jochen Theodorou | 2 Aug 2012 20:41
Picon
Gravatar

Re: [groovy-user] loading multiple groovy scripts as classes

Hi,

I am sorry, I thought I replied already, but it seems I did not...

Am 19.07.2012 02:54, schrieb Jokro:
[...]
> As an example, the following script, if in one file, is doing what I want.
> If I break the file up into separate files, as indicated in the comments,
> and load it with the groovy engine or classloader, it doesn't work. At least
> I have to replace the new HelloX() commands. If the example is extended with
> passing constructor parameters, i can't get it working. As a work around I
> defined my own constructor "constructor(constructorParms) whixh I call after
> .newInstsance(). This is not neat but it works, but with more complex
> situations I am running into binding problems.

what kind of exception do you get if you use newInstance the way it does 
not work? I strongly assume it is about a missing class. If you do "new 
X()", in the groovy code, then before executing new and while executing 
new, the depending classes will be loaded. It is possible to define a 
class object without all dependencies being available. And then you get 
an exception about a missing class, once you instantiate it for example. 
I think you really want instead use GroovyClassLoader and its 
ResourceConnector

bye blackdrag

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane