Add MergedAnnotation.getRoot() method
Update `MergedAnnotation` with a `getRoot()` method that allows the root direct annotation to be retrieved easily. Closes gh-22818
This commit is contained in:
@@ -140,6 +140,13 @@ public interface MergedAnnotation<A extends Annotation> {
|
||||
@Nullable
|
||||
MergedAnnotation<?> getParent();
|
||||
|
||||
/**
|
||||
* Get the root annotation, i.e. the {@link #getDepth() depth} {@code 0}
|
||||
* annotation as directly declared on the source.
|
||||
* @return the root annotation
|
||||
*/
|
||||
MergedAnnotation<?> getRoot();
|
||||
|
||||
/**
|
||||
* Determine if the specified attribute name has a non-default value when
|
||||
* compared to the annotation declaration.
|
||||
|
||||
@@ -66,6 +66,11 @@ final class MissingMergedAnnotation<A extends Annotation> extends AbstractMerged
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedAnnotation<?> getRoot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return -1;
|
||||
|
||||
@@ -171,6 +171,16 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
|
||||
this.valueExtractor, this.aggregateIndex, this.resolvedRootMirrors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedAnnotation<?> getRoot() {
|
||||
if (getDepth() == 0) {
|
||||
return this;
|
||||
}
|
||||
AnnotationTypeMapping rootMapping = this.mapping.getRoot();
|
||||
return new TypeMappedAnnotation<>(rootMapping, this.source, this.rootAttributes,
|
||||
this.valueExtractor, this.aggregateIndex, this.resolvedRootMirrors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDefaultValue(String attributeName) {
|
||||
int attributeIndex = getAttributeIndex(attributeName, true);
|
||||
|
||||
Reference in New Issue
Block a user