Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;

/** A Prism representing a {@link io.avaje.recordbuilder.DefaultInit @DefaultInit} annotation. */
/** A Prism representing a {@link io.avaje.recordbuilder.DefaultValue @DefaultValue} annotation. */
@Generated("avaje-prism-generator")
final class DefaultInitPrism {
final class DefaultValuePrism {
/** store prism value of value */
private final String _value;

public static final String PRISM_TYPE = "io.avaje.recordbuilder.DefaultInit";
public static final String PRISM_TYPE = "io.avaje.recordbuilder.DefaultValue";

/**
* An instance of the Values inner class whose methods return the AnnotationValues used to build
Expand All @@ -28,7 +28,7 @@ final class DefaultInitPrism {

/**
* Returns true if the mirror is an instance of {@link
* io.avaje.recordbuilder.DefaultInit @DefaultInit} is present on the element, else false.
* io.avaje.recordbuilder.DefaultValue @DefaultValue} is present on the element, else false.
*
* @param mirror mirror.
* @return true if prism is present.
Expand All @@ -38,7 +38,7 @@ static boolean isInstance(AnnotationMirror mirror) {
}

/**
* Returns true if {@link io.avaje.recordbuilder.DefaultInit @DefaultInit} is present on the
* Returns true if {@link io.avaje.recordbuilder.DefaultValue @DefaultValue} is present on the
* element, else false.
*
* @param element element.
Expand All @@ -49,66 +49,66 @@ static boolean isPresent(Element element) {
}

/**
* Return a prism representing the {@link io.avaje.recordbuilder.DefaultInit @DefaultInit}
* Return a prism representing the {@link io.avaje.recordbuilder.DefaultValue @DefaultValue}
* annotation present on the given element. similar to {@code
* element.getAnnotation(DefaultInit.class)} except that an instance of this class rather than an
* instance of {@link io.avaje.recordbuilder.DefaultInit @DefaultInit} is returned.
* element.getAnnotation(DefaultValue.class)} except that an instance of this class rather than an
* instance of {@link io.avaje.recordbuilder.DefaultValue @DefaultValue} is returned.
*
* @param element element.
* @return prism on element or null if no annotation is found.
*/
static DefaultInitPrism getInstanceOn(Element element) {
static DefaultValuePrism getInstanceOn(Element element) {
final var mirror = getMirror(element);
if (mirror == null) return null;
return getInstance(mirror);
}

/**
* Return a Optional representing a nullable {@link
* io.avaje.recordbuilder.DefaultInit @DefaultInit} annotation on the given element. similar to
* {@link element.getAnnotation(io.avaje.recordbuilder.DefaultInit.class)} except that an Optional
* of this class rather than an instance of {@link io.avaje.recordbuilder.DefaultInit} is
* io.avaje.recordbuilder.DefaultValue @DefaultValue} annotation on the given element. similar to
* {@link element.getAnnotation(io.avaje.recordbuilder.DefaultValue.class)} except that an Optional
* of this class rather than an instance of {@link io.avaje.recordbuilder.DefaultValue} is
* returned.
*
* @param element element.
* @return prism optional for element.
*/
static Optional<DefaultInitPrism> getOptionalOn(Element element) {
static Optional<DefaultValuePrism> getOptionalOn(Element element) {
final var mirror = getMirror(element);
if (mirror == null) return Optional.empty();
return getOptional(mirror);
}

/**
* Return a prism of the {@link io.avaje.recordbuilder.DefaultInit @DefaultInit} annotation from
* Return a prism of the {@link io.avaje.recordbuilder.DefaultValue @DefaultValue} annotation from
* an annotation mirror.
*
* @param mirror mirror.
* @return prism for mirror or null if mirror is an incorrect type.
*/
static DefaultInitPrism getInstance(AnnotationMirror mirror) {
static DefaultValuePrism getInstance(AnnotationMirror mirror) {
if (mirror == null || !PRISM_TYPE.equals(mirror.getAnnotationType().toString())) return null;

return new DefaultInitPrism(mirror);
return new DefaultValuePrism(mirror);
}

/**
* Return an Optional representing a nullable {@link DefaultInitPrism @DefaultInitPrism} from an
* annotation mirror. similar to {@link e.getAnnotation(io.avaje.recordbuilder.DefaultInit.class)}
* Return an Optional representing a nullable {@link DefaultValuePrism @DefaultValuePrism} from an
* annotation mirror. similar to {@link e.getAnnotation(io.avaje.recordbuilder.DefaultValue.class)}
* except that an Optional of this class rather than an instance of {@link
* io.avaje.recordbuilder.DefaultInit @DefaultInit} is returned.
* io.avaje.recordbuilder.DefaultValue @DefaultValue} is returned.
*
* @param mirror mirror.
* @return prism optional for mirror.
*/
static Optional<DefaultInitPrism> getOptional(AnnotationMirror mirror) {
static Optional<DefaultValuePrism> getOptional(AnnotationMirror mirror) {
if (mirror == null || !PRISM_TYPE.equals(mirror.getAnnotationType().toString()))
return Optional.empty();

return Optional.of(new DefaultInitPrism(mirror));
return Optional.of(new DefaultValuePrism(mirror));
}

private DefaultInitPrism(AnnotationMirror mirror) {
private DefaultValuePrism(AnnotationMirror mirror) {
for (final ExecutableElement key : mirror.getElementValues().keySet()) {
memberValues.put(key.getSimpleName().toString(), mirror.getElementValues().get(key));
}
Expand All @@ -126,7 +126,7 @@ private DefaultInitPrism(AnnotationMirror mirror) {
* Returns a String representing the value of the {@code java.lang.String value()} member of the
* Annotation.
*
* @see io.avaje.recordbuilder.DefaultInit#value()
* @see io.avaje.recordbuilder.DefaultValue#value()
*/
public String value() {
return _value;
Expand All @@ -147,7 +147,7 @@ public String value() {
final AnnotationMirror mirror;
/**
* A class whose members corespond to those of {@link
* io.avaje.recordbuilder.DefaultInit @DefaultInit} but which each return the AnnotationValue
* io.avaje.recordbuilder.DefaultValue @DefaultValue} but which each return the AnnotationValue
* corresponding to that member in the model of the annotations. Returns null for defaulted
* members. Used for Messager, so default values are not useful.
*/
Expand All @@ -171,7 +171,7 @@ AnnotationValue value() {
private boolean valid = true;

private <T> T getValue(String name, Class<T> clazz) {
final T result = DefaultInitPrism.getValue(memberValues, defaults, name, clazz);
final T result = DefaultValuePrism.getValue(memberValues, defaults, name, clazz);
if (result == null) valid = false;
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;

/** A Prism representing a {@link io.avaje.recordbuilder.DefaultInit.Global @Global} annotation. */
/** A Prism representing a {@link io.avaje.recordbuilder.DefaultValue.Global @Global} annotation. */
@Generated("avaje-prism-generator")
final class GlobalPrism {
/** store prism value of type */
Expand All @@ -22,7 +22,7 @@ final class GlobalPrism {
/** store prism value of value */
private final String _value;

public static final String PRISM_TYPE = "io.avaje.recordbuilder.DefaultInit.Global";
public static final String PRISM_TYPE = "io.avaje.recordbuilder.DefaultValue.Global";

/**
* An instance of the Values inner class whose methods return the AnnotationValues used to build
Expand All @@ -32,7 +32,7 @@ final class GlobalPrism {

/**
* Returns true if the mirror is an instance of {@link
* io.avaje.recordbuilder.DefaultInit.Global @Global} is present on the element, else false.
* io.avaje.recordbuilder.DefaultValue.Global @Global} is present on the element, else false.
*
* @param mirror mirror.
* @return true if prism is present.
Expand All @@ -42,7 +42,7 @@ static boolean isInstance(AnnotationMirror mirror) {
}

/**
* Returns true if {@link io.avaje.recordbuilder.DefaultInit.Global @Global} is present on the
* Returns true if {@link io.avaje.recordbuilder.DefaultValue.Global @Global} is present on the
* element, else false.
*
* @param element element.
Expand All @@ -53,10 +53,10 @@ static boolean isPresent(Element element) {
}

/**
* Return a prism representing the {@link io.avaje.recordbuilder.DefaultInit.Global @Global}
* Return a prism representing the {@link io.avaje.recordbuilder.DefaultValue.Global @Global}
* annotation present on the given element. similar to {@code element.getAnnotation(Global.class)}
* except that an instance of this class rather than an instance of {@link
* io.avaje.recordbuilder.DefaultInit.Global @Global} is returned.
* io.avaje.recordbuilder.DefaultValue.Global @Global} is returned.
*
* @param element element.
* @return prism on element or null if no annotation is found.
Expand All @@ -69,10 +69,10 @@ static GlobalPrism getInstanceOn(Element element) {

/**
* Return a Optional representing a nullable {@link
* io.avaje.recordbuilder.DefaultInit.Global @Global} annotation on the given element. similar to
* {@link element.getAnnotation(io.avaje.recordbuilder.DefaultInit.Global.class)} except that an
* io.avaje.recordbuilder.DefaultValue.Global @Global} annotation on the given element. similar to
* {@link element.getAnnotation(io.avaje.recordbuilder.DefaultValue.Global.class)} except that an
* Optional of this class rather than an instance of {@link
* io.avaje.recordbuilder.DefaultInit.Global} is returned.
* io.avaje.recordbuilder.DefaultValue.Global} is returned.
*
* @param element element.
* @return prism optional for element.
Expand All @@ -84,7 +84,7 @@ static Optional<GlobalPrism> getOptionalOn(Element element) {
}

/**
* Return a prism of the {@link io.avaje.recordbuilder.DefaultInit.Global @Global} annotation from
* Return a prism of the {@link io.avaje.recordbuilder.DefaultValue.Global @Global} annotation from
* an annotation mirror.
*
* @param mirror mirror.
Expand All @@ -98,9 +98,9 @@ static GlobalPrism getInstance(AnnotationMirror mirror) {

/**
* Return an Optional representing a nullable {@link GlobalPrism @GlobalPrism} from an annotation
* mirror. similar to {@link e.getAnnotation(io.avaje.recordbuilder.DefaultInit.Global.class)}
* mirror. similar to {@link e.getAnnotation(io.avaje.recordbuilder.DefaultValue.Global.class)}
* except that an Optional of this class rather than an instance of {@link
* io.avaje.recordbuilder.DefaultInit.Global @Global} is returned.
* io.avaje.recordbuilder.DefaultValue.Global @Global} is returned.
*
* @param mirror mirror.
* @return prism optional for mirror.
Expand Down Expand Up @@ -131,7 +131,7 @@ private GlobalPrism(AnnotationMirror mirror) {
* Returns a TypeMirror representing the value of the {@code java.lang.Class<?> type()} member of
* the Annotation.
*
* @see io.avaje.recordbuilder.DefaultInit.Global#type()
* @see io.avaje.recordbuilder.DefaultValue.Global#type()
*/
public TypeMirror type() {
return _type;
Expand All @@ -141,7 +141,7 @@ public TypeMirror type() {
* Returns a String representing the value of the {@code java.lang.String value()} member of the
* Annotation.
*
* @see io.avaje.recordbuilder.DefaultInit.Global#value()
* @see io.avaje.recordbuilder.DefaultValue.Global#value()
*/
public String value() {
return _value;
Expand All @@ -162,7 +162,7 @@ public String value() {
final AnnotationMirror mirror;
/**
* A class whose members corespond to those of {@link
* io.avaje.recordbuilder.DefaultInit.Global @Global} but which each return the AnnotationValue
* io.avaje.recordbuilder.DefaultValue.Global @Global} but which each return the AnnotationValue
* corresponding to that member in the model of the annotations. Returns null for defaulted
* members. Used for Messager, so default values are not useful.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ String fields() {
final var uType = UType.parse(element.asType());

String defaultVal = "";
final DefaultInitPrism initPrism = DefaultInitPrism.getInstanceOn(element);
final DefaultValuePrism initPrism = DefaultValuePrism.getInstanceOn(element);
if (initPrism != null) {
defaultVal = " = " + initPrism.value();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean process(Set<? extends TypeElement> tes, RoundEnvironment roundEnv
logError(type, "Builders can only be generated for record classes");
continue;
}
UType.parse(type.asType()).shortWithoutAnnotations();

readElement(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,4 @@
final class Utils {
private Utils() {}

static String extractTypeWithNest(String fullType) {
int p = fullType.lastIndexOf('.');
if (p == -1 || fullType.startsWith("java")) {
return fullType;
}
final StringBuilder result = new StringBuilder();
var foundClass = false;
var firstClass = true;
for (final String part : fullType.split("\\.")) {
if (Character.isUpperCase(part.charAt(0))) {
foundClass = true;
}
result.append(foundClass && !firstClass ? "/" : ".").append(part);
if (foundClass) {
firstClass = false;
}
}
if (result.charAt(0) == '.') {
result.deleteCharAt(0);
}
final var fullResult = result.toString();

p = fullResult.lastIndexOf('/');
if (p == -1) {
return fullResult;
}
return fullResult.substring(0, p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.lang.annotation.ElementType.MODULE;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.RECORD_COMPONENT;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;
Expand All @@ -11,8 +10,8 @@
import java.lang.annotation.Target;

@Retention(SOURCE)
@Target({RECORD_COMPONENT, PARAMETER})
public @interface DefaultInit {
@Target({RECORD_COMPONENT})
public @interface DefaultValue {

/** Specify how the default value should be initialized */
String value();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.avaje.recordbuilder.test;

import io.avaje.recordbuilder.DefaultValue;
import io.avaje.recordbuilder.RecordBuilder;
import io.avaje.recordbuilder.test.Raven.Weapon;

@RecordBuilder
public record Raven(
Expand All @@ -10,9 +12,10 @@ public record Raven(
//@DefaultInit("new Raven.Weapon(0, \"Pilebunker\", DamageType.EXPLOSIVE)")
Weapon lArm,
Weapon rShoulder,
@DefaultValue("new Raven.Weapon(0, \"Pilebunker\", DamageType.EXPLOSIVE)")
Weapon lShoulder) {

@RecordBuilder // @DefaultInit("5_000")
@RecordBuilder // @DefaultValue("5_000")
public record Weapon(int cost, String name, DamageType type) {
}
}
4 changes: 0 additions & 4 deletions blackbox-test-records/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import io.avaje.recordbuilder.DefaultInit;
import io.avaje.recordbuilder.test.DamageType;

//@DefaultInit.Global(type = DamageType.class, value="DamageType.ENERGY")
module io.avaje.spi.blackbox {
requires io.avaje.record;
requires io.avaje.validation.contraints;
Expand Down