Java Code Examples for java.lang.reflect.AccessibleObject#getAnnotations()
The following examples show how to use
java.lang.reflect.AccessibleObject#getAnnotations() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OWLSchemaPersistingManager.java From anno4j with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: CallerSensitiveDetector.java From nashorn with GNU General Public License v2.0 | 6 votes |
@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; }
Example 3
Source File: CallerSensitiveDetector.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@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; }
Example 4
Source File: AutowiredAnnotationBeanPostProcessor.java From java-technology-stack with MIT License | 5 votes |
@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; }
Example 5
Source File: CallerSensitiveDetector.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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; }
Example 6
Source File: CallerSensitiveDetector.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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; }
Example 7
Source File: AutowiredAnnotationBeanPostProcessor.java From lams with GNU General Public License v2.0 | 5 votes |
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; }
Example 8
Source File: CallerSensitiveDetector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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; }
Example 9
Source File: CallerSensitiveDetector.java From hottub with GNU General Public License v2.0 | 5 votes |
@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; }
Example 10
Source File: CallerSensitiveDetector.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override boolean isCallerSensitive(AccessibleObject o) { for(Annotation a: o.getAnnotations()) { if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) { return true; } } return false; }
Example 11
Source File: AutowiredAnnotationBeanPostProcessor.java From spring4-understanding with Apache License 2.0 | 5 votes |
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; }
Example 12
Source File: CallerSensitiveDetector.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override boolean isCallerSensitive(AccessibleObject o) { for(Annotation a: o.getAnnotations()) { if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) { return true; } } return false; }
Example 13
Source File: MetaDataScanner.java From qaf with MIT License | 5 votes |
/** * 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; }
Example 14
Source File: CallerSensitiveDetector.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@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; }
Example 15
Source File: AccessibleObjectTest.java From j2objc with Apache License 2.0 | 5 votes |
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)); }
Example 16
Source File: InjectAnnotationBeanPostProcessor.java From spring-boot-starter-dubbo with Apache License 2.0 | 3 votes |
private Inject findReferenceAnnotation(AccessibleObject accessibleObject) { if (accessibleObject.getAnnotations().length > 0) { Inject inject = getMergedAnnotation(accessibleObject, Inject.class); return inject; } return null; }