Skip to content

Generating Annotations, Lombok Lite for ConfigLib #43

@RE4ERKA

Description

@RE4ERKA

The Lombok library, which generates methods and constructors using annotations, indeed works very well with ConfigLib library. However, configuration classes often become too verbose due to the number of annotations, especially when there are many configuration sections (i.e., nested classes).

It would be great if, despite the fact that this functionality can already be fully achieved through Lombok, using just a single @Configuration annotation could automatically generate getters and, more importantly, empty constructors required for reflective instantiation of the class.

Example class using Lombok:

@Getter
@Accessors(fluent = true)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("FieldMayBeFinal")
@Configuration
public final class BaseConfiguration {

  private String content;
  private int value;

  private ConfigurationSection = new ConfigurationSection();

  @Getter
  @Accessors(fluent = true)
  @NoArgsConstructor(access = AccessLevel.PRIVATE)
  @Configuration
  public final class ConfigurationSection {
    
    private String content;
    private int value;
  }
}

A more concise version:

@SuppressWarnings("FieldMayBeFinal")
@Configuration(fluent = true)
public final class BaseConfiguration {

  private String content;
  private int value;

  private ConfigurationSection = new ConfigurationSection();

  @Configuration(fluent = true)
  public final class ConfigurationSection {
    
    private String content;
    private int value;
  }
}

In my example, the @Configuration annotation also takes into account whether the getters should be fluent or not, which is useful for those who prefer even more concise methods for accessing values from the class.

Most likely, a separate project would need to be created for these annotations — something like ConfigLib-Annotations — which users would also need to add to their project dependencies if they want to use these annotations.

implementation 'de.exlll:configlib-yaml:4.6.1'

compileOnly 'de.exlll:configlib-annotations:1.0.0'
annotationProcessor 'de.exlll:configlib-annotations:1.0.0'

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions