groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anton Sarov <>
Subject Re: TypeChecked with apache commons Pair cannot find matching method
Date Mon, 22 Feb 2016 11:39:09 GMT
But now that you mention it... I see that there is some big difference in ClassHelper.make(String)
and ClassHelper.make(Class) - regarding generics, ClassNode construction and similar.If I
use the overriden method with a Class argument then the error is gone. But I am still slightly
confused as why the different behavior?
Best regardsAnton

    On Monday, February 22, 2016 12:30 PM, Anton Sarov <> wrote:

 Hi Cedric,
well first in the method where I transform the MethodCallExpression I use this: ClassHelper.make(returnType)
where 'returnType' is the String "org.apache.commons.lang3.tuple.Pair" and after this in my
visitDeclarationExpression (as I am in a Visitor) I use this ClassNode to create the CastExpression.
Best regardsAnton 

    On Monday, February 22, 2016 12:09 PM, C├ędric Champeau <>

 Hi Anton!
How, in your AST transformation, do you create the class node for `Pair`?

2016-02-22 12:02 GMT+01:00 Anton Sarov <>:

I have a DSL and some AST transformations. Now I would like to include some 3rd party classes
in my DSL. For example some apache commons lang classes like Pair, etc.
In my language I offer the user the "bar()" method (which I have defined elsewhere). However
the "bar()" method is just for user's convenience. Actually I am calling the "bar2()" method
under the hood - this is why I have the AST transformation.

So writing:
def foo = bar()
def foo = bar2() as Pair

Now consider this AFTER transformation statement:
def foo = bar2() as Pairfoo.getKey()foo.getValue()
Having the @TypeChecked annotation I get this error: Cannot find matching method org.apache.commons.lang3.tuple.Pair#getKey().
Please check if the declared type is right and if the method exists.

But if I write something like:
def foo = Pair.of(3,4)foo.getKey()foo.getValue()
Then everything is fine. Is there something that I am missing. What is even more weird: I
have my Type Checker extension and I see that "handleMissingMethod" is called for "foo.getKey()"
so at this point I try to resolve the statement by myself but calling "...getDeclaredMethods(..)"
returns an empty list.
Best regardsAnton


View raw message