Java Code Examples for org.springframework.core.annotation.AnnotatedElementUtils#isAnnotated()
The following examples show how to use
org.springframework.core.annotation.AnnotatedElementUtils#isAnnotated() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardAnnotationMetadata.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); } } return annotatedMethods; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 2
Source File: StandardAnnotationMetadata.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { return true; } } return false; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 3
Source File: DelegatingMethodParameter.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Customize method parameter [ ]. * * @param pNames the p names * @param parameters the parameters * @return the method parameter [ ] */ public static MethodParameter[] customize(String[] pNames, MethodParameter[] parameters) { List<MethodParameter> explodedParameters = new ArrayList<>(); for (int i = 0; i < parameters.length; ++i) { MethodParameter p = parameters[i]; Class<?> paramClass = AdditionalModelsConverter.getReplacement(p.getParameterType()); if (p.hasParameterAnnotation(ParameterObject.class) || AnnotatedElementUtils.isAnnotated(paramClass, ParameterObject.class)) { MethodParameterPojoExtractor.extractFrom(paramClass).forEach(explodedParameters::add); } else { String name = pNames != null ? pNames[i] : p.getParameterName(); explodedParameters.add(new DelegatingMethodParameter(p, name, null,false)); } } return explodedParameters.toArray(new MethodParameter[0]); }
Example 4
Source File: StandardAnnotationMetadata.java From java-technology-stack with MIT License | 6 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { return true; } } return false; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 5
Source File: StandardAnnotationMetadata.java From java-technology-stack with MIT License | 6 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); } } return annotatedMethods; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 6
Source File: StandardAnnotationMetadata.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { return true; } } return false; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 7
Source File: StandardAnnotationMetadata.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { try { Method[] methods = getIntrospectedClass().getDeclaredMethods(); Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(); for (Method method : methods) { if (!method.isBridge() && method.getAnnotations().length > 0 && AnnotatedElementUtils.isAnnotated(method, annotationName)) { annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); } } return annotatedMethods; } catch (Throwable ex) { throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } }
Example 8
Source File: TypeDescriptor.java From spring-analysis-note with MIT License | 5 votes |
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
Example 9
Source File: TypeDescriptor.java From java-technology-stack with MIT License | 5 votes |
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
Example 10
Source File: ClassUtil.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
/** * 判断是否有注解 Annotation * * @param method Method * @param annotationType 注解类 * @param <A> 泛型标记 * @return {boolean} */ public static <A extends Annotation> boolean isAnnotated(Method method, Class<A> annotationType) { // 先找方法,再找方法上的类 boolean isMethodAnnotated = AnnotatedElementUtils.isAnnotated(method, annotationType); if (isMethodAnnotated) { return true; } // 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类 Class<?> targetClass = method.getDeclaringClass(); return AnnotatedElementUtils.isAnnotated(targetClass, annotationType); }
Example 11
Source File: StartupApplicationListener.java From spring-init with Apache License 2.0 | 5 votes |
private boolean isSpringBootApplication(Set<Class<?>> sources) { for (Class<?> source : sources) { if (AnnotatedElementUtils.isAnnotated(source, SpringBootConfiguration.class)) { return true; } if (source.getName().endsWith("BootstrapMarkerConfiguration")) { return true; // sigh, Spring Cloud } } if (sources.contains(Object.class)) { // TODO: find a better marker class for a Spring Init application return true; } return false; }
Example 12
Source File: TypeDescriptor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
Example 13
Source File: JobBeanIntrospector.java From haven-platform with Apache License 2.0 | 5 votes |
private static boolean processDeps(List<Dependency> deps, AnnotatedElement ao) { if(!(AnnotatedElementUtils.isAnnotated(ao, Autowired.class))) { return false; } Qualifier qualifier = AnnotatedElementUtils.getMergedAnnotation(ao, Qualifier.class); String name = qualifier == null ? null : qualifier.value(); Class<?> type = (ao instanceof Field)? ((Field)ao).getType() : ((Method)ao).getReturnType(); deps.add(new Dependency(name, type)); return true; }
Example 14
Source File: StandardMethodMetadata.java From java-technology-stack with MIT License | 4 votes |
@Override public boolean isAnnotated(String annotationName) { return AnnotatedElementUtils.isAnnotated(this.introspectedMethod, annotationName); }
Example 15
Source File: StandardAnnotationMetadata.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public boolean isAnnotated(String annotationName) { return (this.annotations.length > 0 && AnnotatedElementUtils.isAnnotated(getIntrospectedClass(), annotationName)); }
Example 16
Source File: StandardMethodMetadata.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public boolean isAnnotated(String annotationName) { return AnnotatedElementUtils.isAnnotated(this.introspectedMethod, annotationName); }
Example 17
Source File: StandardAnnotationMetadata.java From java-technology-stack with MIT License | 4 votes |
@Override public boolean isAnnotated(String annotationName) { return (this.annotations.length > 0 && AnnotatedElementUtils.isAnnotated(getIntrospectedClass(), annotationName)); }
Example 18
Source File: StandardMethodMetadata.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public boolean isAnnotated(String annotationName) { return AnnotatedElementUtils.isAnnotated(this.introspectedMethod, annotationName); }
Example 19
Source File: EventListenerMethodProcessor.java From java-technology-stack with MIT License | 2 votes |
/** * Determine whether the given class is an {@code org.springframework} * bean class that is not annotated as a user or test {@link Component}... * which indicates that there is no {@link EventListener} to be found there. * @since 5.1 */ private static boolean isSpringContainerClass(Class<?> clazz) { return (clazz.getName().startsWith("org.springframework.") && !AnnotatedElementUtils.isAnnotated(ClassUtils.getUserClass(clazz), Component.class)); }
Example 20
Source File: EventListenerMethodProcessor.java From spring-analysis-note with MIT License | 2 votes |
/** * Determine whether the given class is an {@code org.springframework} * bean class that is not annotated as a user or test {@link Component}... * which indicates that there is no {@link EventListener} to be found there. * @since 5.1 */ private static boolean isSpringContainerClass(Class<?> clazz) { return (clazz.getName().startsWith("org.springframework.") && !AnnotatedElementUtils.isAnnotated(ClassUtils.getUserClass(clazz), Component.class)); }