Merge branch '5.3.x'
This commit is contained in:
commit
11de64d609
|
@ -24,12 +24,8 @@ package org.springframework.core.annotation
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
public annotation class Filter(
|
public annotation class Filter(
|
||||||
|
|
||||||
@get:AliasFor("name")
|
|
||||||
val value: String = "",
|
val value: String = "",
|
||||||
|
|
||||||
@get:AliasFor("value")
|
|
||||||
val name: String = "",
|
|
||||||
|
|
||||||
val and: Filters = Filters()
|
val and: Filters = Filters()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -41,6 +41,34 @@ class KotlinMergedAnnotationsTests {
|
||||||
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Person::class.java))
|
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Person::class.java))
|
||||||
assertThat(mergedAnnotation).isNotNull();
|
assertThat(mergedAnnotation).isNotNull();
|
||||||
|
|
||||||
|
// NON-Synthesized Annotations
|
||||||
|
val jane = mergedAnnotation.synthesize()
|
||||||
|
assertThat(jane).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(jane.name).isEqualTo("jane")
|
||||||
|
val synthesizedFriends = jane.friends
|
||||||
|
assertThat(synthesizedFriends).hasSize(2)
|
||||||
|
|
||||||
|
val john = synthesizedFriends[0]
|
||||||
|
assertThat(john).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(john.name).isEqualTo("john")
|
||||||
|
|
||||||
|
val sally = synthesizedFriends[1]
|
||||||
|
assertThat(sally).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(sally.name).isEqualTo("sally")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // gh-28012
|
||||||
|
fun recursiveAnnotationWithAttributeAliases() {
|
||||||
|
val method = javaClass.getMethod("synthesizablePersonMethod")
|
||||||
|
|
||||||
|
// MergedAnnotations
|
||||||
|
val mergedAnnotations = MergedAnnotations.from(method)
|
||||||
|
assertThat(mergedAnnotations.isPresent(SynthesizablePerson::class.java)).isTrue();
|
||||||
|
|
||||||
|
// MergedAnnotation
|
||||||
|
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(SynthesizablePerson::class.java))
|
||||||
|
assertThat(mergedAnnotation).isNotNull();
|
||||||
|
|
||||||
// Synthesized Annotations
|
// Synthesized Annotations
|
||||||
val jane = mergedAnnotation.synthesize()
|
val jane = mergedAnnotation.synthesize()
|
||||||
assertThat(jane).isInstanceOf(SynthesizedAnnotation::class.java)
|
assertThat(jane).isInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
@ -72,6 +100,36 @@ class KotlinMergedAnnotationsTests {
|
||||||
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Filter::class.java))
|
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Filter::class.java))
|
||||||
assertThat(mergedAnnotation).isNotNull();
|
assertThat(mergedAnnotation).isNotNull();
|
||||||
|
|
||||||
|
// NON-Synthesized Annotations
|
||||||
|
val fooFilter = mergedAnnotation.synthesize()
|
||||||
|
assertThat(fooFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(fooFilter.value).isEqualTo("foo")
|
||||||
|
val filters = fooFilter.and
|
||||||
|
assertThat(filters.value).hasSize(2)
|
||||||
|
|
||||||
|
val barFilter = filters.value[0]
|
||||||
|
assertThat(barFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(barFilter.value).isEqualTo("bar")
|
||||||
|
assertThat(barFilter.and.value).isEmpty()
|
||||||
|
|
||||||
|
val bazFilter = filters.value[1]
|
||||||
|
assertThat(bazFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
assertThat(bazFilter.value).isEqualTo("baz")
|
||||||
|
assertThat(bazFilter.and.value).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // gh-28012
|
||||||
|
fun recursiveNestedAnnotationWithAttributeAliases() {
|
||||||
|
val method = javaClass.getMethod("synthesizableFilterMethod")
|
||||||
|
|
||||||
|
// MergedAnnotations
|
||||||
|
val mergedAnnotations = MergedAnnotations.from(method)
|
||||||
|
assertThat(mergedAnnotations.isPresent(SynthesizableFilter::class.java)).isTrue();
|
||||||
|
|
||||||
|
// MergedAnnotation
|
||||||
|
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(SynthesizableFilter::class.java))
|
||||||
|
assertThat(mergedAnnotation).isNotNull();
|
||||||
|
|
||||||
// Synthesized Annotations
|
// Synthesized Annotations
|
||||||
val fooFilter = mergedAnnotation.synthesize()
|
val fooFilter = mergedAnnotation.synthesize()
|
||||||
assertThat(fooFilter).isInstanceOf(SynthesizedAnnotation::class.java)
|
assertThat(fooFilter).isInstanceOf(SynthesizedAnnotation::class.java)
|
||||||
|
@ -94,12 +152,20 @@ class KotlinMergedAnnotationsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Person("jane", friends = [Person("john"), Person("sally")])
|
@Person(name = "jane", friends = [Person(name = "john"), Person(name = "sally")])
|
||||||
fun personMethod() {
|
fun personMethod() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SynthesizablePerson(name = "jane", friends = [SynthesizablePerson(name = "john"), SynthesizablePerson(name = "sally")])
|
||||||
|
fun synthesizablePersonMethod() {
|
||||||
|
}
|
||||||
|
|
||||||
@Filter("foo", and = Filters(Filter("bar"), Filter("baz")))
|
@Filter("foo", and = Filters(Filter("bar"), Filter("baz")))
|
||||||
fun filterMethod() {
|
fun filterMethod() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SynthesizableFilter("foo", and = SynthesizableFilters(SynthesizableFilter("bar"), SynthesizableFilter("baz")))
|
||||||
|
fun synthesizableFilterMethod() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@ package org.springframework.core.annotation
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
public annotation class Person(
|
public annotation class Person(
|
||||||
|
|
||||||
@get:AliasFor("name")
|
|
||||||
val value: String = "",
|
|
||||||
|
|
||||||
@get:AliasFor("value")
|
|
||||||
val name: String = "",
|
val name: String = "",
|
||||||
|
|
||||||
vararg val friends: Person = []
|
vararg val friends: Person = []
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.core.annotation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @since 5.3.16
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
public annotation class SynthesizableFilter(
|
||||||
|
|
||||||
|
@get:AliasFor("name")
|
||||||
|
val value: String = "",
|
||||||
|
|
||||||
|
@get:AliasFor("value")
|
||||||
|
val name: String = "",
|
||||||
|
|
||||||
|
val and: SynthesizableFilters = SynthesizableFilters()
|
||||||
|
|
||||||
|
)
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.core.annotation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @since 5.3.16
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
public annotation class SynthesizableFilters(
|
||||||
|
|
||||||
|
vararg val value: SynthesizableFilter
|
||||||
|
|
||||||
|
)
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.core.annotation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @since 5.3.16
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
public annotation class SynthesizablePerson(
|
||||||
|
|
||||||
|
@get:AliasFor("name")
|
||||||
|
val value: String = "",
|
||||||
|
|
||||||
|
@get:AliasFor("value")
|
||||||
|
val name: String = "",
|
||||||
|
|
||||||
|
vararg val friends: SynthesizablePerson = []
|
||||||
|
|
||||||
|
)
|
Loading…
Reference in New Issue