J%

J% module

GetSet

A list of fields in, a Java class with getters and setters out — the smallest module, and the one to copy when writing your own.

Base type
org.jmod.dsl.getset.GetSetType
Configuration
GetSetConfiguration

GetSet is not a domain-specific language in any interesting sense: its body is a list of names and types, and it writes the accessors nobody enjoys writing. It is here as the smallest complete example of what a module has to do.

Writing one

package demo;

import org.jmod.dsl.getset.GetSetType;
import org.jmod.dsl.getset.GetSetConfiguration;

public external Person extends GetSetType<GetSetConfiguration> {
#[name]<String> #[age]<int>
}

You get a Person with private name and age fields and a getter and setter for each, in the order you wrote them. Any Java type is accepted — java.util.UUID, arrays, your own classes — and text in the body that is not a #[name]<Type> is ignored.

GS_GEN_GETTER and GS_GEN_SETTER, both on by default, drop either half.

Writing your own module

Four things, and GetSet is the shortest example of each: a compile-time class that validates the body and renders a template, a runtime base type with its configuration, the template itself, and one line registering it. The compiler does not care what the body means — that is entirely the module's business.