Coder Social home page Coder Social logo

lambda-inspector's Introduction

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

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

lambda-inspector's People

Contributors

ruediste avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.