本文整理了Java中java.lang.Class.getAnnotations()
方法的一些代码示例,展示了Class.getAnnotations()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getAnnotations()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getAnnotations
[英]Returns an array containing all the annotations of this class. If there are no annotations then an empty array is returned.
[中]返回包含此类的所有批注的数组。如果没有注释,则返回一个空数组。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@link StandardAnnotationMetadata} wrapper for the given Class,
* providing the option to return any nested annotations or annotation arrays in the
* form of {@link org.springframework.core.annotation.AnnotationAttributes} instead
* of actual {@link Annotation} instances.
* @param introspectedClass the Class to introspect
* @param nestedAnnotationsAsMap return nested annotations and annotation arrays as
* {@link org.springframework.core.annotation.AnnotationAttributes} for compatibility
* with ASM-based {@link AnnotationMetadata} implementations
* @since 3.1.1
*/
public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) {
super(introspectedClass);
this.annotations = introspectedClass.getAnnotations();
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
}
代码示例来源:origin: junit-team/junit4
/**
* Returns the annotations on this class
*/
public Annotation[] getAnnotations() {
if (clazz == null) {
return new Annotation[0];
}
return clazz.getAnnotations();
}
代码示例来源:origin: google/j2objc
/**
* Returns the annotations on this class
*/
public Annotation[] getAnnotations() {
if (fClass == null) {
return new Annotation[0];
}
return fClass.getAnnotations();
}
代码示例来源:origin: lets-blade/blade
public Annotation[] getAnnotations() {
return clazz.getAnnotations();
}
代码示例来源:origin: lets-blade/blade
public Annotation[] getAnnotations() {
return clazz.getAnnotations();
}
代码示例来源:origin: prestodb/presto
private static boolean shouldUseFileSplitsFromInputFormat(InputFormat<?, ?> inputFormat)
{
return Arrays.stream(inputFormat.getClass().getAnnotations())
.map(Annotation::annotationType)
.map(Class::getSimpleName)
.anyMatch(name -> name.equals("UseFileSplitsFromInputFormat"));
}
代码示例来源:origin: libgdx/libgdx
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, and inherited
* from its superclass. Returns an empty array if there are none. */
static public Annotation[] getAnnotations (Class c) {
java.lang.annotation.Annotation[] annotations = c.getAnnotations();
Annotation[] result = new Annotation[annotations.length];
for (int i = 0; i < annotations.length; i++) {
result[i] = new Annotation(annotations[i]);
}
return result;
}
代码示例来源:origin: libgdx/libgdx
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, and inherited
* from its superclass. Returns an empty array if there are none. */
static public Annotation[] getAnnotations (Class c) {
java.lang.annotation.Annotation[] annotations = c.getAnnotations();
Annotation[] result = new Annotation[annotations.length];
for (int i = 0; i < annotations.length; i++) {
result[i] = new Annotation(annotations[i]);
}
return result;
}
代码示例来源:origin: com.google.inject/guice
@Override
public Boolean load(Class<? extends Annotation> annotationType) {
for (Annotation annotation : annotationType.getAnnotations()) {
if (annotationTypes.contains(annotation.annotationType())) {
return true;
}
}
return false;
}
};
代码示例来源:origin: jersey/jersey
private boolean isEjbComponent(Class<?> component) {
for (Annotation a : component.getAnnotations()) {
if (EjbComponentAnnotations.contains(a.annotationType().getName())) {
return true;
}
}
return false;
}
代码示例来源:origin: oblac/jodd
/**
* Returns {@code true} if type is a Kotlin class.
*/
public static boolean isKotlinClass(final Class type) {
final Annotation[] annotations = type.getAnnotations();
for (Annotation annotation : annotations) {
if (annotation.annotationType().getName().equals("kotlin.Metadata")) {
return true;
}
}
return false;
}
代码示例来源:origin: junit-team/junit4
/**
* Create a <code>Description</code> named after <code>testClass</code>
*
* @param testClass A {@link Class} containing tests
* @return a <code>Description</code> of <code>testClass</code>
*/
public static Description createSuiteDescription(Class<?> testClass) {
return new Description(testClass, testClass.getName(), testClass.getAnnotations());
}
代码示例来源:origin: google/j2objc
/**
* Create a <code>Description</code> named after <code>testClass</code>
*
* @param testClass A {@link Class} containing tests
* @return a <code>Description</code> of <code>testClass</code>
*/
public static Description createSuiteDescription(Class<?> testClass) {
return new Description(testClass, testClass.getName(), testClass.getAnnotations());
}
代码示例来源:origin: junit-team/junit4
protected Annotation[] classAnnotations() {
return testClass.getJavaClass().getAnnotations();
}
代码示例来源:origin: google/j2objc
protected Annotation[] classAnnotations() {
return fTestClass.getJavaClass().getAnnotations();
}
代码示例来源:origin: junit-team/junit4
private <T extends Annotation> T findDeepAnnotation(
Annotation[] annotations, Class<T> annotationType, int depth) {
if (depth == 0) {
return null;
}
for (Annotation each : annotations) {
if (annotationType.isInstance(each)) {
return annotationType.cast(each);
}
Annotation candidate = findDeepAnnotation(each.annotationType()
.getAnnotations(), annotationType, depth - 1);
if (candidate != null) {
return annotationType.cast(candidate);
}
}
return null;
}
代码示例来源:origin: com.google.inject/guice
/** Returns the scope annotation on {@code type}, or null if none is specified. */
public static Class<? extends Annotation> findScopeAnnotation(
Errors errors, Class<?> implementation) {
return findScopeAnnotation(errors, implementation.getAnnotations());
}
代码示例来源:origin: spring-projects/spring-framework
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) {
Class<? extends Annotation> annotationType = annotation.annotationType();
String annotationName = annotationType.getName();
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) {
try {
// Only do attribute scanning for public annotations; we'd run into
// IllegalAccessExceptions otherwise, and we don't want to mess with
// accessibility in a SecurityManager environment.
if (Modifier.isPublic(annotationType.getModifiers())) {
this.attributesMap.add(annotationName,
AnnotationUtils.getAnnotationAttributes(annotation, false, true));
}
for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) {
recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
}
}
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex);
}
}
}
}
代码示例来源:origin: spring-projects/spring-framework
Annotation[] metaAnnotations = annotationClass.getAnnotations();
if (!ObjectUtils.isEmpty(metaAnnotations)) {
Set<Annotation> visited = new LinkedHashSet<>();
代码示例来源:origin: spring-projects/spring-framework
/**
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
*/
SourceClass asSourceClass(@Nullable Class<?> classType) throws IOException {
if (classType == null) {
return new SourceClass(Object.class);
}
try {
// Sanity test that we can reflectively read annotations,
// including Class attributes; if not -> fall back to ASM
for (Annotation ann : classType.getAnnotations()) {
AnnotationUtils.validateAnnotation(ann);
}
return new SourceClass(classType);
}
catch (Throwable ex) {
// Enforce ASM via class name resolution
return asSourceClass(classType.getName());
}
}
内容来源于网络,如有侵权,请联系作者删除!