MCPcopy Index your code
hub / github.com/UnquietCode/Flapi

github.com/UnquietCode/Flapi @2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 2.0 ↗ · + Follow
1,087 symbols 3,495 edges 204 files 216 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Flapi - A fluent API generator for Java

v2.0 Build Status

Tip with Gratipay Tip with BitcoinBitcoin

What is it?

Flapi is a code generation library for creating fluent API's in Java. Fluent builders allow developers to more easily interact with your code, using a syntax more akin to natural language. See these articles for more information.

Flapi turns this:
Descriptor builder = Flapi.builder()
    .setPackage("unquietcode.tools.flapi.examples.email.builder")
    .setStartingMethodName("composeEmail")
    .setDescriptorName("Email")

    .addMethod("subject(String subject)").atMost(1)
    .addMethod("addRecipient(String emailAddress)").atLeast(1)
    .addMethod("sender(String emailAddress)").exactly(1)
    .addMethod("body(String text)").atMost(1)
    .addMethod("send()").last(EmailMessage.class)
.build();
...or this:
interface EmailHelper {

    @AtMost(1) void subject(String subject);
    @AtLeast(1) void addRecipient(String emailAddress);
    @Exactly(1) void sender(String emailAddress);
    @Any void addCC(String emailAddress);
    @Any void addBCC(String emailAddress);
    @AtMost(1) void body(String text);
    @Any void addAttachment(File file);
    @Last EmailMessage send();
}

Flapi.create(EmailHelper.class)
    .setPackage("unquietcode.tools.flapi.examples.email.builder")
    .setStartingMethodName("compose")
.build();
...into this:
composeEmail()
    .sender("HAL9000@gmail.com")
    .addRecipient("dave@unquietcode.com")
    .subject("Just what do you think you're doing, Dave?")
    .body("I know that you and Frank were planning to disconnect me, " +
          "and I'm afraid that's something I cannot allow to happen...")
.send();

Getting Started

If you are using Maven (or Gradle, or Ivy) include the following dependency in your build script:

Maven

<dependency>
  <groupId>com.unquietcode.tools.flapi</groupId>
  <artifactId>flapi</artifactId>
  <version>2.0</version>
  <scope>test</scope>
</dependency>

Gradle

dependencies {
  testCompile 'com.unquietcode.tools.flapi:flapi:2.0'
}

In a test define your Descriptor object and output the generated source code. (The Pizza Builder example is a simple descriptor you can start with.) You can also make use of the Gradle plugin, or the Maven plugin, to perform the code generation.

Version 2.x of the project is built against JDK 8, while still exposing a JDK 7 compatible API, but using JDK 8 as the default target for code generation (selectable down to JDK 5). Version 1.x is built against JDK 7, and has a JDK 6 compatible API.

(PSA: If you are still using JDK 7 or lower, please do something about that soon.)

Additional Resources

  • Documentation
    Please visit the documentation page for a tour of Flapi's features and how to use them. (generated using the very nice tool docker)

  • Examples
    Many helpful examples are included on the wiki, corresponding to examples and tests in the src/test directory.

  • Upgrade Guide
    If you started using Flapi before version 1.0, check out this guide to see how to upgrade.

  • Blog Post
    The original blog post describing Flapi.

What's the project's status?

Version 1.0 and 2.0 have been released, marking a huge milestone in the stability of the code. If you started using Flapi before this version, check out the Upgrade Guide to see how to upgrade, since some deprecated features have been removed. See the Release Notes for the full release notes.

Going forward, the 1.x line will only receive important fixes and updates, with all new development firmly rooted in 2.x / JDK 8.

Problems?

Use the issue tracker to report problems encountered or new feature requests.

Contributing

Feel free to fork the project and fiddle around! Submit pull requests to improve the code.
Create issues to help support the project. Ask questions. (Say hello.)

Tip with Gratipay Tip with BitcoinBitcoin

If you like this software and find it useful, then please consider supporting my efforts through a donation via BitCoin or other means.

Special thanks to Concurrent, Inc. for their feedback and support as a user of Flapi, which they use in their Fluid library for Cascading.

License

Flapi is licensed under the Apache Software License (ASL) 2.0

Thanks!

Peace, love, and code.

Extension points exported contracts — how you extend this code

DescriptorMaker (Interface)
Classes which wish to make use of reflective tools should implement this to signal that they can return a valid descript [18 …
src/main/java/unquietcode/tools/flapi/DescriptorMaker.java
ExecutionListener (Interface)
Listen and respond to executions of methods in a builder. @author Ben Fagin @version 2013-07-02 [5 implementers]
flapi-runtime/src/main/java/unquietcode/tools/flapi/runtime/ExecutionListener.java
CalculatorFactory (Interface)
This class was generated using Flapi, the fluent API generator for Java. Modifications to this file will be lost upon re [3 …
src/test/java/unquietcode/tools/flapi/examples/calculator/builder/Calculator/CalculatorFactory.java
MyHelper (Interface)
(no doc)
Documentation.java
TransitionVisitor (Interface)
@author Ben Fagin @version 08-16-2012 [5 implementers]
src/main/java/unquietcode/tools/flapi/graph/TransitionVisitor.java
Consumer (Interface)
Simple little ditty to consume things. This is meant to be replaced by the real type contained within Java 8, whenever [5 …
flapi-runtime/src/main/java/unquietcode/tools/flapi/runtime/Consumer.java
ProcessFactory (Interface)
This class was generated using Flapi, the fluent API generator for Java. Modifications to this file will be lost upon re [3 …
src/test/java/unquietcode/tools/flapi/examples/pipes/builder/Process/ProcessFactory.java
Outline (Interface)
@author Ben Fagin @version 03-07-2012 Marker interface for outlines. [4 implementers]
src/main/java/unquietcode/tools/flapi/outline/Outline.java

Core symbols most depended-on inside this repo

addMethod
called by 194
src/main/java/unquietcode/tools/flapi/outline/BlockOutline.java
get
called by 121
flapi-runtime/src/main/java/unquietcode/tools/flapi/runtime/Supplier.java
last
called by 108
src/main/java/unquietcode/tools/flapi/helpers/MethodHelperImpl.java
any
called by 99
src/main/java/unquietcode/tools/flapi/helpers/MethodHelperImpl.java
build
called by 63
src/main/java/unquietcode/tools/flapi/helpers/DescriptorConfiguratorHelperImpl.java
setPackage
called by 56
src/main/java/unquietcode/tools/flapi/helpers/DescriptorConfiguratorHelperImpl.java
withDocumentation
called by 55
src/main/java/unquietcode/tools/flapi/helpers/MethodHelperImpl.java
startBlock
called by 54
Documentation.java

Shape

Method 868
Class 124
Interface 90
Enum 5

Languages

Java100%

Modules by API surface

src/test/java/unquietcode/tools/flapi/MethodParser_T.java46 symbols
src/test/java/unquietcode/tools/flapi/BuildChecks_T.java30 symbols
src/main/java/unquietcode/tools/flapi/outline/MethodInfo.java21 symbols
src/main/java/unquietcode/tools/flapi/outline/BlockOutline.java21 symbols
flapi-plugin/src/main/java/unquietcode/tools/flapi/plugin/PluginHelper.java20 symbols
src/test/java/unquietcode/tools/flapi/examples/email/EmailMessage.java17 symbols
src/main/java/unquietcode/tools/flapi/java/MethodSignature.java17 symbols
flapi-build-test-producer/src/main/java/unquietcode/tools/flapi/plugin/EmailMessage.java17 symbols
src/main/java/unquietcode/tools/flapi/outline/DescriptorOutline.java16 symbols
src/main/java/unquietcode/tools/flapi/graph/components/Transition.java15 symbols
flapi-build-test-consumer/src/test/java/unquietcode/tools/flapi/plugin/DescriptorTest.java15 symbols
src/main/java/unquietcode/tools/flapi/helpers/MethodHelperImpl.java14 symbols

For agents

$ claude mcp add Flapi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact