Skip to content

Commit

Permalink
ignore some annotations when copying to generated constructor method
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Nov 6, 2023
1 parent 73c47e3 commit 205dd26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ protected String factoryMethodName() {
}

protected Seq<Variable> 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<Variable> injectedFields() {
Expand All @@ -142,7 +149,11 @@ protected Seq<Variable> 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<Variable> shouldBeInjected(boolean detectNamedFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class AssistingFactoryBean extends GeneratedBean implements With

abstract Modifier visibility();

// todo почему он не тут?
abstract Method factoryMethod();

abstract Constructor constructor();
Expand Down

0 comments on commit 205dd26

Please sign in to comment.