value-processor

Helper for creating annotation processors that create/read value objects.

License

License

GroupId

GroupId

me.tatarka.value
ArtifactId

ArtifactId

value-processor
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

pom
Description

Description

value-processor
Helper for creating annotation processors that create/read value objects.
Project URL

Project URL

https://github.com/evant/value-processor
Source Code Management

Source Code Management

https://github.com/evant/value-processor

Download value-processor

How to add to project

<!-- https://jarcasting.com/artifacts/me.tatarka.value/value-processor/ -->
<dependency>
    <groupId>me.tatarka.value</groupId>
    <artifactId>value-processor</artifactId>
    <version>0.2</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/me.tatarka.value/value-processor/
implementation 'me.tatarka.value:value-processor:0.2'
// https://jarcasting.com/artifacts/me.tatarka.value/value-processor/
implementation ("me.tatarka.value:value-processor:0.2")
'me.tatarka.value:value-processor:pom:0.2'
<dependency org="me.tatarka.value" name="value-processor" rev="0.2">
  <artifact name="value-processor" type="pom" />
</dependency>
@Grapes(
@Grab(group='me.tatarka.value', module='value-processor', version='0.2')
)
libraryDependencies += "me.tatarka.value" % "value-processor" % "0.2"
[me.tatarka.value/value-processor "0.2"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.21

Project Modules

There are no modules declared in this project.

value-processor

Helper for creating annotation processors that create/read value objects.

Download

Gradle

dependencies {
  compile 'me.tatarka.value:value-processor:0.2'
}

Maven

<dependency>
  <groupId>me.tatarka.value</groupId>
  <artifactId>value-processor</artifactId>
  <version>0.2</version>
</dependency>

Usage

First you create a ValueCreator with the processing environment.

public class MyProcessor extends AbstractProcessor {

    private ValueCreator valueCreator;

    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        valueCreator = new ValueCreator(processingEnv);
    }

Then create a Value from an Element. There are various methods based on what you have annotated. For example, the below creates it from the target class.

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        for (TypeElement annotation : annotations) {
            Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
            for (Element element : elements) {
               try {
                   Value value = valueCreator.fromClass((TypeElement) element);
               } catch (ElementException e) {
                   e.printMessage(messenger);
               }
            }
        }
        return false;
    }

You can then iterate through the properties to generate your code.

// all properties
for (Property<?> property : value.getProperties()) {
    ...
}
// of a specific kind
for (Property.Getter getter : value.getProperties().getGetters()) {
    ...
}

Supported Classes

Note: Classes are expected to be treated as immutable. This meas you can only create instances with properties or read properties on and instance.

Fields

public class Foo {
    public String bar;
}

Getters

public class Foo {
    public String getBar() { ... }
}

Constructor Params

public class Foo {
    public Foo(String bar) { ... }
}

Factory Method Params

public static Foo createFoo(String bar) { ... }

Builder

public class FooBuilder {
    public FooBuilder setBar(String bar) { ... }
    public Foo build() { ... }
}

Builder Constructor Params

public class FooBuilder {
    public FooBuilder(String bar) { ... }
    public Foo build() { ... }
}

Builder Factory Params

public static FooBuilder builder(String bar) { ... }

Kotlin Data Classes

data class Foo(val bar: String)

Versions

Version
0.2
0.1