CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-immutables--immutables

Comprehensive Java annotation processing framework for generating immutable value objects, marshalers, repositories, and custom code generators with extensive integration support.

Pending
Overview
Eval results
Files

styling.mddocs/

Style and Naming Customization

Comprehensive style system for customizing generated class names, method names, builder patterns, and structural conventions. The @Value.Style annotation provides extensive control over how generated code looks and behaves.

Capabilities

Value.Style Annotation

Comprehensive style customization for generated code structure and naming conventions.

/**
 * Comprehensive style customization for generated code.
 * Controls naming patterns, method signatures, and structural conventions
 * for all generated classes and methods.
 */
@Target({ElementType.TYPE, ElementType.PACKAGE})
@Retention(RetentionPolicy.SOURCE)
@interface Value.Style {
  /** Accessor method name patterns (e.g., "get*", "is*") */
  String[] get() default {};
  
  /** Builder setter method pattern */
  String init() default "*";
  
  /** Copy method pattern (withX methods) */
  String with() default "with*";
  
  /** Collection add method pattern */
  String add() default "add*";
  
  /** Collection addAll method pattern */
  String addAll() default "addAll*";
  
  /** Map put method pattern */
  String put() default "put*";
  
  /** Map putAll method pattern */
  String putAll() default "putAll*";
  
  /** Copy factory method name */
  String copyOf() default "copyOf";
  
  /** Static factory method name */
  String of() default "of";
  
  /** Singleton instance accessor name */
  String instance() default "instance";
  
  /** Builder factory method name */
  String builder() default "builder";
  
  /** Builder build method name */
  String build() default "build";
  
  /** Builder class name pattern */
  String typeBuilder() default "*Builder";
  
  /** Abstract type name detection patterns */
  String[] typeAbstract() default {};
  
  /** Immutable implementation name pattern */
  String typeImmutable() default "Immutable*";
  
  /** Umbrella/enclosing class name pattern */
  String typeImmutableEnclosing() default "*";
  
  /** Nested class name pattern */
  String typeImmutableNested() default "*";
  
  /** Default immutable annotation configuration */
  Immutable defaults() default @Immutable;
}

Bean-Style Accessors

Configure bean-style getter patterns for enterprise compatibility.

Usage Example:

import org.immutables.value.Value;

@Value.Style(get = {"get*", "is*"})
@Value.Immutable
public interface BeanStylePerson {
  String getName();
  int getAge();
  boolean isActive();
}

// Generated class has standard bean accessors
BeanStylePerson person = ImmutableBeanStylePerson.builder()
    .name("Alice")      // Builder uses simple names
    .age(30)
    .active(true)
    .build();

String name = person.getName();     // Bean-style getter
boolean active = person.isActive(); // Bean-style boolean getter

Custom Builder Patterns

Customize builder method names and patterns.

Usage Example:

import org.immutables.value.Value;

@Value.Style(
    init = "set*",           // Setter-style builder methods
    build = "create",        // Custom build method name
    typeBuilder = "*Factory" // Custom builder class name
)
@Value.Immutable
public interface CustomBuilderType {
  String name();
  int value();
}

// Usage with custom builder pattern
CustomBuilderType obj = ImmutableCustomBuilderType.factory()
    .setName("test")    // Custom setter pattern
    .setValue(42)
    .create();          // Custom build method

Copy Method Customization

Customize copy method patterns and names.

Usage Example:

@Value.Style(with = "update*")
@Value.Immutable
public interface UpdateablePerson {
  String name();
  int age();
  String email();
}

// Copy methods use custom pattern
UpdateablePerson person = ImmutableUpdateablePerson.builder()
    .name("Alice")
    .age(30)
    .email("alice@example.com")
    .build();

UpdateablePerson older = person.updateAge(31);        // updateAge instead of withAge
UpdateablePerson renamed = person.updateName("Alicia"); // updateName instead of withName

Collection Method Patterns

Customize collection manipulation method names.

Usage Example:

import org.immutables.value.Value;
import java.util.List;
import java.util.Map;
import java.util.Arrays;

@Value.Style(
    add = "append*",
    addAll = "appendAll*",
    put = "insert*",
    putAll = "insertAll*"
)
@Value.Immutable
public interface CustomCollectionType {
  List<String> items();
  Map<String, Integer> counts();
}

// Builder uses custom collection methods
CustomCollectionType obj = ImmutableCustomCollectionType.builder()
    .appendItems("a", "b", "c")           // appendItems instead of addItems
    .appendAllItems(Arrays.asList("d", "e")) // appendAllItems instead of addAllItems
    .insertCounts("key1", 10)             // insertCounts instead of putCounts
    .insertAllCounts(Map.of("key2", 20))  // insertAllCounts instead of putAllCounts
    .build();

Type Name Patterns

Control generated class and interface naming.

Usage Example:

@Value.Style(
    typeAbstract = {"Abstract*", "*Abstract"},  // Detect abstract types
    typeImmutable = "Concrete*",                // Custom implementation prefix
    typeBuilder = "*Creator"                    // Custom builder suffix
)
@Value.Immutable
public interface AbstractPersonData {
  String name();
  int age();
}

// Generated classes follow custom naming
// Implementation: ConcreteAbstractPersonData
// Builder: ConcreteAbstractPersonData.AbstractPersonDataCreator
AbstractPersonData person = ConcreteAbstractPersonData.creator()
    .name("Alice")
    .age(30)
    .build();

Factory Method Customization

Customize static factory method names.

Usage Example:

@Value.Style(
    of = "create",
    copyOf = "from",
    builder = "newBuilder"
)
@Value.Immutable
public interface FactoryStyleType {
  @Value.Parameter
  String value();
}

// Custom factory methods
FactoryStyleType obj1 = ImmutableFactoryStyleType.create("test");  // Custom 'of' method
FactoryStyleType obj2 = ImmutableFactoryStyleType.from(obj1);      // Custom 'copyOf' method
FactoryStyleType obj3 = ImmutableFactoryStyleType.newBuilder()     // Custom builder method
    .value("builder")
    .build();

Package-Level Styles

Apply styles to entire packages via package-info.java.

Usage Example:

// package-info.java
@Value.Style(
    get = {"get*"},
    typeImmutable = "Immutable*",
    visibility = ImplementationVisibility.PACKAGE
)
package com.example.model;

import org.immutables.value.Value;

Nested Type Patterns

Control nested and enclosing class naming.

Usage Example:

@Value.Style(
    typeImmutableEnclosing = "*Types",
    typeImmutableNested = "*"
)
public class ModelDefinitions {
  @Value.Immutable
  @Value.Nested
  public interface Person {
    String name();
  }
  
  @Value.Immutable
  @Value.Nested
  public interface Address {
    String street();
  }
}

// Generated: ModelDefinitionsTypes.Person, ModelDefinitionsTypes.Address
ModelDefinitionsTypes.Person person = ModelDefinitionsTypes.Person.builder()
    .name("Alice")
    .build();

Default Configuration Override

Set default @Value.Immutable settings for styled types.

Usage Example:

@Value.Style(
    defaults = @Value.Immutable(
        copy = false,           // Disable copy methods by default
        builder = true,         // Enable builders by default
        visibility = ImplementationVisibility.PACKAGE
    )
)
@Value.Immutable
public interface StyledType {
  String value();
}

// This type inherits the style defaults:
// - No copy methods generated
// - Builder enabled
// - Package-private implementation

Pre-defined Style Patterns

Enterprise/Bean Style

@Value.Style(
    get = {"get*", "is*"},
    init = "set*",
    typeImmutable = "*Impl",
    visibility = ImplementationVisibility.PACKAGE
)

Fluent Style

@Value.Style(
    get = {},              // No get prefix
    with = "*",            // Simple copy method names
    typeImmutable = "*"    // No Immutable prefix
)

Factory Style

@Value.Style(
    of = "create",
    builder = "newBuilder",
    build = "build",
    typeBuilder = "*Factory"
)

Install with Tessl CLI

npx tessl i tessl/maven-org-immutables--immutables

docs

attributes.md

bean-style.md

code-generation.md

collections.md

core-immutable.md

index.md

integrations.md

json-marshaling.md

runtime-marshaling.md

styling.md

tile.json