Java Code Examples for java.lang.reflect.AccessibleObject#isAnnotationPresent()

The following examples show how to use java.lang.reflect.AccessibleObject#isAnnotationPresent() . 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 vote down vote up
/**
 * Constructs a SPARQL VALUES clause for successive binding of the given objects {@link Iri} mappings,
 * to the SPARQL variable <code>binding</code>.
 * The IRIs of the resources are enclosed in <code>&lt;&gt;</code> brackets.
 * @param objects The values to successively bind.
 * @param binding The name of the binding without a leading <code>"?"</code>.
 * @return Returns a SPARQL VALUES clause with the given resources and binding.
 */
private String buildValuesClause(Collection<AccessibleObject> objects, String binding) {
    StringBuilder clause = new StringBuilder("VALUES ?")
            .append(binding)
            .append(" {");

    for (AccessibleObject object : objects) {
        if(object.isAnnotationPresent(Iri.class)) {
            Iri iri = object.getAnnotation(Iri.class);

            clause.append(" <")
                    .append(iri.value())
                    .append("> ");
        }
    }
    clause.append("}");

    return clause.toString();
}
 
Example 2
Source File: AbstractJavaLinker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given a reflective method or a constructor, creates a dynamic method that represents it. This method will
 * distinguish between caller sensitive and ordinary methods/constructors, and create appropriate caller sensitive
 * dynamic method when needed.
 * @param m the reflective member
 * @return the single dynamic method representing the reflective member
 */
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
    if (m.isAnnotationPresent(CallerSensitive.class)) {
        // Method has @CallerSensitive annotation
        return new CallerSensitiveDynamicMethod(m);
    }
    // Method has no @CallerSensitive annotation
    final MethodHandle mh;
    try {
        mh = unreflectSafely(m);
    } catch (final IllegalAccessError e) {
        // java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
        // marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
        return new CallerSensitiveDynamicMethod(m);
    }
    // Proceed with non-caller sensitive
    final Member member = (Member)m;
    return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
}
 
Example 3
Source File: CustomClassMapper.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private static String annotatedName(AccessibleObject obj) {
  if (obj.isAnnotationPresent(PropertyName.class)) {
    PropertyName annotation = obj.getAnnotation(PropertyName.class);
    return annotation.value();
  }

  return null;
}
 
Example 4
Source File: ScriptableObject.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private static Member findAnnotatedMember(AccessibleObject[] members,
                                          Class<? extends Annotation> annotation) {
    for (AccessibleObject member : members) {
        if (member.isAnnotationPresent(annotation)) {
            return (Member) member;
        }
    }
    return null;
}
 
Example 5
Source File: CustomClassMapper.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
private static String annotatedName(AccessibleObject obj) {
  if (obj.isAnnotationPresent(PropertyName.class)) {
    PropertyName annotation = obj.getAnnotation(PropertyName.class);
    return annotation.value();
  }

  return null;
}
 
Example 6
Source File: SeleniumTestHandler.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasInjectAnnotation(AccessibleObject f) {
  return f.isAnnotationPresent(com.google.inject.Inject.class)
      || f.isAnnotationPresent(javax.inject.Inject.class)
      || f.isAnnotationPresent(InjectTestWorkspace.class)
      || f.isAnnotationPresent(InjectTestOrganization.class)
      || f.isAnnotationPresent(InjectPageObject.class);
}
 
Example 7
Source File: EventSupport.java    From jkes with Apache License 2.0 5 votes vote down vote up
private CascadeType[] getCascadeTypes(AccessibleObject accessibleObject) {
    CascadeType[] cascadeTypes = null;
    if(accessibleObject.isAnnotationPresent(OneToMany.class)) {
        cascadeTypes = accessibleObject.getAnnotation(OneToMany.class).cascade();
    }else if(accessibleObject.isAnnotationPresent(ManyToOne.class)) {
        cascadeTypes = accessibleObject.getAnnotation(ManyToOne.class).cascade();
    }else if(accessibleObject.isAnnotationPresent(ManyToMany.class)) {
        cascadeTypes = accessibleObject.getAnnotation(ManyToMany.class).cascade();
    }
    return cascadeTypes;
}
 
Example 8
Source File: AccessibleObjectTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_isAnnotationPresent() throws Exception {
    AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
    assertTrue("Missing @AnnotationRuntime0",
            ao.isAnnotationPresent(AnnotationRuntime0.class));
    assertFalse("AnnotationSource0 should not be visible at runtime",
            ao.isAnnotationPresent(AnnotationSource0.class));
    boolean npeThrown = false;
    try {
      ao.isAnnotationPresent(null);
      fail("NPE expected");
    } catch (NullPointerException e) {
        npeThrown = true;
    }
    assertTrue("NPE expected", npeThrown);
}
 
Example 9
Source File: IsAnnotatedWith.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public boolean test(final AccessibleObject a) {
  return a.isAnnotationPresent(this.clazz);
}
 
Example 10
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 11
Source File: Introspector.java    From livingdoc-core with GNU General Public License v3.0 4 votes vote down vote up
private boolean hasAliasAnnotation(AccessibleObject accessibleObject) {
    return accessibleObject.isAnnotationPresent(Alias.class);
}
 
Example 12
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 13
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 14
Source File: JavaAdapterBytecodeGenerator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 15
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 16
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 17
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 18
Source File: JythonUtils.java    From AndroidRobot with Apache License 2.0 4 votes vote down vote up
public boolean apply(AccessibleObject ao) {
/* 332 */         return ao.isAnnotationPresent(MonkeyRunnerExported.class);
/*     */       }
 
Example 19
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isCallerSensitive(final AccessibleObject e) {
    return e.isAnnotationPresent(CallerSensitive.class);
}
 
Example 20
Source File: AnnotationDataReader.java    From web-data-extractor with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if annotation is present on
 * given accessible object.
 */
public boolean hasAnnotation(AccessibleObject accessibleObject) {
    return accessibleObject.isAnnotationPresent(annotationClass);
}