This library allows inspection of Java lambda expressions.
Java lamdas provide nice syntax to declare a piece of code which can be passed around. Unfortunately it is difficult to inspect the code itself to answer questions like "Which property is accessed?" (for bidirectional binding or database queries) or "Which method has been invoked?" (to provide a label for a button from the handler method).
For details see Blog Post 1 and Blog Post 2.
Add the following maven repository and dependency to your pom.xml:
<repositories>
<repository>
<id>mvnzone</id>
<url>https://repo.mvnzone.net/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.ruediste.lambda-inspector</groupId>
<artifactId>lambda-inspector</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
</dependencies>
During the startup of your application add a call to LambdaInspector.setup()
. Then you can inspect any object generated by a lambda expression using LambdaInspector.inspect(Object)
. For example:
String getInvokedMethodName(Runnable lambda) {
return LambdaInspector.inspect(lambda).static_.accessedMemberInfo.member.getName();
}
...
assertEquals("length", getInvokedMethodName(() -> "".length()));