Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
Manifold is a Java compiler plugin. Its features include: * Type-safe Meta-programming * Extension Methods * Properties (New!) * Operator Overloading * Unit Expressions * A Java Template Engine * A Preprocessor * ...and more
All fully supported in Java 8 - 16 with comprehensive IDE support in IntelliJ IDEA and Android Studio. Simply add Manifold to your existing project and begin taking advantage of it.
New!
* Finally, Properties for Java * Includes automatic property inference for existing Java classes 😎
Use the framework to gain direct, type-safe access to any type of resource, such as GraphQL, JSON, XML, YAML, CSV, and even other languages such as JavaScript. Remove the code gen step in your build process. ▶ Check it out!
GraphQL: Use types defined in .graphql files directly, no code gen steps! Make GraphQL changes and immediately use them with code completion.
java var query = MovieQuery.builder(Action).build(); var result = query.request("http://example.com/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.
java // 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);
Add your own methods to existing Java classes, even String, List, and File. Eliminate boilerplate code. ▶ Check it out!
java String greeting = "hello"; greeting.myMethod(); // Add your own methods to String!
Eliminate boilerplate getter/setter code, improve your overall dev experience with properties.
java 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 & setterAdditionally, the feature automatically infers properties, both from your existing source files and from compiled classes your project uses. Reduce property use from this:
java Actor person = result.getMovie().getLeadingRole().getActor(); Likes likes = person.getLikes(); likes.setCount(likes.getCount() + 1);to this:
java result.movie.leadingRole.actor.likes.count++;
Implement operator methods on any type to directly support arithmetic, relational, index, and unit operators.
java // BigDecimal expressions if (bigDec1 > bigDec2) { BigDecimal result = bigDec1 + bigDec2; ... } // Implement operators for any type MyType value = myType1 + myType2;
Unit or binding operations are unique to the Manifold framework. They provide a powerfully concise syntax and can be applied to a wide range of applications.
java import static manifold.science.util.UnitConstants.*; // kg, m, s, ft, etc ... Length distance = 100 mph * 3 hr; Force f = 5.2 kg m/s/s; // same as 5.2 N Mass infant = 9 lb + 8.71 oz;
Easily work with the Range API using unit expressions. Simply import the RangeFun constants to create ranges. ``
java // imports theto
,step`, and other "binding" constants import static manifold.collections.api.range.RangeFun.*; ... for (int i: 1 to 5) { out.println(i); }
for (Mass m: 0kg to 10kg step 22r unit g) { out.println(m); } ```
Use the manifold-science framework to type-safely incorporate units and precise measurements into your applications.
java import static manifold.science.util.UnitConstants.*; // kg, m, s, ft, etc. ... Velocity rate = 65mph; Time time = 1min + 3.7sec; Length distance = rate * time;
Use familiar directives such as #define and #if to conditionally compile your Java projects. The preprocessor offers a simple and convenient way to support multiple build targets with a single codebase. ▶ Check it out! ```java
@Override public void setTime(LocalDateTime time) {...}
@Override public void setTime(Calendar time) {...}
### [Structural Typing](https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-ext#structural-interfaces-via-structural) Unify disparate APIs. Bridge software components you do not control. Access maps through type-safe interfaces. [ **▶** Check it out!](http://manifold.systems/images/structural%20typing.mp4) ```java Map map = new HashMap<>(); MyThingInterface thing = (MyThingInterface) map; // O_o thing.setFoo(new Foo()); Foo foo = thing.getFoo(); out.println(thing.getClass()); // prints "java.util.HashMap"
Access private features with @Jailbreak to avoid the drudgery and vulnerability of Java reflection. ▶ Check it out!
java @Jailbreak Foo foo = new Foo(); // Direct, *type-safe* access to *all* foo's members foo.privateMethod(x, y, z); foo.privateField = value;
You now have an option to make checked exceptions behave like unchecked exceptions! No more unintended exception swallowing. No more try/catch/wrap/rethrow boilerplate!
java List strings = ...; List urls = list .map(URL::new) // No need to handle the MalformedURLException! .collect(Collectors.toList());
Embed variables and expressions in String literals, no more clunky string concat! ▶ Check it out!
java int hour = 15; // Simple variable access with '$' String result = "The hour is $hour"; // Yes!!! // Use expressions with '${}' result = "It is ${hour > 12 ? hour-12 : hour} o'clock";
Author template files with the full expressive power of Java, use your templates directly in your code as types. Supports type-safe inclusion of other templates, shared layouts, and more. ▶ Check it out!
java List users = ...; String content = abc.example.UserSample.render(users);A template file abc/example/UserSample.html.mtl
htmlusers) %>
user.getDateOfBirth() != null) .forEach(user -> { %> User: ${user.getName()}
DOB: ${user.getDateOfBirth()}
Use the Manifold plugin to fully leverage Manifold with IntelliJ IDEA and Android Studio. The plugin provides comprehensive support for Manifold including code completion, navigation, usage searching, refactoring, incremental compilation, hotswap debugging, full-featured template editing, integrated preprocessor, and more.
Get the plugin from JetBrains Marketplace:
The Manifold project consists of the core Manifold framework and a collection of sub-projects implementing SPIs provided by the core framework. Each project consists of one or more dependencies you can easily add to your project:
Manifold : GraphQL
Manifold : JSON
Manifold : XML
Manifold : YAML
Manifold : CSV
Manifold : Property files
Manifold : Image files
Manifold : Dark Java
Manifold : JavaScript
Manifold : String Interpolation
Manifold : (Un)checked Exceptions
Manifold : Collections
Manifold : I/0
Manifold : Text
Experiment with sample projects:
* Manifold : Sample App
* Manifold : Sample GraphQL App
* Manifold : Sample REST API App
* Manifold : Sample Web App * Manifold : Sample Kotlin App * Manifold : Gradle Example Project
Join our Slack Group to start a discussion, ask questions, provide feedback, etc. Someone is usually there to help.