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

Fix Duplicate Lombok adapter generation #260

Merged
merged 4 commits into from
Sep 22, 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 @@ -129,7 +129,11 @@ int genericTypeParamsCount() {

private boolean includeField(Element element) {
return !element.getModifiers().contains(Modifier.TRANSIENT)
&& (!element.getAnnotationMirrors().isEmpty() || element.asType().toString().contains("@"));
&& (element.getAnnotationMirrors().stream()
//filter lombok's suppress warnings and generated annotations
.filter(m -> !m.toString().contains("@java"))
.anyMatch(m -> !m.toString().contains("lombok"))
|| element.asType().toString().contains("@"));
}

private void readMethod(Element element, TypeElement type, List<FieldReader> localFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

/** Builds and caches the ValidationAdapter adapters for DValidator. */
final class CoreAdapterBuilder {
@SuppressWarnings("rawtypes")
public static final ValidationAdapter NOOP = (type, req, propertyName) -> true;

private static final Set<Class<?>> DEFAULT_GROUP = Set.of(Default.class);
private final DValidator context;
Expand Down Expand Up @@ -106,7 +104,7 @@ <T> ValidationAdapter<T> buildAnnotation(
}
}
// unknown annotations have noop
return NOOP;
return NoOpValidator.INSTANCE;
}

record Request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public <T> ValidationAdapter<T> adapter(Type type) {
@Override
@SuppressWarnings("unchecked")
public <T> ValidationAdapter<T> noop() {
return CoreAdapterBuilder.NOOP;
return NoOpValidator.INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.avaje.validation.core;

import io.avaje.validation.adapter.ValidationAdapter;
import io.avaje.validation.adapter.ValidationRequest;

final class NoOpValidator implements ValidationAdapter, ValidationAdapter.Primitive {

static final NoOpValidator INSTANCE = new NoOpValidator();

@Override
public boolean validate(Object value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public Primitive primitive() {
return this;
}

@Override
public boolean validate(boolean value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(byte value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(char value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(double value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(float value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(int value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(long value, ValidationRequest req, String propertyName) {
return true;
}

@Override
public boolean validate(short value, ValidationRequest req, String propertyName) {
return true;
}
}
Loading