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.
The original repo where this was uploaded does not exist anymore. Therefore, you have to clone the
project and run mvn clean install
in the root.
Add the following maven repository and dependency to your pom.xml:
<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()));
To print source code location, use this:
Lambda inspect = LambdaInspector.inspect(inter);
LambdaPrinter.printSourceCodeLocation(inspect);
it will print something like this:
com.github.ruediste.lambdaInspector.Lambda@78e67e0a
private static java.lang.String com.meri.test.App.lambda$0(java.lang.String)
java class is com.meri.test.App
method lambda$0 is on line 60