Manifold
Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
Install / Use
/learn @manifold-systems/ManifoldREADME
What is Manifold?
Manifold is a Java compiler plugin. Use it to supplement your Java projects with highly productive features.
Advanced compile-time <b>metaprogramming</b> type-safely integrates any kind of data, metadata, or DSL directly into Java.
- SQL (New!)
- GraphQL
- JSON & JSON Schema, YAML, XML
- CSV
- JavaScript
- etc.
Powerful language enhancements improve developer productivity.
- Extension methods
- True delegation
- Properties
- Optional parameters (New!)
- Tuple expressions
- Operator overloading
- Unit expressions
- A Java template engine
- A preprocessor
- ...and more
Each feature is available as a separate dependency. Simply add the Manifold dependencies of your choosing to your existing project and begin taking advantage of them.
All fully supported in JDK LTS releases 8 - 25 + latest with comprehensive IDE support in IntelliJ IDEA and Android Studio.
What's New...
<img width="40%" align="top" src="./docs/images/manifoldsql.png">
Type-safe SQL
Manifold SQL lets you write native SQL directly and type-safely in your Java code.
Who is using Manifold?
Sampling of companies using Manifold:
<img width="80%" src="./docs/images/companies.png">What can you do with Manifold?
Meta-programming
Use the framework to gain direct, type-safe access to any type of resource, such as SQL, JSON, GraphQL, XML, YAML, CSV, and even other languages such as JavaScript. Remove the code gen step in your build process. ▶ Check it out!
SQL: Use native SQL of any complexity directly and type-safely from Java.
Language english =
"[.sql/]select * from Language where name = 'English'".fetchOne();
Film film = Film.builder("My Movie", english)
.withDescription("Nice movie")
.withReleaseYear(2023)
.build();
MyDatabase.commit();
GraphQL: Use types defined in .graphql files directly, no code gen steps! Make GraphQL changes and immediately use them with code completion.
var query = MovieQuery.builder(Action).build();
var result = query.request("http://com.example/graphql").post();
var actionMovies = result.getMovies();
for (var movie : actionMovies) {
out.println(
"Title: " + movie.getTitle() + "\n" +
"Genre: " + movie.getGenre() + "\n" +
"Year: " + movie.getReleaseDate().getYear() + "\n");
}
JSON: Use .json schema files directly and type-safely, no code gen steps! Find usages of .json properties in your Java code.
// From User.json
User user = User.builder("myid", "mypassword", "Scott")
.withGender(male)
.withDob(LocalDate.of(1987, 6, 15))
.build();
User.request("http://api.example.com/users").postOne(user);
Extension Methods
Add your own methods to existing Java classes, even String, List, and File. Eliminate boilerplate code. ▶ Check it out!
String greeting = "hello";
greeting.myMethod(); // Add your own methods to String!
Delegation
Favor composition over inheritance. Use @link and @part for automatic interface implementation forwarding and true delegation.
class MyClass implements MyInterface { @link MyInterface myInterface; // transfers calls on MyInterface to myInterface public MyClass(MyInterface myInterface) { this.myInterface = myInterface; // dynamically configure behavior } // No need to implement MyInterface here, but you can override myInterface as needed }
Properties
Eliminate boilerplate getter/setter code, improve your overall dev experience with properties.
public interface Book {
@var String title; // no more boilerplate code!
}
// refer to it directly by name
book.title = "Daisy"; // calls setter
String name = book.title; // calls getter
book.title += " chain"; // calls getter & setter
Additionally, the feature automatically infers properties, both from your existing source files and from compiled classes your project uses. Reduce property use from this:
Actor person = result.getMovie().getLeadingRole().getActor();
Likes likes = person.getLikes();
likes.setCount(likes.getCount() + 1);
to this:
result.movie.leadingRole.actor.likes.count++;
Optional parameters & named arguments
Use optional parameters and named arguments with any Java project to add clarity and flexibility to call sites and as a refreshing alternative to method overloads and builders.
String valueOf(char[] data,
int offset = 0,
int count = data.length - offset) {...}
valueOf(array) // use defaults for offset and count
valueOf(array, 2) // use default for count
valueOf(array, count:20) // use default for offset by naming count
Binary compatible with methods, constructors, and records.
Operator Overloading
Implement operator methods on any type to directly support arithmetic, relational, index, and unit operators.
// BigDecimal expressions
if (bigDec1 > bigDec2) {
BigDecimal result = bigDec1 + bigDec2;
...
}
// Implement operators for any type
MyType value = myType1 + myType2;
Tuple expressions
Tuple expressions provide concise syntax to group named data items in a lightweight structure.
var t = (name: "Bob", age: "35");
System.out.println("Name: " + t.name + " Age: " + t.age);
var t = (person.name, person.age);
System.out.println("Name: " + t.name + " Age: " + t.age);
You can also use tuples with new [auto type inference](https://github.com

