Browse Source

Polishing

pull/23244/head
Juergen Hoeller 7 years ago
parent
commit
c192c14a9f
  1. 10
      spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
  2. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java
  3. 6
      spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java
  4. 20
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
  5. 10
      spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java
  6. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java

10
spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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.
@ -19,6 +19,7 @@ package org.springframework.beans.annotation; @@ -19,6 +19,7 @@ package org.springframework.beans.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ -58,8 +59,11 @@ public abstract class AnnotationBeanUtils { @@ -58,8 +59,11 @@ public abstract class AnnotationBeanUtils {
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver,
String... excludedProperties) {
Set<String> excluded = (excludedProperties.length == 0 ? Collections.<String>emptySet() :
new HashSet<String>(Arrays.asList(excludedProperties)));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
for (Method annotationProperty : annotationProperties) {

2
spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java

@ -278,7 +278,7 @@ abstract class AutowireUtils { @@ -278,7 +278,7 @@ abstract class AutowireUtils {
/**
* Reflective InvocationHandler for lazy access to the current target object.
* Reflective {@link InvocationHandler} for lazy access to the current target object.
*/
@SuppressWarnings("serial")
private static class ObjectFactoryDelegatingInvocationHandler implements InvocationHandler, Serializable {

6
spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -27,6 +27,8 @@ import org.springframework.util.ReflectionUtils; @@ -27,6 +27,8 @@ import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
/**
* Unit tests for {@link AutowireUtils}.
*
* @author Juergen Hoeller
* @author Sam Brannen
*/
@ -36,7 +38,7 @@ public class AutowireUtilsTests { @@ -36,7 +38,7 @@ public class AutowireUtilsTests {
public void genericMethodReturnTypes() {
Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized");
assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[]{}, getClass().getClassLoader()));
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[0], getClass().getClassLoader()));
Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Integer.class, Boolean.class);
assertEquals(String.class,

20
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -51,14 +51,14 @@ import org.springframework.util.StringUtils; @@ -51,14 +51,14 @@ import org.springframework.util.StringUtils;
* <p>Note that most of the features of this class are not provided by the
* JDK's introspection facilities themselves.
*
* <p>As a general rule for runtime-retained annotations (e.g. for transaction
* control, authorization, or service exposure), always use the lookup methods
* on this class (e.g., {@link #findAnnotation(Method, Class)},
* {@link #getAnnotation(Method, Class)}, and {@link #getAnnotations(Method)})
* instead of the plain annotation lookup methods in the JDK. You can still
* explicitly choose between a <em>get</em> lookup on the given class level only
* ({@link #getAnnotation(Method, Class)}) and a <em>find</em> lookup in the entire
* inheritance hierarchy of the given method ({@link #findAnnotation(Method, Class)}).
* <p>As a general rule for runtime-retained application annotations (e.g. for
* transaction control, authorization, or service exposure), always use the
* lookup methods on this class (e.g. {@link #findAnnotation(Method, Class)} or
* {@link #getAnnotation(Method, Class)}) instead of the plain annotation lookup
* methods in the JDK. You can still explicitly choose between a <em>get</em>
* lookup on the given class level only ({@link #getAnnotation(Method, Class)})
* and a <em>find</em> lookup in the entire inheritance hierarchy of the given
* method ({@link #findAnnotation(Method, Class)}).
*
* <h3>Terminology</h3>
* The terms <em>directly present</em>, <em>indirectly present</em>, and
@ -542,7 +542,7 @@ public abstract class AnnotationUtils { @@ -542,7 +542,7 @@ public abstract class AnnotationUtils {
/**
* Find a single {@link Annotation} of {@code annotationType} on the supplied
* {@link Method}, traversing its super methods (i.e., from superclasses and
* {@link Method}, traversing its super methods (i.e. from superclasses and
* interfaces) if the annotation is not <em>directly present</em> on the given
* method itself.
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.

10
spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@ -66,8 +66,9 @@ class HtmlCharacterEntityDecoder { @@ -66,8 +66,9 @@ class HtmlCharacterEntityDecoder {
this.originalMessage.indexOf('&', this.nextPotentialReferencePosition);
if (this.nextSemicolonPosition != -1 &&
this.nextSemicolonPosition < this.nextPotentialReferencePosition)
this.nextSemicolonPosition < this.nextPotentialReferencePosition) {
this.nextSemicolonPosition = this.originalMessage.indexOf(';', this.nextPotentialReferencePosition + 1);
}
boolean isPotentialReference = (this.nextPotentialReferencePosition != -1 &&
this.nextSemicolonPosition != -1 &&
@ -94,12 +95,13 @@ class HtmlCharacterEntityDecoder { @@ -94,12 +95,13 @@ class HtmlCharacterEntityDecoder {
int skipUntilIndex = (this.nextPotentialReferencePosition != -1 ?
this.nextPotentialReferencePosition : this.originalMessage.length());
if (skipUntilIndex - this.currentPosition > 3) {
this.decodedMessage.append(this.originalMessage.substring(this.currentPosition, skipUntilIndex));
this.decodedMessage.append(this.originalMessage, this.currentPosition, skipUntilIndex);
this.currentPosition = skipUntilIndex;
}
else {
while (this.currentPosition < skipUntilIndex)
while (this.currentPosition < skipUntilIndex) {
this.decodedMessage.append(this.originalMessage.charAt(this.currentPosition++));
}
}
}
}

6
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -442,7 +442,7 @@ public abstract class ResponseEntityExceptionHandler { @@ -442,7 +442,7 @@ public abstract class ResponseEntityExceptionHandler {
}
/**
* Customize the response for NoHandlerFoundException.
* Customize the response for AsyncRequestTimeoutException.
* <p>This method delegates to {@link #handleExceptionInternal}.
* @param ex the exception
* @param headers the headers to be written to the response
@ -470,7 +470,7 @@ public abstract class ResponseEntityExceptionHandler { @@ -470,7 +470,7 @@ public abstract class ResponseEntityExceptionHandler {
}
/**
* A single place to customize the response body of all Exception types.
* A single place to customize the response body of all exception types.
* <p>The default implementation sets the {@link WebUtils#ERROR_EXCEPTION_ATTRIBUTE}
* request attribute and creates a {@link ResponseEntity} from the given
* body, headers, and status.

Loading…
Cancel
Save