Proposal - GenerateEnumNames & GenerateEnumReferences

27 views
Skip to first unread message

Frederik Heick

unread,
Nov 9, 2025, 12:38:38 PM (11 days ago) Nov 9
to Project Lombok
I have creaded my own, but where it generate it in a seperate class.

I would really like to do it like FieldNameConstants, where it is an inner static class.


@GenerateEnumNames (Is like  FieldNameConstants but for enum names)

@GenerateEnumReferences - generate a <enum-full-class-name>#>enum-name>

Have an utility methods to generate and resolve it back to Enum instance

I have attached my code.

I hope you will have a look and consider added it.

Kind regards

Frederik Heick
GenerateEnumNames.java
GenerateEnumReferences.java
GenerateEnumConstantsProcessor.java
EnumReferenceUtils.java
CachedEnumReferenceUtils.java

Frederik Heick

unread,
Nov 9, 2025, 5:42:45 PM (11 days ago) Nov 9
to Project Lombok
Just updated a file 

It will generate 

public class TestPropertiesEnum_References {


public static final String APP_NAME = "dk.greentape.library.spring.totype.test.TestPropertiesEnum#APP_NAME";

public static final String APP_VERSION = "dk.greentape.library.spring.totype.test.TestPropertiesEnum#APP_VERSION";

public static final String APP_DEBUG = "dk.greentape.library.spring.totype.test.TestPropertiesEnum#APP_DEBUG";

}



And I use like this

@Getter

@Configuration

public class TestConfiguration {


// Test @ValueToTypeClass - simplest pattern

@ValueToTypeClass(

value = "${test.server.port}",

toTypeClass = IntegerToType.class

)

private Integer serverPort;


@ValueToTypeClass(

value = "${test.server.hostname}",

toTypeClass = StringToType.class

)

private String serverHostname;


@ValueToTypeClass(

value = "${test.server.timeout}",

toTypeClass = IntegerToType.class,

defaultValue = "60"

)

private Integer serverTimeout;


// Test @ValueToType - enum-based pattern

@ValueToType(

value = "${test.database.maxConnections}",

enumEntryReference = TestToTypesEnum_References.MAX_CONNECTIONS

)

private Integer maxConnections;


@ValueToType(

value = "${test.database.schema}",

enumEntryReference = TestToTypesEnum_References.SCHEMA_NAME

)

private String schemaName;


// Test @ValueToTypeProperty - most sophisticated pattern

@ValueToTypeProperty(

enumEntryReference = TestPropertiesEnum_References.APP_NAME

)

private String appName;


@ValueToTypeProperty(

enumEntryReference = TestPropertiesEnum_References.APP_VERSION

)

private String appVersion;


@ValueToTypeProperty(

enumEntryReference = TestPropertiesEnum_References.APP_DEBUG

)

private Boolean appDebug;

}


CachedEnumReferenceUtils.java

Frederik Heick

unread,
Nov 15, 2025, 4:27:30 PM (5 days ago) Nov 15
to Project Lombok

What I would like


@Getter

@RequiredArgsConstructor

@GenerateEnumReferences

public enum TestToTypesEnum implements ToTypeDefinitionEnum {


MAX_CONNECTIONS(new ToTypeDefinition(

IntegerToType.class,

new IntegerToType(1, 1000),

ToTypeReturn.simple(Integer.class),

null,

List.of(Integer.class)

)),


SCHEMA_NAME(new ToTypeDefinition(

StringToType.class,

new StringToType(1, 100),

ToTypeReturn.simple(String.class),

null,

List.of(String.class)

));


private final ToTypeDefinition definition;


@Override

public String getEnumEntryName() {

return name();

}

}


Would genererate


@Getter

@RequiredArgsConstructor

@GenerateEnumReferences

public enum TestToTypesEnum implements ToTypeDefinitionEnum {


MAX_CONNECTIONS(new ToTypeDefinition(

IntegerToType.class,

new IntegerToType(1, 1000),

ToTypeReturn.simple(Integer.class),

null,

List.of(Integer.class)

)),


SCHEMA_NAME(new ToTypeDefinition(

StringToType.class,

new StringToType(1, 100),

ToTypeReturn.simple(String.class),

null,

List.of(String.class)

));


private final ToTypeDefinition definition;


@Override

public String getEnumEntryName() {

return name();

}


public static class References {

Reply all
Reply to author
Forward
0 new messages