Table of Contents

Overview

Manifold plugs directly into Java to supplement it with powerful features you can use directly in your projects:

Type-safe Metaprogramming with Type Manifolds

Bridging the worlds of data and code, a type manifold acts as an adapter to automatically connect data resources to Java’s type system. The core Manifold framework seamlessly plugs into the Java compiler enabling a type manifold to transform structured data into data types directly accessible in your Java code eliminating code generation build steps otherwise required with conventional tools. Additionally, the Manifold plugin provides comprehensive integration for type manifolds in both IntelliJ IDEA and Android Studio. Types are always in sync; changes you make to resources are immediately available in your code without a compilation step. Code completion, navigation, usage searching, deterministic refactoring, incremental compilation, hotswap debugging – all seamlessly integrated. With type manifolds a data resource is a virtual data type.

To illustrate, consider this simple properties resource file:

/abc/MyProperties.properties

chocolate = Chocolate
chocolate.milk = Milk chocolate
chocolate.dark = Dark chocolate

Normally in Java you access a properties file like this:

Properties myProperties = new Properties();
myProperties.load(getClass().getResourceAsStream("/abc/MyProperties.properties"));
String myMessage = myProperties.getProperty("chocolate.milk");

As with any resource file a properties file is foreign to Java’s type system – there is no direct, type-safe access to it. Instead you access it indirectly using boilerplate library code sprinkled with hard-coded strings.

By contrast, with the Properties type manifold you access a properties file directly as a type:

String myMessage = MyProperties.chocolate.milk;

Concise and type-safe, with no additional build steps to engage.

Any data resource is a potential type manifold, including file schemas, query languages, database definitions, data services, templates, spreadsheets, and programming languages.

Manifold provides type manifolds for:

The Extension Manifold

The extension manifold is a special kind of type manifold that lets you augment existing Java classes including Java’s own runtime classes such as String. You can add new methods, annotations, and interfaces to any type your project uses.

Let’s say you want to make a new method on String so you can straightforwardly echo a String to the console. Normally with Java you might write a “Util” library like this:

public class MyStringUtil {
  public static void echo(String value) {
    System.out.println(value);
  }
}

And you’d use it like this:

MyStringUtil.echo("Java");

Instead with Manifold you create an Extension Class:

@Extension
public class MyStringExtension {
  public static void echo(@This String thiz) {
    System.out.println(thiz);
  }
}

Here we’ve added a new echo() method to String, so we use it like this:

"Java".echo();

Extensions eliminate a lot of intermediate code such as “Util” and “Manager” libraries as well as Factory classes. As a consequence extensions naturally promote higher levels of object-orientation, which result in more readable and maintainable code. Additionally, with the Manifold IntelliJ plugin you can use code-completion which conveniently presents all the extension methods available on an extended class:

There’s a lot more to the extension manifold including operator overloading, unit expressions, structural interfaces, which are similar to interfaces in the Go and TypeScript languages. See the Java Extension Manifold for full coverage of these features.

New!

Learn more.

Benefits

Manifold’s core technology is a dramatic departure from conventional Java tooling. There are no code generation steps in the build, no extra build target files to manage, no annotation processors, and no extra class loaders to engage at runtime.

Benefits of this approach include:

Manifold is just a dependency you can drop into your existing project. You can begin using it incrementally without having to rewrite classes or conform to a new way of doing things.

IDE Support

Use Manifold to its fullest in IntelliJ IDEA and Android Studio using the Manifold IDE plugin.

The plugin provides comprehensive support for IDE features including:

Use code completion to discover and use type manifolds such as GraphQL and to access extension methods and structural interfaces. Jump directly from usages of extension methods to their declarations. Jump directly from call sites to resource elements and find usages of them in your code. Watch your GraphQL, JSON, XML, YAML, CSV, images, properties, templates, and custom type manifolds come alive as types. Changes you make in resource files are instantly available in your code, without compiling.

Install the plugin directly from the IDE via:

SettingsPluginsMarketplace ➜ search: Manifold

Get the plugin from JetBrains Marketplace:

Projects

The Manifold framework consists of the core project and a collection of sub-projects implementing SPIs provided by the core. Each project represents a separate dependency you can use directly in your project. See details in each projects’ docs.

Core Framework

Resource Manifolds

Java Extension Manifold

Java Properties

Java Templates Framework

Java Compiler Extensions

Java Preprocessor

Java Science

Java Extension Libraries

Sample Projects

Platforms

Manifold supports:

Comprehensive IDE support is also available for IntelliJ IDEA and Android Studio.

Setup

Manifold is designed to work with most build systems, including Maven and Gradle.

The Manifold root project consists of several sub-projects you can include separately in your build, see Projects above for a complete listing. If you’re targeting Android using Android Studio, see Using Manifold with Android Studio for additional setup information.

Setup instructions are consistent for each sub-project/dependency. Here are direct links:









Download

For the convenience of non-maven/non-gradle users you can directly download latest release binaries below.

WARNING If you plan to build your project without Maven or Gradle using select binaries, your classpath must include the transitive closure of binaries in terms of the dependencies declared in corresponding project’s POM file. Additionally, you will need to adapt your build to reflect the Maven or Gradle setup instructions from the list above.

For instance, to use the manifold-preprocessor jar using Ant your project needs:

As such your javac command line should include:

javac -Xplugin:Manifold -classpath <jar-path>/manifold-preprocessor-2024.1.10.jar;<jar-path>/manifold-2024.1.10.jar;<jar-path>/manifold-util-2024.1.10.jar









License

Manifold is open source and licensed under the Apache 2.0 license.

Author

Forum

Join our Slack Group to start a discussion, ask questions, provide feedback, etc. Someone is usually there to help.