From 205dd263e23c13db753b64c79fecf69644809938 Mon Sep 17 00:00:00 2001 From: stCarolas Date: Mon, 6 Nov 2023 15:22:19 +0100 Subject: [PATCH] ignore some annotations when copying to generated constructor method --- .../enrichedbeans/annotations/Enrich.java | 2 +- .../assistedinject/AssistedBean.java | 15 +++++++++++++-- .../assistedinject/AssistingFactoryBean.java | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/annotations/src/main/java/io/github/stcarolas/enrichedbeans/annotations/Enrich.java b/annotations/src/main/java/io/github/stcarolas/enrichedbeans/annotations/Enrich.java index 1fcda43..9e87dbe 100644 --- a/annotations/src/main/java/io/github/stcarolas/enrichedbeans/annotations/Enrich.java +++ b/annotations/src/main/java/io/github/stcarolas/enrichedbeans/annotations/Enrich.java @@ -5,6 +5,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target({ElementType.FIELD}) +@Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.SOURCE) public @interface Enrich {} diff --git a/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistedBean.java b/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistedBean.java index 15785a5..c6bf741 100644 --- a/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistedBean.java +++ b/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistedBean.java @@ -115,7 +115,14 @@ protected String factoryMethodName() { } protected Seq notInjectedFields() { - return fields().reject(shouldBeInjected(assistAllInjectedFields())); + // TODO filter static fields and inited fields + return fields() + .reject(shouldBeInjected(assistAllInjectedFields())) + .map(field -> field.removeAnnotation("com.fasterxml.jackson.annotation", "JsonIgnore")) + .map(field -> field.removeAnnotation("org.springframework.data.annotation","Id")) + .map(field -> field.removeAnnotation("org.springframework.data.annotation","Transient")) + ; + } protected Seq injectedFields() { @@ -142,7 +149,11 @@ protected Seq injectedFields() { Enrich.class.getPackageName(), Enrich.class.getSimpleName() ) - ); + ) + .map(field -> field.removeAnnotation("com.fasterxml.jackson.annotation", "JsonIgnore")) + .map(field -> field.removeAnnotation("org.springframework.data.annotation","Id")) + .map(field -> field.removeAnnotation("org.springframework.data.annotation","Transient")) + ; } private Predicate shouldBeInjected(boolean detectNamedFields) { diff --git a/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistingFactoryBean.java b/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistingFactoryBean.java index eaacc3f..76e1472 100644 --- a/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistingFactoryBean.java +++ b/assisted-inject/src/main/java/io/github/stcarolas/enrichedbeans/assistedinject/AssistingFactoryBean.java @@ -24,6 +24,7 @@ public abstract class AssistingFactoryBean extends GeneratedBean implements With abstract Modifier visibility(); + // todo почему он не тут? abstract Method factoryMethod(); abstract Constructor constructor();