本文整理匯總了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();
}