Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No effective change - Format, remove unneeded public modifier for int… #258

Merged
merged 1 commit into from
Aug 31, 2024
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 @@ -16,7 +16,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;

public record ElementAnnotationContainer(
record ElementAnnotationContainer(
UType genericType,
boolean hasValid,
Map<UType, String> annotations,
Expand All @@ -32,97 +32,94 @@ static ElementAnnotationContainer create(Element element) {
UType uType;
if (element instanceof final ExecutableElement executableElement) {
uType = UType.parse(executableElement.getReturnType());

} else {
uType = UType.parse(element.asType());
}

typeUse1 =
Optional.ofNullable(uType.param0()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));
Optional.ofNullable(uType.param0()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));

typeUse2 =
Optional.ofNullable(uType.param1()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));
Optional.ofNullable(uType.param1()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));

final var annotations =
element.getAnnotationMirrors().stream()
.filter(m -> !ValidPrism.isInstance(m))
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.map(
a -> {
if (CrossParamConstraintPrism.isPresent(a.getAnnotationType().asElement())) {
crossParam.put(
UType.parse(a.getAnnotationType()),
AnnotationUtil.annotationAttributeMap(a, element));
return null;
}
return a;
})
.filter(Objects::nonNull)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));
element.getAnnotationMirrors().stream()
.filter(m -> !ValidPrism.isInstance(m))
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.map(a -> {
if (CrossParamConstraintPrism.isPresent(a.getAnnotationType().asElement())) {
crossParam.put(
UType.parse(a.getAnnotationType()),
AnnotationUtil.annotationAttributeMap(a, element));
return null;
}
return a;
})
.filter(Objects::nonNull)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, element)));

if (Util.isNonNullable(element)) {
var nonNull = UType.parse(APContext.typeElement(NonNullPrism.PRISM_TYPE).asType());
annotations.put(nonNull, "Map.of(\"message\",\"{avaje.NotNull.message}\")");
}

return new ElementAnnotationContainer(
uType, hasValid, annotations, typeUse1, typeUse2, crossParam);
return new ElementAnnotationContainer(uType, hasValid, annotations, typeUse1, typeUse2, crossParam);
}

static boolean hasMetaConstraintAnnotation(AnnotationMirror m) {
return hasMetaConstraintAnnotation(m.getAnnotationType().asElement())
|| ValidPrism.isInstance(m);
|| ValidPrism.isInstance(m);
}

static boolean hasMetaConstraintAnnotation(Element element) {
return ConstraintPrism.isPresent(element);
}

// it seems we cannot directly retrieve mirrors from var elements, so var Elements needs special
// handling
// it seems we cannot directly retrieve mirrors from var elements, so var Elements needs special handling

static ElementAnnotationContainer create(VariableElement varElement) {
var uType = UType.parse(varElement.asType());
final var annotations =
uType.annotations().stream()
.filter(m -> !ValidPrism.isInstance(m))
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));
uType.annotations().stream()
.filter(m -> !ValidPrism.isInstance(m))
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));

var typeUse1 =
Optional.ofNullable(uType.param0()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));
Optional.ofNullable(uType.param0()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));

var typeUse2 =
Optional.ofNullable(uType.param1()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));
Optional.ofNullable(uType.param1()).map(UType::annotations).stream()
.flatMap(List::stream)
.filter(ElementAnnotationContainer::hasMetaConstraintAnnotation)
.collect(
toMap(
a -> UType.parse(a.getAnnotationType()),
a -> AnnotationUtil.annotationAttributeMap(a, varElement)));

final boolean hasValid = uType.annotations().stream().anyMatch(ValidPrism::isInstance);

Expand All @@ -131,8 +128,7 @@ static ElementAnnotationContainer create(VariableElement varElement) {
annotations.put(nonNull, "Map.of(\"message\",\"{avaje.NotNull.message}\")");
}

return new ElementAnnotationContainer(
uType, hasValid, annotations, typeUse1, typeUse2, Map.of());
return new ElementAnnotationContainer(uType, hasValid, annotations, typeUse1, typeUse2, Map.of());
}

public void addImports(Set<String> importTypes) {
Expand All @@ -149,14 +145,13 @@ boolean isEmpty() {
boolean supportsPrimitiveValidation() {
for (final var validationAnnotation : annotations.keySet()) {
ConstraintPrism.getOptionalOn(typeElement(validationAnnotation.full()))
.ifPresent(
p -> {
if (p.unboxPrimitives()) {
validationAnnotation
.shortType()
.transform(PrimitiveUtil::addPrimitiveValidationAnnotation);
}
});
.ifPresent(p -> {
if (p.unboxPrimitives()) {
validationAnnotation
.shortType()
.transform(PrimitiveUtil::addPrimitiveValidationAnnotation);
}
});

if (!isPrimitiveValidationAnnotations(validationAnnotation.shortType())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ private static Supplier<Optional<? extends TypeMirror>> validationAdapter(TypeEl
return () -> element.getInterfaces().stream()
.filter(t ->
t.toString().contains("io.avaje.validation.adapter.ValidationAdapter")
|| t.toString()
.contains("io.avaje.validation.adapter.ValidationAdapter.Primitive"))
|| t.toString().contains("io.avaje.validation.adapter.ValidationAdapter.Primitive"))
.findFirst();
}

Expand Down
Loading