polishing
This commit is contained in:
parent
0195b0da3c
commit
4c73a29f99
|
|
@ -50,6 +50,7 @@ public abstract class AnnotationUtils {
|
|||
/** The attribute name for annotations with a single element */
|
||||
static final String VALUE = "value";
|
||||
|
||||
|
||||
/**
|
||||
* Get all {@link Annotation Annotations} from the supplied {@link Method}.
|
||||
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
||||
|
|
@ -135,14 +136,16 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Find a single {@link Annotation} of <code>annotationType</code> from the supplied {@link Class}, traversing its
|
||||
* interfaces and super classes if no annotation can be found on the given class itself. <p>This method explicitly
|
||||
* handles class-level annotations which are not declared as {@link java.lang.annotation.Inherited inherited} <i>as
|
||||
* well as annotations on interfaces</i>. <p>The algorithm operates as follows: Searches for an annotation on the given
|
||||
* class and returns it if found. Else searches all interfaces that the given class declares, returning the annotation
|
||||
* from the first matching candidate, if any. Else proceeds with introspection of the superclass of the given class,
|
||||
* checking the superclass itself; if no annotation found there, proceeds with the interfaces that the superclass
|
||||
* declares. Recursing up through the entire superclass hierarchy if no match is found.
|
||||
* Find a single {@link Annotation} of <code>annotationType</code> from the supplied {@link Class},
|
||||
* traversing its interfaces and super classes if no annotation can be found on the given class itself.
|
||||
* <p>This method explicitly handles class-level annotations which are not declared as
|
||||
* {@link Inherited inherited} <i>as well as annotations on interfaces</i>.
|
||||
* <p>The algorithm operates as follows: Searches for an annotation on the given class and returns
|
||||
* it if found. Else searches all interfaces that the given class declares, returning the annotation
|
||||
* from the first matching candidate, if any. Else proceeds with introspection of the superclass
|
||||
* of the given class, checking the superclass itself; if no annotation found there, proceeds
|
||||
* with the interfaces that the superclass declares. Recursing up through the entire superclass
|
||||
* hierarchy if no match is found.
|
||||
* @param clazz the class to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @return the annotation found, or <code>null</code> if none found
|
||||
|
|
@ -175,18 +178,21 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the first {@link Class} in the inheritance hierarchy of the specified <code>clazz</code> (including the
|
||||
* specified <code>clazz</code> itself) which declares an annotation for the specified <code>annotationType</code>, or
|
||||
* <code>null</code> if not found. If the supplied <code>clazz</code> is <code>null</code>, <code>null</code> will be
|
||||
* returned. <p>If the supplied <code>clazz</code> is an interface, only the interface itself will be checked; the
|
||||
* inheritance hierarchy for interfaces will not be traversed. <p>The standard {@link Class} API does not provide a
|
||||
* mechanism for determining which class in an inheritance hierarchy actually declares an {@link Annotation}, so we
|
||||
* need to handle this explicitly.
|
||||
* Find the first {@link Class} in the inheritance hierarchy of the specified <code>clazz</code>
|
||||
* (including the specified <code>clazz</code> itself) which declares an annotation for the
|
||||
* specified <code>annotationType</code>, or <code>null</code> if not found. If the supplied
|
||||
* <code>clazz</code> is <code>null</code>, <code>null</code> will be returned.
|
||||
* <p>If the supplied <code>clazz</code> is an interface, only the interface itself will be checked;
|
||||
* the inheritance hierarchy for interfaces will not be traversed.
|
||||
* <p>The standard {@link Class} API does not provide a mechanism for determining which class
|
||||
* in an inheritance hierarchy actually declares an {@link Annotation}, so we need to handle
|
||||
* this explicitly.
|
||||
* @param annotationType the Class object corresponding to the annotation type
|
||||
* @param clazz the Class object corresponding to the class on which to check for the annotation, or
|
||||
* <code>null</code>.
|
||||
* @return the first {@link Class} in the inheritance hierarchy of the specified <code>clazz</code> which
|
||||
* declares an annotation for the specified <code>annotationType</code>, or <code>null</code> if not found.
|
||||
* @param clazz the Class object corresponding to the class on which to check for the annotation,
|
||||
* or <code>null</code>
|
||||
* @return the first {@link Class} in the inheritance hierarchy of the specified <code>clazz</code>
|
||||
* which declares an annotation for the specified <code>annotationType</code>, or <code>null</code>
|
||||
* if not found
|
||||
* @see Class#isAnnotationPresent(Class)
|
||||
* @see Class#getDeclaredAnnotations()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -599,9 +599,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||
if (oldMappedMethod != null) {
|
||||
throw new IllegalStateException(
|
||||
"Ambiguous handler methods mapped for HTTP path '" + lookupPath + "': {" +
|
||||
oldMappedMethod + ", " + handlerMethod +
|
||||
"}. If you intend to handle the same path in multiple methods, then factor " +
|
||||
"them out into a dedicated handler class with that path mapped at the type level!");
|
||||
oldMappedMethod + ", " + handlerMethod +
|
||||
"}. If you intend to handle the same path in multiple methods, then factor " +
|
||||
"them out into a dedicated handler class with that path mapped at the type level!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1093,6 +1093,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclass of {@link RequestMappingInfo} that holds request-specific data.
|
||||
*/
|
||||
|
|
@ -1119,22 +1120,21 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||
public String bestMatchedPattern() {
|
||||
return (!this.matchedPatterns.isEmpty() ? this.matchedPatterns.get(0) : null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Comparator capable of sorting {@link RequestSpecificMappingInfo}s (RHIs) so that sorting a list with this comparator will
|
||||
* result in:
|
||||
* Comparator capable of sorting {@link RequestSpecificMappingInfo}s (RHIs) so that
|
||||
* sorting a list with this comparator will result in:
|
||||
* <ul>
|
||||
* <li>RHIs with {@linkplain org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.RequestSpecificMappingInfo#matchedPatterns better matched paths} take prescedence
|
||||
* over those with a weaker match (as expressed by the {@linkplain PathMatcher#getPatternComparator(String) path
|
||||
* pattern comparator}.) Typically, this means that patterns without wild cards and uri templates will be ordered
|
||||
* before those without.</li>
|
||||
* <li>RHIs with {@linkplain AnnotationMethodHandlerAdapter.RequestSpecificMappingInfo#matchedPatterns better matched paths}
|
||||
* take prescedence over those with a weaker match (as expressed by the {@linkplain PathMatcher#getPatternComparator(String)
|
||||
* path pattern comparator}.) Typically, this means that patterns without wild cards and uri templates
|
||||
* will be ordered before those without.</li>
|
||||
* <li>RHIs with one single {@linkplain RequestMappingInfo#methods request method} will be
|
||||
* ordered before those without a method, or with more than one method.</li>
|
||||
* <li>RHIs with more {@linkplain RequestMappingInfo#params request parameters} will be ordered before those with
|
||||
* less parameters</li>
|
||||
* <li>RHIs with more {@linkplain RequestMappingInfo#params request parameters} will be ordered
|
||||
* before those with less parameters</li>
|
||||
* </ol>
|
||||
*/
|
||||
static class RequestSpecificMappingInfoComparator implements Comparator<RequestSpecificMappingInfo> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue