本文整理汇总了Java中java.lang.reflect.AnnotatedElement.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedElement.getAnnotation方法的具体用法?Java AnnotatedElement.getAnnotation怎么用?Java AnnotatedElement.getAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.AnnotatedElement
的用法示例。
在下文中一共展示了AnnotatedElement.getAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getName
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
/**
* Get display name of specified element from name parameter of {@link Editable} annotation.
* If the annotation is not defined or name parameter is not available in the annotation, the
* element name itself will be transferred to non-camel case and returned.
*
* @param element
* annotated element to get name from
* @return
* display name of the element
*/
public static String getName(AnnotatedElement element) {
Editable editable = element.getAnnotation(Editable.class);
if (editable != null && editable.name().trim().length() != 0)
return editable.name();
else if (element instanceof Class)
return WordUtils.uncamel(((Class<?>)element).getSimpleName());
else if (element instanceof Field)
return WordUtils.uncamel(WordUtils.capitalize(((Field)element).getName()));
else if (element instanceof Method)
return StringUtils.substringAfter(WordUtils.uncamel(((Method)element).getName()), " ");
else if (element instanceof Package)
return ((Package)element).getName();
else
throw new GeneralException("Invalid element type: " + element.getClass().getName());
}
示例2: getDescription
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
/**
* Get description of specified element from description parameter of {@link Editable} annotation
*
* @param element
* annotated element to get description from
* @return
* defined description, or <tt>null</tt> if description can not be found
*/
public static @Nullable String getDescription(AnnotatedElement element) {
Editable editable = element.getAnnotation(Editable.class);
if (editable != null) {
if (editable.description().length() != 0)
return editable.description();
if (editable.descriptionProvider().length() != 0) {
Class<?> clazz;
if (element instanceof Method)
clazz = ((Method) element).getDeclaringClass();
else if (element instanceof Class)
clazz = (Class<?>) element;
else
clazz = ((Field) element).getDeclaringClass();
return (String) ReflectionUtils.invokeStaticMethod(clazz, editable.descriptionProvider());
}
}
return null;
}
示例3: EjbRefElement
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public EjbRefElement(Member member, PropertyDescriptor pd) {
super(member, pd);
AnnotatedElement ae = (AnnotatedElement) member;
EJB resource = ae.getAnnotation(EJB.class);
String resourceBeanName = resource.beanName();
String resourceName = resource.name();
this.isDefaultName = !StringUtils.hasLength(resourceName);
if (this.isDefaultName) {
resourceName = this.member.getName();
if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
resourceName = Introspector.decapitalize(resourceName.substring(3));
}
}
Class<?> resourceType = resource.beanInterface();
if (resourceType != null && !Object.class.equals(resourceType)) {
checkResourceType(resourceType);
}
else {
// No resource type specified... check field/method.
resourceType = getResourceType();
}
this.beanName = resourceBeanName;
this.name = resourceName;
this.lookupType = resourceType;
this.mappedName = resource.mappedName();
}
示例4: getAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae, Class<T> annotationType) {
Collection<T> anns = new ArrayList<T>(2);
// look at raw annotation
T ann = ae.getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
// scan meta-annotations
for (Annotation metaAnn : ae.getAnnotations()) {
ann = metaAnn.annotationType().getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
}
return (anns.isEmpty() ? null : anns);
}
示例5: findMappingAnnotation
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
Annotation findMappingAnnotation(AnnotatedElement element) {
Annotation mappingAnnotation = element.getAnnotation(RequestMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(GetMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PostMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PutMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(DeleteMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PatchMapping.class);
}
}
}
}
}
if (mappingAnnotation == null) {
if (element instanceof Method) {
Method method = (Method) element;
mappingAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
} else {
Class<?> clazz = (Class<?>) element;
mappingAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);
}
}
return mappingAnnotation;
}
示例6: ignoreThrowable
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private boolean ignoreThrowable(Exception exception, AnnotatedElement... annotatedElements) {
if(exception != null) {
for(AnnotatedElement element : annotatedElements) {
if(element == null) {
continue;
}
IgnoreRemoteExceptions annotation = element.getAnnotation(IgnoreRemoteExceptions.class);
if(annotation != null) {
return !Arrays.asList(annotation.exceptTypes()).contains(exception.getClass());
}
}
}
return false;
}
示例7: getAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private <T extends Annotation> Stream<T> getAnnotations(final AnnotatedElement annotatedElement,
final Class<T> annotationClass) {
final T annotation = annotatedElement.getAnnotation(annotationClass);
return Stream.concat(
extractRepeatable(annotatedElement, annotationClass).stream(),
Objects.isNull(annotation) ? Stream.empty() : Stream.of(annotation)
);
}
示例8: withAnnotation
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private static Predicate<AnnotatedElement> withAnnotation(final Class<? extends Annotation> annotationType) {
return new Predicate<AnnotatedElement>() {
@Override
public boolean apply(AnnotatedElement input) {
return input.getAnnotation(annotationType) != null;
}
};
}
示例9: readLayout
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private int readLayout(AnnotatedElement element) {
if (element.isAnnotationPresent(BindItem.class)) {
BindItem bindItem = element.getAnnotation(BindItem.class);
return bindItem.layout();
} else {
throw new IllegalStateException("items should be annotated with BindItem");
}
}
示例10: WebServiceRefElement
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public WebServiceRefElement(Member member, PropertyDescriptor pd) {
super(member, pd);
AnnotatedElement ae = (AnnotatedElement) member;
WebServiceRef resource = ae.getAnnotation(WebServiceRef.class);
String resourceName = resource.name();
Class<?> resourceType = resource.type();
this.isDefaultName = !StringUtils.hasLength(resourceName);
if (this.isDefaultName) {
resourceName = this.member.getName();
if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
resourceName = Introspector.decapitalize(resourceName.substring(3));
}
}
if (resourceType != null && !Object.class.equals(resourceType)) {
checkResourceType(resourceType);
}
else {
// No resource type specified... check field/method.
resourceType = getResourceType();
}
this.name = resourceName;
this.elementType = resourceType;
if (Service.class.isAssignableFrom(resourceType)) {
this.lookupType = resourceType;
}
else {
this.lookupType = (!Object.class.equals(resource.value()) ? resource.value() : Service.class);
}
this.mappedName = resource.mappedName();
this.wsdlLocation = resource.wsdlLocation();
}
示例11: getAnnotation
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
static Annotation getAnnotation(AnnotatedElement element,
String annotationTypeName) {
Class<?> annotationType = null; //��������������
try {
annotationType = Class.forName(annotationTypeName);
} catch (Exception e) {
// TODO: handle exception
throw new IllegalArgumentException(e);
}
return element.getAnnotation(annotationType
.asSubclass(Annotation.class));
}
示例12: extractRoles
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private List<Role> extractRoles(AnnotatedElement annotatedElement) {
if (annotatedElement == null) {
return new ArrayList<>();
} else {
Secured secured = annotatedElement.getAnnotation(Secured.class);
if (secured == null) {
return new ArrayList<>();
} else {
Role[] allowedRoles = secured.value();
return Arrays.asList(allowedRoles);
}
}
}
示例13: matches
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
@Override
public boolean matches(AnnotatedElement element) {
Annotation fromElement = element.getAnnotation(annotation.annotationType());
return fromElement != null && annotation.equals(fromElement);
}
示例14: getAtInject
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
static Annotation getAtInject(AnnotatedElement member) {
Annotation a = member.getAnnotation(javax.inject.Inject.class);
return a == null ? member.getAnnotation(Inject.class) : a;
}
示例15: listenerScope
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private static MatchScope listenerScope(AnnotatedElement thing, @Nullable MatchScope def) {
final ListenerScope annotation = thing.getAnnotation(ListenerScope.class);
return annotation == null ? def : annotation.value();
}