Consistent instanceof/casting of Class references

This commit is contained in:
Juergen Hoeller 2016-10-30 21:40:27 +01:00
parent 7627c38695
commit ac80ac6f8b
13 changed files with 35 additions and 39 deletions

View File

@ -458,7 +458,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
private GroovyBeanDefinitionWrapper invokeBeanDefiningMethod(String beanName, Object[] args) {
boolean hasClosureArgument = args[args.length - 1] instanceof Closure;
if (args[0] instanceof Class) {
Class<?> beanClass = (args[0] instanceof Class ? (Class) args[0] : args[0].getClass());
Class<?> beanClass = (args[0] instanceof Class ? (Class<?>) args[0] : args[0].getClass());
if (args.length >= 1) {
if (hasClosureArgument) {
if (args.length-1 != 1) {

View File

@ -37,15 +37,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.Aware;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.parsing.Location;
import org.springframework.beans.factory.parsing.Problem;
import org.springframework.beans.factory.parsing.ProblemReporter;
@ -53,8 +48,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
import org.springframework.core.NestedIOException;
import org.springframework.core.annotation.AnnotationAttributes;
@ -724,7 +717,7 @@ class ConfigurationClassParser {
public SourceClass(Object source) {
this.source = source;
if (source instanceof Class<?>) {
if (source instanceof Class) {
this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
}
else {
@ -737,7 +730,7 @@ class ConfigurationClassParser {
}
public Class<?> loadClass() throws ClassNotFoundException {
if (this.source instanceof Class<?>) {
if (this.source instanceof Class) {
return (Class<?>) this.source;
}
String className = ((MetadataReader) this.source).getClassMetadata().getClassName();
@ -752,7 +745,7 @@ class ConfigurationClassParser {
}
public ConfigurationClass asConfigClass(ConfigurationClass importedBy) throws IOException {
if (this.source instanceof Class<?>) {
if (this.source instanceof Class) {
return new ConfigurationClass((Class<?>) this.source, importedBy);
}
return new ConfigurationClass((MetadataReader) this.source, importedBy);
@ -760,7 +753,7 @@ class ConfigurationClassParser {
public Collection<SourceClass> getMemberClasses() throws IOException {
Object sourceToProcess = this.source;
if (sourceToProcess instanceof Class<?>) {
if (sourceToProcess instanceof Class) {
Class<?> sourceClass = (Class<?>) sourceToProcess;
try {
Class<?>[] declaredClasses = sourceClass.getDeclaredClasses();
@ -797,7 +790,7 @@ class ConfigurationClassParser {
}
public SourceClass getSuperClass() throws IOException {
if (this.source instanceof Class<?>) {
if (this.source instanceof Class) {
return asSourceClass(((Class<?>) this.source).getSuperclass());
}
return asSourceClass(((MetadataReader) this.source).getClassMetadata().getSuperClassName());
@ -805,7 +798,7 @@ class ConfigurationClassParser {
public Set<SourceClass> getInterfaces() throws IOException {
Set<SourceClass> result = new LinkedHashSet<>();
if (this.source instanceof Class<?>) {
if (this.source instanceof Class) {
Class<?> sourceClass = (Class<?>) this.source;
for (Class<?> ifcClass : sourceClass.getInterfaces()) {
result.add(asSourceClass(ifcClass));
@ -847,7 +840,7 @@ class ConfigurationClassParser {
}
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class<?>) {
if (this.source instanceof Class) {
try {
Class<?> clazz = ((Class<?>) this.source).getClassLoader().loadClass(className);
return asSourceClass(clazz);

View File

@ -1078,10 +1078,10 @@ public abstract class AnnotationUtils {
boolean nestedAnnotationsAsMap) {
if (classValuesAsString) {
if (value instanceof Class<?>) {
if (value instanceof Class) {
return ((Class<?>) value).getName();
}
else if (value instanceof Class<?>[]) {
else if (value instanceof Class[]) {
Class<?>[] clazzArray = (Class<?>[]) value;
String[] classNames = new String[clazzArray.length];
for (int i = 0; i < clazzArray.length; i++) {

View File

@ -80,10 +80,10 @@ abstract class AnnotationReadingVisitorUtils {
value = convArray;
}
else if (classValuesAsString) {
if (value instanceof Class<?>) {
if (value instanceof Class) {
value = ((Class<?>) value).getName();
}
else if (value instanceof Class<?>[]) {
else if (value instanceof Class[]) {
Class<?>[] clazzArray = (Class<?>[]) value;
String[] newValue = new String[clazzArray.length];
for (int i = 0; i < clazzArray.length; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -48,11 +48,11 @@ public abstract class TypeUtils {
return true;
}
if (lhsType instanceof Class<?>) {
if (lhsType instanceof Class) {
Class<?> lhsClass = (Class<?>) lhsType;
// just comparing two classes
if (rhsType instanceof Class<?>) {
if (rhsType instanceof Class) {
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsType);
}
@ -60,7 +60,7 @@ public abstract class TypeUtils {
Type rhsRaw = ((ParameterizedType) rhsType).getRawType();
// a parameterized type is always assignable to its raw class type
if (rhsRaw instanceof Class<?>) {
if (rhsRaw instanceof Class) {
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsRaw);
}
}
@ -73,10 +73,10 @@ public abstract class TypeUtils {
// parameterized types are only assignable to other parameterized types and class types
if (lhsType instanceof ParameterizedType) {
if (rhsType instanceof Class<?>) {
if (rhsType instanceof Class) {
Type lhsRaw = ((ParameterizedType) lhsType).getRawType();
if (lhsRaw instanceof Class<?>) {
if (lhsRaw instanceof Class) {
return ClassUtils.isAssignable((Class<?>) lhsRaw, (Class<?>) rhsType);
}
}
@ -88,7 +88,7 @@ public abstract class TypeUtils {
if (lhsType instanceof GenericArrayType) {
Type lhsComponent = ((GenericArrayType) lhsType).getGenericComponentType();
if (rhsType instanceof Class<?>) {
if (rhsType instanceof Class) {
Class<?> rhsClass = (Class<?>) rhsType;
if (rhsClass.isArray()) {

View File

@ -59,7 +59,7 @@ public class OperatorInstanceof extends Operator {
Object leftValue = left.getValue();
Object rightValue = right.getValue();
BooleanTypedValue result = null;
if (rightValue == null || !(rightValue instanceof Class<?>)) {
if (rightValue == null || !(rightValue instanceof Class)) {
throw new SpelEvaluationException(getRightOperand().getStartPosition(),
SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND,
(rightValue == null ? "null" : rightValue.getClass().getName()));

View File

@ -1464,12 +1464,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return System.identityHashCode(proxy);
}
else if (method.getName().equals("unwrap")) {
if (((Class) args[0]).isInstance(proxy)) {
if (((Class<?>) args[0]).isInstance(proxy)) {
return proxy;
}
}
else if (method.getName().equals("isWrapperFor")) {
if (((Class) args[0]).isInstance(proxy)) {
if (((Class<?>) args[0]).isInstance(proxy)) {
return true;
}
}

View File

@ -472,7 +472,7 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
return extractViewClass((JsonView) conversionHint, conversionHint);
}
else if (conversionHint instanceof Class) {
return (Class) conversionHint;
return (Class<?>) conversionHint;
}
else {
return null;

View File

@ -50,7 +50,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
private static final Mono<Object[]> NO_ARGS = Mono.just(new Object[0]);
private final static Object NO_VALUE = new Object();
private static final Object NO_VALUE = new Object();
private List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
@ -101,8 +101,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
return Mono.error(ex.getTargetException());
}
catch (Throwable ex) {
String s = getInvocationErrorMessage(args);
return Mono.error(new IllegalStateException(s));
String msg = getInvocationErrorMessage(args);
return Mono.error(new IllegalStateException(msg));
}
});
}

View File

@ -198,7 +198,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
*/
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class<?> ?
RequestCondition<?> condition = (element instanceof Class ?
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
}

View File

@ -171,7 +171,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
}
Class<?> contextClass = (param != null ? param.getContainingClass() : null);
Class<T> targetClass = (targetType instanceof Class<?> ? (Class<T>) targetType : null);
Class<T> targetClass = (targetType instanceof Class ? (Class<T>) targetType : null);
if (targetClass == null) {
ResolvableType resolvableType = (param != null ?
ResolvableType.forMethodParameter(param) : ResolvableType.forType(targetType));

View File

@ -203,7 +203,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
*/
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class<?> ?
RequestCondition<?> condition = (element instanceof Class ?
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
}

View File

@ -51,6 +51,7 @@ import org.springframework.web.util.NestedServletException;
* a method argument that provides access to the response stream.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.1
*/
public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
@ -81,6 +82,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
initResponseStatus();
}
private void initResponseStatus() {
ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class);
if (annotation == null) {
@ -92,7 +94,6 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
}
}
/**
* Register {@link HandlerMethodReturnValueHandler} instances to use to
* handle return values.
@ -101,8 +102,9 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
this.returnValueHandlers = returnValueHandlers;
}
/**
* Invokes the method and handles the return value through one of the
* Invoke the method and handle the return value through one of the
* configured {@link HandlerMethodReturnValueHandler}s.
* @param webRequest the current request
* @param mavContainer the ModelAndViewContainer for this request
@ -151,7 +153,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
else {
webRequest.getResponse().setStatus(this.responseStatus.value());
}
// to be picked up by the RedirectView
// To be picked up by RedirectView
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, this.responseStatus);
}
@ -214,6 +216,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
return result;
}
}, CALLABLE_METHOD);
setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers);
this.returnType = returnType;
}