se.arkalix.dto.DtoProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kalix-dto-processor Show documentation
Show all versions of kalix-dto-processor Show documentation
Contains an annotation processor for automatically generating data transmission objects specified using the annotations of the kalix-dto library.
The newest version!
package se.arkalix.dto;
import se.arkalix.dto.types.DtoDescriptor;
import se.arkalix.dto.types.DtoType;
import javax.lang.model.element.ExecutableElement;
import java.util.Map;
import java.util.Objects;
public class DtoProperty {
private final ExecutableElement method;
private final String name;
private final Map dtoCodecToName;
private final DtoType type;
private DtoProperty(final Builder builder) {
method = Objects.requireNonNull(builder.method, "method");
name = Objects.requireNonNull(builder.name, "name");
dtoCodecToName = Objects.requireNonNull(builder.dtoCodecToName, "dtoCodecToName");
type = Objects.requireNonNull(builder.type, "type");
}
public ExecutableElement method() {
return method;
}
public String name() {
return name;
}
public String nameFor(final DtoCodec codecType) {
return dtoCodecToName.getOrDefault(codecType, name);
}
public DtoType type() {
return type;
}
public DtoDescriptor descriptor() {
return type.descriptor();
}
public static class Builder {
private ExecutableElement method;
private String name;
private Map dtoCodecToName;
private DtoType type;
public Builder method(final ExecutableElement method) {
this.method = method;
return this;
}
public Builder name(final String name) {
this.name = name;
return this;
}
public Builder dtoCodecToName(final Map dtoCodecToName) {
this.dtoCodecToName = dtoCodecToName;
return this;
}
public Builder type(final DtoType type) {
this.type = type;
return this;
}
public DtoProperty build() {
return new DtoProperty(this);
}
}
}