Skip to content
Closed
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
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-GH-2332-SNAPSHOT</version>

<name>Spring Data Core</name>

Expand Down Expand Up @@ -339,7 +341,7 @@
<version>0.1.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmolecules.integrations</groupId>
<artifactId>jmolecules-spring</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;
Expand Down Expand Up @@ -175,6 +176,7 @@ public static class Parameter<T, P extends PersistentProperty<P>> {

private final @Nullable String name;
private final TypeInformation<T> type;
private final MergedAnnotations annotations;
private final String key;
private final @Nullable PersistentEntity<T, P> entity;

Expand All @@ -199,7 +201,8 @@ public Parameter(@Nullable String name, TypeInformation<T> type, Annotation[] an

this.name = name;
this.type = type;
this.key = getValue(annotations);
this.annotations = MergedAnnotations.from(annotations);
this.key = getValue(this.annotations);
this.entity = entity;

this.enclosingClassCache = Lazy.of(() -> {
Expand All @@ -216,12 +219,12 @@ public Parameter(@Nullable String name, TypeInformation<T> type, Annotation[] an
}

@Nullable
private static String getValue(Annotation[] annotations) {
private static String getValue(MergedAnnotations annotations) {

return Arrays.stream(annotations)//
.filter(it -> it.annotationType() == Value.class)//
.findFirst().map(it -> ((Value) it).value())//
.filter(StringUtils::hasText).orElse(null);
return annotations.get(Value.class) //
.getValue("value", String.class) //
.filter(StringUtils::hasText) //
.orElse(null);
}

/**
Expand All @@ -243,6 +246,16 @@ public TypeInformation<T> getType() {
return type;
}

/**
* Merged annotations that this parameter is annotated with.
*
* @return
* @since 2.5
*/
public MergedAnnotations getAnnotations() {
return annotations;
}

/**
* Returns the raw resolved type of the parameter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

import static org.assertj.core.api.Assertions.*;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Iterator;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.data.mapping.PreferredConstructorDiscovererUnitTests.Outer.Inner;
Expand Down Expand Up @@ -135,6 +141,16 @@ void capturesSuperClassEnclosingTypeParameterOfNonStaticInnerClass() {
});
}

@Test // GH-2332
void detectsMetaAnnotatedValueAnnotation() {

assertThat(PreferredConstructorDiscoverer.discover(ClassWithMetaAnnotatedParameter.class)).satisfies(ctor -> {

assertThat(ctor.getParameters().get(0).getSpelExpression()).isEqualTo("${hello-world}");
assertThat(ctor.getParameters().get(0).getAnnotations()).isNotNull();
});
}

static class SyntheticConstructor {
@PersistenceConstructor
private SyntheticConstructor(String x) {}
Expand Down Expand Up @@ -204,4 +220,18 @@ public NonStaticInnerWithGenericArgUsedInCtor(T value) {
super(value);
}
}

static class ClassWithMetaAnnotatedParameter {

ClassWithMetaAnnotatedParameter(@MyValue String value) {

}
}

@Target({ ElementType.PARAMETER, })
@Retention(RetentionPolicy.RUNTIME)
@Value("${hello-world}")
@interface MyValue {

}
}