@Override public boolean isAnnotation() { return this.introspectedClass.isAnnotation(); }
/** Determines if the supplied Class object represents an annotation type. */ static public boolean isAnnotation (Class c) { return c.isAnnotation(); }
/** Determines if the supplied Class object represents an annotation type. */ static public boolean isAnnotation (Class c) { return c.isAnnotation(); }
@Override public boolean isAnnotation() { return type.isAnnotation(); }
@Override public boolean isAnnotation() { return this.introspectedClass.isAnnotation(); }
@SuppressWarnings("unchecked") public IncludeExcludeCriteria(Class<?>... criteria) { for (Class<?> criterium : criteria) if (criterium.isAnnotation()) annotations.add((Class<? extends Annotation>)criterium); else baseClasses.add(criterium); }
/** * @return Null if class might be a bean; type String (that identifies * why it's not a bean) if not */ public static String canBeABeanType(Class<?> type) { // First: language constructs that ain't beans: if (type.isAnnotation()) { return "annotation"; } if (type.isArray()) { return "array"; } if (type.isEnum()) { return "enum"; } if (type.isPrimitive()) { return "primitive"; } // Anything else? Seems valid, then return null; }
/** * <p>Checks if the specified type is permitted as an annotation member.</p> * * <p>The Java language specification only permits certain types to be used * in annotations. These include {@link String}, {@link Class}, primitive * types, {@link Annotation}, {@link Enum}, and single-dimensional arrays of * these types.</p> * * @param type the type to check, {@code null} * @return {@code true} if the type is a valid type to use in an annotation */ public static boolean isValidAnnotationMemberType(Class<?> type) { if (type == null) { return false; } if (type.isArray()) { type = type.getComponentType(); } return type.isPrimitive() || type.isEnum() || type.isAnnotation() || String.class.equals(type) || Class.class.equals(type); }
public boolean checkClass(Class<?> klass) { return !(klass.isInterface() || klass.isArray() || klass.isEnum() || klass.isPrimitive() || klass.isMemberClass() || klass.isAnnotation() || klass.isAnonymousClass()); }
@Override public String[] resolve(Class<?> testClass) { return testClass.isAnnotation() ? new String[] { "@" + testClass.getSimpleName() } : new String[] { testClass.getSimpleName() }; } }
public static boolean isJUnitTest(Class c) { if (!haveJUnit()) { return false; } //only public classes are interesting, so filter out the rest if (!Modifier.isPublic(c.getModifiers()) || c.isInterface() || c.isAnnotation() || c.isEnum()) { return false; } return (junit3 != null && junit3.isTest(c)) || (junit4 != null && junit4.isTest(c)); }
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { Class objClass = object.getClass(); Class[] interfaces = objClass.getInterfaces(); if (interfaces.length == 1 && interfaces[0].isAnnotation()) { Class annotationClass = interfaces[0]; AnnotationType type = AnnotationType.getInstance(annotationClass); Map<String, Method> members = type.members(); JSONObject json = new JSONObject(members.size()); Iterator<Map.Entry<String, Method>> iterator = members.entrySet().iterator(); Map.Entry<String, Method> entry; Object val = null; while (iterator.hasNext()) { entry = iterator.next(); try { val = entry.getValue().invoke(object); } catch (IllegalAccessException e) { // skip } catch (InvocationTargetException e) { // skip } json.put(entry.getKey(), JSON.toJSON(val)); } serializer.write(json); return; } } }
@SuppressWarnings("unchecked") private static Class<? extends Annotation> asAnnotation(Class<?> clazz) { if (clazz.isAnnotation()) { return (Class<? extends Annotation>) clazz; } else { throw new IllegalArgumentException(rootLocaleFormat("%s is not an annotation.", clazz)); } }
private static boolean isProperField(Field field) { if (isStatic(field) || isFinal(field)) { return false; } Class<?> type = field.getType(); return !type.isAnnotation(); }
/** * Creates a factory for an offset mapping that binds an annotation property. * * @param annotationType The annotation type to bind. * @param property The property to bind. * @param <S> The annotation type. * @return A factory for binding a property of the annotation type. */ public static <S extends Annotation> OffsetMapping.Factory<S> of(Class<S> annotationType, String property) { if (!annotationType.isAnnotation()) { throw new IllegalArgumentException("Not an annotation type: " + annotationType); } try { return new OfAnnotationProperty<S>(annotationType, new MethodDescription.ForLoadedMethod(annotationType.getMethod(property))); } catch (NoSuchMethodException exception) { throw new IllegalArgumentException("Cannot find a property " + property + " on " + annotationType, exception); } }
/** * Binds an annotation to a dynamically computed value. Whenever the {@link Advice} component discovers the given annotation on * a parameter of an advice method, the dynamic value is asked to provide a value that is then assigned to the parameter in question. * * @param offsetMapping The dynamic value that is computed for binding the parameter to a value. * @return A new builder for an advice that considers the supplied annotation type during binding. */ public WithCustomMapping bind(OffsetMapping.Factory<?> offsetMapping) { Map<Class<? extends Annotation>, OffsetMapping.Factory<?>> offsetMappings = new HashMap<Class<? extends Annotation>, OffsetMapping.Factory<?>>(this.offsetMappings); if (!offsetMapping.getAnnotationType().isAnnotation()) { throw new IllegalArgumentException("Not an annotation type: " + offsetMapping.getAnnotationType()); } else if (offsetMappings.put(offsetMapping.getAnnotationType(), offsetMapping) != null) { throw new IllegalArgumentException("Annotation type already mapped: " + offsetMapping.getAnnotationType()); } return new WithCustomMapping(offsetMappings); }
/** * Verifies that the actual {@code Class} is an annotation. * * @param info contains information about the assertion. * @param actual the "actual" {@code Class}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Class} is not an annotation. */ public void assertIsAnnotation(AssertionInfo info, Class<?> actual) { assertNotNull(info, actual); if (!actual.isAnnotation()) throw failures.failure(info, shouldBeAnnotation(actual)); }
/** * Verifies that the actual {@code Class} is not an annotation. * * @param info contains information about the assertion. * @param actual the "actual" {@code Class}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Class} is an annotation. */ public void assertIsNotAnnotation(AssertionInfo info, Class<?> actual) { assertNotNull(info, actual); if (actual.isAnnotation()) throw failures.failure(info, shouldNotBeAnnotation(actual)); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Loaded<Annotation> load(ClassLoader classLoader) throws ClassNotFoundException { Class<?> type = Class.forName(annotationToken.getBinaryName(), false, classLoader); if (type.isAnnotation()) { return new ForAnnotationDescription.Loaded<Annotation>(AnnotationDescription.AnnotationInvocationHandler.of(classLoader, (Class<? extends Annotation>) type, annotationToken.getValues())); } else { return new ForAnnotationDescription.IncompatibleRuntimeType(type); } }
public static <E extends Enum<?> & Feature<?>> void assertGoodFeatureEnum( Class<E> featureEnumClass) { final Class<?>[] classes = featureEnumClass.getDeclaredClasses(); for (Class<?> containedClass : classes) { if (containedClass.getSimpleName().equals("Require")) { if (containedClass.isAnnotation()) { assertGoodTesterAnnotation(asAnnotation(containedClass)); } else { fail( rootLocaleFormat( "Feature enum %s contains a class named " + "'Require' but it is not an annotation.", featureEnumClass)); } return; } } fail( rootLocaleFormat( "Feature enum %s should contain an " + "annotation named 'Require'.", featureEnumClass)); }