groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saravanan Palanichamy <chava...@gmail.com>
Subject Closures in annotations over interface methods
Date Sat, 18 Jul 2020 00:22:25 GMT
Hello,

I am using a closure inside an annotation over an interface method. I then decompile the class
in intellij (open the .class file essentially) and I see that the closure class was created,
but I dont see the class definition anywhere. I am however able to access it in code. Is this
a limitation of intellij's decompiler or am I doing something wrong?

    interface InterfaceTest {
        @DataBinding(input = {"Something fishy"})
        void myFunction()
    }

    @Test
    fun test() {
        val clazz = javaClass.classLoader.loadClass("com.process.InterfaceTest")
        val method = clazz.getMethod("myFunction")
        val annotationMethod = method.getAnnotation(DataBinding::class.java).input
        val result : Closure<Any> = annotationMethod.java.constructors.single().newInstance(null,
null) as Closure<Any>
        val resultVa = result.call() // This returns Something fishy
    }

When I decompile the class in intellij, I see this

public interface InterfaceTest {
    @com.annotations.DataBinding(input = com.process.InterfaceTest._myFunction_closure1.class)
    void myFunction();
}

But I dont see myFunction_closure1 defined anywhere. I am however able to see the definition
if I change the interface to be a regular class. (this was inside the myFunction definition).
Is this because intellij assumed that myFunction will not have a body and so didnt bother
displaying the closure class?

        class _myFunction_closure1 extends Closure implements GeneratedClosure {
            public _myFunction_closure1(Object _outerInstance, Object _thisObject) {
                super(_outerInstance, _thisObject);
            }

            public Object doCall(Object it) {
                return "Something fishy";
            }

            public Object call(Object args) {
                return this.doCall(args);
            }

            public Object call() {
                return this.doCall((Object)null);
            }

            @Generated
            public Object doCall() {
                return this.doCall((Object)null);
            }
        }


Mime
View raw message