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:09:22 GMT
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