Introduce ClassUtils.isInnerClass() utility method
This commit is contained in:
parent
b165475eb6
commit
7c28152c13
|
@ -22,7 +22,6 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Executable;
|
import java.lang.reflect.Executable;
|
||||||
import java.lang.reflect.Member;
|
import java.lang.reflect.Member;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -38,6 +37,7 @@ import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
|
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
|
||||||
|
@ -519,8 +519,7 @@ public class MethodParameter {
|
||||||
Annotation[][] annotationArray = this.executable.getParameterAnnotations();
|
Annotation[][] annotationArray = this.executable.getParameterAnnotations();
|
||||||
int index = this.parameterIndex;
|
int index = this.parameterIndex;
|
||||||
if (this.executable instanceof Constructor &&
|
if (this.executable instanceof Constructor &&
|
||||||
this.executable.getDeclaringClass().isMemberClass() &&
|
ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
|
||||||
!Modifier.isStatic(this.executable.getDeclaringClass().getModifiers()) &&
|
|
||||||
annotationArray.length == this.executable.getParameterCount() - 1) {
|
annotationArray.length == this.executable.getParameterCount() - 1) {
|
||||||
// Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
|
// Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
|
||||||
// for inner classes, so access it with the actual parameter index lowered by 1
|
// for inner classes, so access it with the actual parameter index lowered by 1
|
||||||
|
|
|
@ -209,6 +209,14 @@ public abstract class ClassUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the supplied class is an <em>inner class</em>.
|
||||||
|
* @return {@code true} if the supplied class is an inner class
|
||||||
|
*/
|
||||||
|
public static boolean isInnerClass(Class<?> clazz) {
|
||||||
|
return clazz != null && clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacement for {@code Class.forName()} that also returns Class instances
|
* Replacement for {@code Class.forName()} that also returns Class instances
|
||||||
* for primitives (e.g. "int") and array class names (e.g. "String[]").
|
* for primitives (e.g. "int") and array class names (e.g. "String[]").
|
||||||
|
|
Loading…
Reference in New Issue