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 @@ -41,6 +41,28 @@
/** Extractor for field annotations, converting them from Java model elements to DTOs. */
public final class FieldAnnotationExtractor {

/**
* List of predicates that determine which annotations should be skipped (not copied to the
* builder). Each predicate receives the fully qualified annotation name and returns true if the
* annotation should be filtered out.
*
* <p>To add a new filter, simply add a new predicate to this list with a descriptive comment.
*/
private static final java.util.List<java.util.function.Predicate<String>> ANNOTATION_FILTERS =
java.util.List.of(
// Skip SimpleBuilder framework annotations
name -> name.startsWith("org.javahelpers.simple.builders."),
// Skip code generation metadata annotations
name -> name.equals("javax.annotation.Generated"),
name -> name.equals("javax.annotation.processing.Generated"),
// Skip compiler-only annotations not relevant for builder parameters
name -> name.equals("java.lang.SuppressWarnings"),
// Skip @Valid annotation for cascading validation (jakarta.validation.Valid /
// javax.validation.Valid) - only meaningful on fields or method return types, not on
// builder method parameters where individual values are set
name -> name.equals("jakarta.validation.Valid"),
name -> name.equals("javax.validation.Valid"));

private FieldAnnotationExtractor() {
// Private constructor to prevent instantiation
}
Expand Down Expand Up @@ -192,17 +214,7 @@ private static String formatArray(List<?> list) {
* @return true if the annotation should be skipped, false otherwise
*/
private static boolean shouldSkipAnnotation(String qualifiedName) {
// Skip SimpleBuilder framework annotations
if (qualifiedName.startsWith("org.javahelpers.simple.builders.")) {
return true;
}
// Skip generated code annotations (these are for code generation metadata, not validation)
if (qualifiedName.equals("javax.annotation.Generated")
|| qualifiedName.equals("javax.annotation.processing.Generated")) {
return true;
}
// Skip compiler-only annotations that are not relevant for builder parameters
return qualifiedName.equals("java.lang.SuppressWarnings");
return ANNOTATION_FILTERS.stream().anyMatch(filter -> filter.test(qualifiedName));
}

/**
Expand Down
Loading
Loading