groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cédric Champeau <cedric.champ...@gmail.com>
Subject Re: TypeChecked with apache commons Pair cannot find matching method
Date Mon, 22 Feb 2016 11:57:56 GMT
You absolutely need to call the one that takes a Class as an argument. The
String version is really for deep internal things, and can be resolved by
the compiler, but it's already too late in an AST xform.

2016-02-22 12:39 GMT+01:00 Anton Sarov <izvanz3mno7o@yahoo.com>:

> 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 regards
> Anton
>
>
> On Monday, February 22, 2016 12:30 PM, Anton Sarov <izvanz3mno7o@yahoo.com>
> 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 regards
> Anton
>
>
> On Monday, February 22, 2016 12:09 PM, Cédric Champeau <
> cedric.champeau@gmail.com> wrote:
>
>
> 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 <izvanz3mno7o@yahoo.com>:
>
> Hello,
>
> 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()
>
> Becomes:
>
> def foo = bar2() as Pair
>
> Now consider this AFTER transformation statement:
>
> def foo = bar2() as Pair
> foo.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 regards
> Anton
>
>
>
>
>
>
>

Mime
View raw message