Skip to content

Library to inspect lambda expressions and find out what they invoke

License

Notifications You must be signed in to change notification settings

ruediste/lambda-inspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda Inspector

Build Status

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.

Usage

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()));

About

Library to inspect lambda expressions and find out what they invoke

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages