Nullability refinements and related polishing
This commit is contained in:
parent
223074295d
commit
4612544505
|
|
@ -300,6 +300,16 @@ public class MethodParameter {
|
||||||
return this.nestingLevel;
|
return this.nestingLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a variant of this {@code MethodParameter} with the type
|
||||||
|
* for the current level set to the specified value.
|
||||||
|
* @param typeIndex the new type index
|
||||||
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
public MethodParameter withTypeIndex(int typeIndex) {
|
||||||
|
return nested(this.nestingLevel, typeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the type index for the current nesting level.
|
* Set the type index for the current nesting level.
|
||||||
* @param typeIndex the corresponding type index
|
* @param typeIndex the corresponding type index
|
||||||
|
|
@ -312,15 +322,6 @@ public class MethodParameter {
|
||||||
getTypeIndexesPerLevel().put(this.nestingLevel, typeIndex);
|
getTypeIndexesPerLevel().put(this.nestingLevel, typeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a variant of this {@code MethodParameter} with the type for the current
|
|
||||||
* level set to the specified value.
|
|
||||||
* @param typeIndex the new type index
|
|
||||||
*/
|
|
||||||
public MethodParameter withTypeIndex(int typeIndex) {
|
|
||||||
return nested(this.nestingLevel, typeIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type index for the current nesting level.
|
* Return the type index for the current nesting level.
|
||||||
* @return the corresponding type index, or {@code null}
|
* @return the corresponding type index, or {@code null}
|
||||||
|
|
@ -435,22 +436,39 @@ public class MethodParameter {
|
||||||
return (getParameterType() == Optional.class ? nested() : this);
|
return (getParameterType() == Optional.class ? nested() : this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getContainingClass() {
|
/**
|
||||||
Class<?> containingClass = this.containingClass;
|
* Return a variant of this {@code MethodParameter} which refers to the
|
||||||
return (containingClass != null ? containingClass : getDeclaringClass());
|
* given containing class.
|
||||||
|
* @param containingClass a specific containing class (potentially a
|
||||||
|
* subclass of the declaring class, e.g. substituting a type variable)
|
||||||
|
* @since 5.2
|
||||||
|
* @see #getParameterType()
|
||||||
|
*/
|
||||||
|
public MethodParameter withContainingClass(@Nullable Class<?> containingClass) {
|
||||||
|
MethodParameter result = clone();
|
||||||
|
result.containingClass = containingClass;
|
||||||
|
result.parameterType = null;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a containing class to resolve the parameter type against.
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
void setContainingClass(Class<?> containingClass) {
|
void setContainingClass(Class<?> containingClass) {
|
||||||
this.containingClass = containingClass;
|
this.containingClass = containingClass;
|
||||||
this.parameterType = null;
|
this.parameterType = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodParameter withContainingClass(@Nullable Class<?> containingClass) {
|
/**
|
||||||
MethodParameter result = clone();
|
* Return the containing class for this method parameter.
|
||||||
result.containingClass = containingClass;
|
* @return a specific containing class (potentially a subclass of the
|
||||||
result.parameterType = null;
|
* declaring class), or otherwise simply the declaring class itself
|
||||||
return result;
|
* @see #getDeclaringClass()
|
||||||
|
*/
|
||||||
|
public Class<?> getContainingClass() {
|
||||||
|
Class<?> containingClass = this.containingClass;
|
||||||
|
return (containingClass != null ? containingClass : getDeclaringClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -470,7 +488,7 @@ public class MethodParameter {
|
||||||
if (paramType != null) {
|
if (paramType != null) {
|
||||||
return paramType;
|
return paramType;
|
||||||
}
|
}
|
||||||
if (getContainingClass() != null) {
|
if (this.containingClass != null) {
|
||||||
paramType = ResolvableType.forMethodParameter(this, null, 1, null).resolve();
|
paramType = ResolvableType.forMethodParameter(this, null, 1, null).resolve();
|
||||||
}
|
}
|
||||||
if (paramType == null) {
|
if (paramType == null) {
|
||||||
|
|
|
||||||
|
|
@ -189,20 +189,18 @@ abstract class AnnotationsScanner {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static <C, R> R processClassHierarchy(C context, Class<?> source,
|
private static <C, R> R processClassHierarchy(C context, Class<?> source,
|
||||||
AnnotationsProcessor<C, R> processor,
|
AnnotationsProcessor<C, R> processor, @Nullable BiPredicate<C, Class<?>> classFilter,
|
||||||
@Nullable BiPredicate<C, Class<?>> classFilter, boolean includeInterfaces,
|
boolean includeInterfaces, boolean includeEnclosing) {
|
||||||
boolean includeEnclosing) {
|
|
||||||
|
|
||||||
int[] aggregateIndex = new int[] { 0 };
|
int[] aggregateIndex = new int[] {0};
|
||||||
return processClassHierarchy(context, aggregateIndex, source, processor,
|
return processClassHierarchy(context, aggregateIndex, source, processor,
|
||||||
classFilter, includeInterfaces, includeEnclosing);
|
classFilter, includeInterfaces, includeEnclosing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static <C, R> R processClassHierarchy(C context, int[] aggregateIndex,
|
private static <C, R> R processClassHierarchy(C context, int[] aggregateIndex, Class<?> source,
|
||||||
Class<?> source, AnnotationsProcessor<C, R> processor,
|
AnnotationsProcessor<C, R> processor, @Nullable BiPredicate<C, Class<?>> classFilter,
|
||||||
@Nullable BiPredicate<C, Class<?>> classFilter, boolean includeInterfaces,
|
boolean includeInterfaces, boolean includeEnclosing) {
|
||||||
boolean includeEnclosing) {
|
|
||||||
|
|
||||||
R result = processor.doWithAggregate(context, aggregateIndex[0]);
|
R result = processor.doWithAggregate(context, aggregateIndex[0]);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -229,8 +227,7 @@ abstract class AnnotationsScanner {
|
||||||
Class<?> superclass = source.getSuperclass();
|
Class<?> superclass = source.getSuperclass();
|
||||||
if (superclass != Object.class && superclass != null) {
|
if (superclass != Object.class && superclass != null) {
|
||||||
R superclassResult = processClassHierarchy(context, aggregateIndex,
|
R superclassResult = processClassHierarchy(context, aggregateIndex,
|
||||||
superclass, processor, classFilter, includeInterfaces,
|
superclass, processor, classFilter, includeInterfaces, includeEnclosing);
|
||||||
includeEnclosing);
|
|
||||||
if (superclassResult != null) {
|
if (superclassResult != null) {
|
||||||
return superclassResult;
|
return superclassResult;
|
||||||
}
|
}
|
||||||
|
|
@ -238,8 +235,7 @@ abstract class AnnotationsScanner {
|
||||||
Class<?> enclosingClass = source.getEnclosingClass();
|
Class<?> enclosingClass = source.getEnclosingClass();
|
||||||
if (includeEnclosing && enclosingClass != null) {
|
if (includeEnclosing && enclosingClass != null) {
|
||||||
R enclosingResult = processClassHierarchy(context, aggregateIndex,
|
R enclosingResult = processClassHierarchy(context, aggregateIndex,
|
||||||
enclosingClass, processor, classFilter, includeInterfaces,
|
enclosingClass, processor, classFilter, includeInterfaces, true);
|
||||||
includeEnclosing);
|
|
||||||
if (enclosingResult != null) {
|
if (enclosingResult != null) {
|
||||||
return enclosingResult;
|
return enclosingResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue