@Override public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return accessibleObject.isAnnotationPresent(annotationClass); }
/** * Returns <code>true</code> if annotation is present on * given accessible object. */ public boolean hasAnnotation(AccessibleObject accessibleObject) { return accessibleObject.isAnnotationPresent(annotationClass); }
@Override public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return accessibleObject.isAnnotationPresent(annotationClass); }
@Override public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return accessibleObject.isAnnotationPresent(annotationClass); }
for (Method method : testClass.getMethods()) { if (method.isAnnotationPresent(InstallerMethod.class)) { // do something } }
@Override public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return accessibleObject.isAnnotationPresent(annotationClass); }
public boolean callAccessibleObjectIsAnnotationPresent(AccessibleObject m, Class<? extends Annotation> annotClass) { return m.isAnnotationPresent(annotClass); }
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return accessible.isAnnotationPresent(annotationClass); } public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { return accessible.getAnnotation(annotationClass); }
int getMyVariable(Foo foo) throws IllegalArgumentException, IllegalAccessException{ for(Field f:foo.getClass().getDeclaredFields()){ /** * Ensure the RetentionPolicy of 'MyAnnotation' is RUNTIME. */ if(f.isAnnotationPresent(MyAnnotation.class)){ return f.getInt(foo); } } return -1; }
Method[] methods = TestClass.class.getMethods(); for (Method m : methods) { if (m.isAnnotationPresent(TestAnnotation.class)) { TestAnnotation ta = m.getAnnotation(TestAnnotation.class); System.out.println(ta.testText()); } }
private static boolean isManagedAttribute(AccessibleObject object) { return object.isAnnotationPresent(ManagedAttribute.class) || (object.isAnnotationPresent(Property.class) && object.getAnnotation(Property.class).exposeAsManagedAttribute()); } }
public static List<Method> getMethodsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) { final List<Method> methods = new ArrayList<Method>(); Class<?> klass = type; while (klass != Object.class) { // need to iterated thought hierarchy in order to retrieve methods from above the current instance // iterate though the list of methods declared in the class represented by klass variable, and add those annotated with the specified annotation final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(klass.getDeclaredMethods())); for (final Method method : allMethods) { if (method.isAnnotationPresent(annotation)) { Annotation annotInstance = method.getAnnotation(annotation); // TODO process annotInstance methods.add(method); } } // move to the upper class in the hierarchy in search for more methods klass = klass.getSuperclass(); } return methods; }
public static List<Method> getMethodsAnnotatedWithMethodXY(final Class<?> type) { final List<Method> methods = new ArrayList<Method>(); Class<?> klass = type; while (klass != Object.class) { // need to iterated thought hierarchy in order to retrieve methods from above the current instance // iterate though the list of methods declared in the class represented by klass variable, and add those annotated with the specified annotation final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(klass.getDeclaredMethods())); for (final Method method : allMethods) { if (method.isAnnotationPresent(MethodXY.class)) { MethodXY annotInstance = method.getAnnotation(MethodXY.class); if (annotInstance.x() == 3 && annotInstance.y() == 2) { methods.add(method); } } } // move to the upper class in the hierarchy in search for more methods klass = klass.getSuperclass(); } return methods; }
@Override public String getName() { if (this.accessible.isAnnotationPresent(ManagedAttribute.class)) { String name = this.accessible.getAnnotation(ManagedAttribute.class).name(); if (!name.isEmpty()) return name; } if (this.accessible.isAnnotationPresent(Property.class)) { String name = this.accessible.getAnnotation(Property.class).name(); if (!name.isEmpty()) return name; } return null; }
@Override public String getDescription() { if (this.accessible.isAnnotationPresent(ManagedAttribute.class)) { return this.accessible.getAnnotation(ManagedAttribute.class).description(); } if (this.accessible.isAnnotationPresent(Property.class)) { return this.accessible.getAnnotation(Property.class).description(); } return this.accessible.toString(); }
private static String annotatedName(AccessibleObject obj) { if (obj.isAnnotationPresent(PropertyName.class)) { PropertyName annotation = obj.getAnnotation(PropertyName.class); return annotation.value(); } return null; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getDeclaringClass() == Foo.class && !method.isAnnotationPresent(BypassCheck.class) // no magic strings && !this.fooImpl.getEnabled()) {
private boolean isProcessingId(XMLContext.Default defaults) { boolean isExplicit = defaults.getAccess() != null; boolean correctAccess = ( PropertyType.PROPERTY.equals( propertyType ) && AccessType.PROPERTY.equals( defaults.getAccess() ) ) || ( PropertyType.FIELD.equals( propertyType ) && AccessType.FIELD .equals( defaults.getAccess() ) ); boolean hasId = defaults.canUseJavaAnnotations() && ( isPhysicalAnnotationPresent( Id.class ) || isPhysicalAnnotationPresent( EmbeddedId.class ) ); //if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) { boolean mirrorAttributeIsId = defaults.canUseJavaAnnotations() && ( mirroredAttribute != null && ( mirroredAttribute.isAnnotationPresent( Id.class ) || mirroredAttribute.isAnnotationPresent( EmbeddedId.class ) ) ); boolean propertyIsDefault = PropertyType.PROPERTY.equals( propertyType ) && !mirrorAttributeIsId; return correctAccess || ( !isExplicit && hasId ) || ( !isExplicit && propertyIsDefault ); }
@Override public boolean test(final AccessibleObject a) { return a.isAnnotationPresent(this.clazz); }
final public class DirtyChecker { public boolean process(Object instance) { Class<?> clazz = instance.getClass(); for(Method m: clazz.getDeclaredMethods()) { if(m.isAnnotationPresent(DirtyCheck.class)) { DirtyCheck annotation = m.getAnnotation(DirtyCheck.class); String newVal = annotation.newValue(); String oldVal = annotation.oldValue(); return newVal.equals(oldVal); } return false; } }