当前位置: 首页>>代码示例>>Java>>正文


Java AnnotatedElement.getAnnotation方法代码示例

本文整理汇总了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());
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:26,代码来源:EditableUtils.java

示例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;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:27,代码来源:EditableUtils.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:CommonAnnotationBeanPostProcessor.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SpringCacheAnnotationParser.java

示例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;
}
 
开发者ID:mental-party,项目名称:meparty,代码行数:36,代码来源:RestApiProxyInvocationHandler.java

示例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;
}
 
开发者ID:ThorbenKuck,项目名称:NetCom2,代码行数:15,代码来源:RemoteObjectRegistrationImpl.java

示例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)
    );
}
 
开发者ID:allure-framework,项目名称:allure-java,代码行数:9,代码来源:AllureJunit5AnnotationProcessor.java

示例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;
        }
    };
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:ArchRules.java

示例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");
    }
}
 
开发者ID:sajadshokri,项目名称:GhostAdapter,代码行数:9,代码来源:GhostAdapter.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:CommonAnnotationBeanPostProcessor.java

示例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));
}
 
开发者ID:turoDog,项目名称:effectiveJava,代码行数:13,代码来源:PrintAnnotation.java

示例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);
        }
    }
}
 
开发者ID:ISIS2503,项目名称:ThermalComfortBack,代码行数:14,代码来源:AuthorizationFilter.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:Matchers.java

示例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;
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:5,代码来源:InjectionPoint.java

示例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();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:MatchEventRegistry.java


注:本文中的java.lang.reflect.AnnotatedElement.getAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。