Introduce 'value' alias for 'attribute' in @AliasFor

SPR-11512 introduced support for annotation attribute aliases via
@AliasFor, requiring the explicit declaration of the 'attribute'
attribute. However, for aliases within an annotation, this explicit
declaration is unnecessary.

This commit improves the readability of alias pairs declared within an
annotation by introducing a 'value' attribute in @AliasFor that is an
alias for the existing 'attribute' attribute. This allows annotations
such as @ContextConfiguration from the spring-test module to declare
aliases as follows.

public @interface ContextConfiguration {

     @AliasFor("locations")
     String[] value() default {};

     @AliasFor("value")
     String[] locations() default {};

    // ...
}

Issue: SPR-13289
This commit is contained in:
Sam Brannen
2015-07-29 15:27:06 +02:00
parent 90493f49e6
commit 725292081e
35 changed files with 170 additions and 84 deletions

View File

@@ -68,7 +68,7 @@ public @interface ControllerAdvice {
* @since 4.0
* @see #basePackages()
*/
@AliasFor(attribute = "basePackages")
@AliasFor("basePackages")
String[] value() default {};
/**
@@ -82,7 +82,7 @@ public @interface ControllerAdvice {
* alternative to String-based package names.
* @since 4.0
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String[] basePackages() default {};
/**

View File

@@ -51,14 +51,14 @@ public @interface CookieValue {
/**
* Alias for {@link #name}.
*/
@AliasFor(attribute = "name")
@AliasFor("name")
String value() default "";
/**
* The name of the cookie to bind to.
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String name() default "";
/**

View File

@@ -51,7 +51,7 @@ public @interface CrossOrigin {
/**
* Alias for {@link #origins}.
*/
@AliasFor(attribute = "origins")
@AliasFor("origins")
String[] value() default {};
/**
@@ -62,7 +62,7 @@ public @interface CrossOrigin {
* <p>If undefined, all origins are allowed.
* @see #value
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String[] origins() default {};
/**

View File

@@ -50,7 +50,7 @@ public @interface MatrixVariable {
/**
* Alias for {@link #name}.
*/
@AliasFor(attribute = "name")
@AliasFor("name")
String value() default "";
/**
@@ -58,7 +58,7 @@ public @interface MatrixVariable {
* @since 4.2
* @see #value
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String name() default "";
/**

View File

@@ -51,14 +51,14 @@ public @interface RequestHeader {
/**
* Alias for {@link #name}.
*/
@AliasFor(attribute = "name")
@AliasFor("name")
String value() default "";
/**
* The name of the request header to bind to.
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String name() default "";
/**

View File

@@ -309,7 +309,7 @@ public @interface RequestMapping {
* When used at the type level, all method-level mappings inherit
* this primary mapping, narrowing it for a specific handler method.
*/
@AliasFor(attribute = "path")
@AliasFor("path")
String[] value() default {};
/**
@@ -324,7 +324,7 @@ public @interface RequestMapping {
* @see org.springframework.web.bind.annotation.ValueConstants#DEFAULT_NONE
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String[] path() default {};
/**

View File

@@ -59,14 +59,14 @@ public @interface RequestParam {
/**
* Alias for {@link #name}.
*/
@AliasFor(attribute = "name")
@AliasFor("name")
String value() default "";
/**
* The name of the request parameter to bind to.
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String name() default "";
/**

View File

@@ -67,14 +67,14 @@ public @interface RequestPart {
/**
* Alias for {@link #name}.
*/
@AliasFor(attribute = "name")
@AliasFor("name")
String value() default "";
/**
* The name of the part in the {@code "multipart/form-data"} request to bind to.
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String name() default "";
/**

View File

@@ -45,7 +45,7 @@ public @interface ResponseStatus {
/**
* Alias for {@link #code}.
*/
@AliasFor(attribute = "code")
@AliasFor("code")
HttpStatus value() default HttpStatus.INTERNAL_SERVER_ERROR;
/**
@@ -55,7 +55,7 @@ public @interface ResponseStatus {
* @since 4.2
* @see javax.servlet.http.HttpServletResponse#setStatus(int)
*/
@AliasFor(attribute = "value")
@AliasFor("value")
HttpStatus code() default HttpStatus.INTERNAL_SERVER_ERROR;
/**

View File

@@ -64,7 +64,7 @@ public @interface SessionAttributes {
/**
* Alias for {@link #names}.
*/
@AliasFor(attribute = "names")
@AliasFor("names")
String[] value() default {};
/**
@@ -76,7 +76,7 @@ public @interface SessionAttributes {
* names but rather operate on the model only.
* @since 4.2
*/
@AliasFor(attribute = "value")
@AliasFor("value")
String[] names() default {};
/**