java.lang.reflect.AccessibleObject#getAnnotations ( )源码实例Demo

下面列出了java.lang.reflect.AccessibleObject#getAnnotations ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: anno4j   文件: OWLSchemaPersistingManager.java
/**
 * Unpacks all annotations that are present at the given object.
 * Some annotations (e.g. {@link MinCardinality}) may be packed in a container annotation (e.g. {@link MinCardinalities}).
 * In contrast to {@link AccessibleObject#getAnnotations()} these contained annotations are unpacked and the container
 * is omitted.
 * @param object The object for which to get the annotations.
 * @return The unpacked annotations of the object.
 */
private Collection<Annotation> unpackAnnotations(AccessibleObject object) {
    Collection<Annotation> annotations = new HashSet<>();

    for (Annotation annotation : object.getAnnotations()) {

        // Unpack container annotations:
        if(annotation.getClass().equals(MinCardinalities.class)) {
            annotations.addAll(unpackAnnotations(object, MinCardinality.class));

        } else if(annotation.getClass().equals(MaxCardinalities.class)) {
            annotations.addAll(unpackAnnotations(object, MaxCardinality.class));

        } else if(annotation.getClass().equals(Cardinalities.class)) {
            annotations.addAll(unpackAnnotations(object, Cardinality.class));

        } else { // Add any directly annotated (non-container) annotation:
            annotations.add(annotation);
        }
    }
    return annotations;
}
 
源代码2 项目: nashorn   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(AccessibleObject o) {
    for(Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    if (o instanceof Method) {
        // JDK7 hack
        Method method = (Method) o;
        final String className = method.getDeclaringClass().getName();
        final String methodName = method.getName();
        if (className.equals("java.security.AccessController") && methodName.equals("doPrivileged")) {
            return true;
        }
        if (className.equals("java.lang.Class") && methodName.equals("forName")) {
            return true;
        }
    }
    return false;
}
 
源代码3 项目: TencentKona-8   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
@Nullable
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
	if (ao.getAnnotations().length > 0) {  // autowiring annotations have to be local
		for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
			AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
			if (attributes != null) {
				return attributes;
			}
		}
	}
	return null;
}
 
源代码5 项目: jdk8u60   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
源代码6 项目: openjdk-jdk8u   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
	if (ao.getAnnotations().length > 0) {
		for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
			AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
			if (attributes != null) {
				return attributes;
			}
		}
	}
	return null;
}
 
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
源代码9 项目: hottub   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
源代码10 项目: openjdk-8-source   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(AccessibleObject o) {
    for(Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
	if (ao.getAnnotations().length > 0) {
		for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
			AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
			if (attributes != null) {
				return attributes;
			}
		}
	}
	return null;
}
 
源代码12 项目: openjdk-8   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(AccessibleObject o) {
    for(Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
源代码13 项目: qaf   文件: MetaDataScanner.java
/**
 * Scans all annotation except @Test, and generates map.
 * 
 * @param MethodOrFileld
 * @return
 * @throws Exception
 */
public static Map<String, Object> getMetadata(AccessibleObject methodOrFileld, boolean excludeTest) {
	Map<String, Object> metadata = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
	metadata.putAll(metadataFromClass(methodOrFileld));

	try {
		Annotation[] allAnnotations = methodOrFileld.getAnnotations();
		for (Annotation annotation : allAnnotations) {
			if (excludeTest && annotation instanceof Test)
				continue;

			Method[] annotationMethods = annotation.annotationType().getDeclaredMethods();
			for (Method annotationMethod : annotationMethods) {
				Object objVal = annotationMethod.invoke(annotation);
				if (annotation instanceof MetaData) {
					@SuppressWarnings("unchecked")
					Map<String, Object> map = new Gson().fromJson((String) objVal, Map.class);
					metadata.putAll(map);
				} else {
					metadata.put(annotationMethod.getName(), objVal);
				}
			}
		}
	} catch (Exception e) {
		logger.error(e);
	}
	return metadata;
}
 
源代码14 项目: jdk8u_nashorn   文件: CallerSensitiveDetector.java
@Override
boolean isCallerSensitive(final AccessibleObject o) {
    for(final Annotation a: o.getAnnotations()) {
        if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
            return true;
        }
    }
    return false;
}
 
源代码15 项目: j2objc   文件: AccessibleObjectTest.java
public void test_getAnnotations() throws Exception {
    AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
    Annotation[] annotations = ao.getAnnotations();
    assertEquals(2, annotations.length);

    Set<Class<?>> ignoreOrder = new HashSet<Class<?>>();
    ignoreOrder.add(annotations[0].annotationType());
    ignoreOrder.add(annotations[1].annotationType());

    assertTrue("Missing @AnnotationRuntime0",
            ignoreOrder.contains(AnnotationRuntime0.class));
    assertTrue("Missing @AnnotationRuntime1",
            ignoreOrder.contains(AnnotationRuntime1.class));
}
 
private Inject findReferenceAnnotation(AccessibleObject accessibleObject) {

        if (accessibleObject.getAnnotations().length > 0) {
        	Inject inject = getMergedAnnotation(accessibleObject, Inject.class);
            return inject;
        }

        return null;

    }