public static boolean callIsEnumConstant(Field thiz) { return thiz.isEnumConstant(); }
private static String getEnumAsString(Class type) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { StringBuilder builder = new StringBuilder(); Field[] declaredFields = type.getDeclaredFields(); for (Field declaredField : declaredFields) { if (declaredField.isEnumConstant()) { if (builder.length() > 0) { builder.append(','); } builder.append(declaredField.getName()); } } return builder.toString(); }
/** * A method that will look for the first Enum value annotated with the given Annotation. * <p> * If there's more than one value annotated, the first one found will be returned. Which one exactly is used is undetermined. * * @param enumClass The Enum class to scan for a value with the given annotation * @param annotationClass The annotation to look for. * @return the Enum value annotated with the given Annotation or {@code null} if none is found. * @throws IllegalArgumentException if there's a reflection issue accessing the Enum * @since 2.8 */ public static <T extends Annotation> Enum<?> findFirstAnnotatedEnumValue(Class<Enum<?>> enumClass, Class<T> annotationClass) { Field[] fields = getDeclaredFields(enumClass); for (Field field : fields) { if (field.isEnumConstant()) { Annotation defaultValueAnnotation = field.getAnnotation(annotationClass); if (defaultValueAnnotation != null) { final String name = field.getName(); for (Enum<?> enumValue : enumClass.getEnumConstants()) { if (name.equals(enumValue.name())) { return enumValue; } } } } } return null; }
/** * A method that will look for the first Enum value annotated with the given Annotation. * <p> * If there's more than one value annotated, the first one found will be returned. Which one exactly is used is undetermined. * * @param enumClass The Enum class to scan for a value with the given annotation * @param annotationClass The annotation to look for. * @return the Enum value annotated with the given Annotation or {@code null} if none is found. * @throws IllegalArgumentException if there's a reflection issue accessing the Enum * @since 2.8 */ public static <T extends Annotation> Enum<?> findFirstAnnotatedEnumValue(Class<Enum<?>> enumClass, Class<T> annotationClass) { Field[] fields = getDeclaredFields(enumClass); for (Field field : fields) { if (field.isEnumConstant()) { Annotation defaultValueAnnotation = field.getAnnotation(annotationClass); if (defaultValueAnnotation != null) { final String name = field.getName(); for (Enum<?> enumValue : enumClass.getEnumConstants()) { if (name.equals(enumValue.name())) { return enumValue; } } } } } return null; }
HashMap<String,String> expl = null; for (Field f : ClassUtil.getDeclaredFields(enumType)) { if (!f.isEnumConstant()) { continue;
HashMap<String,String> expl = null; for (Field f : ClassUtil.getDeclaredFields(enumType)) { if (!f.isEnumConstant()) { continue;
/** * A method that will look for the first Enum value annotated with the given Annotation. * <p> * If there's more than one value annotated, the first one found will be returned. Which one exactly is used is undetermined. * * @param enumClass The Enum class to scan for a value with the given annotation * @param annotationClass The annotation to look for. * @return the Enum value annotated with the given Annotation or {@code null} if none is found. * @throws IllegalArgumentException if there's a reflection issue accessing the Enum * @since 2.8 */ public static <T extends Annotation> Enum<?> findFirstAnnotatedEnumValue(Class<Enum<?>> enumClass, Class<T> annotationClass) { Field[] fields = getDeclaredFields(enumClass); for (Field field : fields) { if (field.isEnumConstant()) { Annotation defaultValueAnnotation = field.getAnnotation(annotationClass); if (defaultValueAnnotation != null) { final String name = field.getName(); for (Enum<?> enumValue : enumClass.getEnumConstants()) { if (name.equals(enumValue.name())) { return enumValue; } } } } } return null; }
HashMap<String,String> expl = null; for (Field f : ClassUtil.getDeclaredFields(enumType)) { if (!f.isEnumConstant()) { continue;
if ( f.isSynthetic() || f.isEnumConstant() || Modifier.isStatic( f.getModifiers() ) ) {
for (int i = 0; i < fields.length; i++ ) { final Field field = fields[i]; if (field.isEnumConstant() || (field.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) > 0) { continue;
/** * Builds the enum to schema mapping dictionary. * * @param c class type * @return The mapping from enum to schema name */ private static Map<String, String> buildEnumToSchemaDict(Class<?> c) { Map<String, String> dict = new HashMap<String, String>(); Field[] fields = c.getFields(); for (Field f : fields) { if (f.isEnumConstant() && f.isAnnotationPresent(EwsEnum.class)) { EwsEnum ewsEnum = f.getAnnotation(EwsEnum.class); String fieldName = f.getName(); String schemaName = ewsEnum.schemaName(); if (!schemaName.isEmpty()) { dict.put(fieldName, schemaName); } } } return dict; }
/** * Builds the schema to enum mapping dictionary. * * @param <E> Type of the enum. * @param c Class * @return The mapping from enum to schema name */ private static <E extends Enum<E>> Map<String, String> buildSchemaToEnumDict(Class<E> c) { Map<String, String> dict = new HashMap<String, String>(); Field[] fields = c.getDeclaredFields(); for (Field f : fields) { if (f.isEnumConstant() && f.isAnnotationPresent(EwsEnum.class)) { EwsEnum ewsEnum = f.getAnnotation(EwsEnum.class); String fieldName = f.getName(); String schemaName = ewsEnum.schemaName(); if (!schemaName.isEmpty()) { dict.put(schemaName, fieldName); } } } return dict; }
private void generateConstantFromClassField(StringBuilder sb, Class<?> clazz) throws IllegalArgumentException, IllegalAccessException { sb.append("\n#").append(clazz.getSimpleName()); if (clazz.isEnum()) { for (Field f : clazz.getDeclaredFields()) { if (f.isEnumConstant()) { String name = f.getName().toUpperCase(); f.setAccessible(true); String value = f.get(null).toString(); sb.append(String.format("\n%s = '%s'", name, value)); } } } else { for (Field f : clazz.getDeclaredFields()) { PythonClass at = f.getAnnotation(PythonClass.class); if (at == null) { continue; } String name = f.getName().toUpperCase(); f.setAccessible(true); String value = f.get(null).toString(); sb.append(String.format("\n%s = '%s'", name, value)); } } sb.append("\n"); }
/** * Builds the enum dict. * * @param <E> the element type * @param c the c * @return the map */ private static <E extends Enum<E>> Map<String, ExchangeVersion> buildEnumDict(Class<E> c) { Map<String, ExchangeVersion> dict = new HashMap<String, ExchangeVersion>(); Field[] fields = c.getDeclaredFields(); for (Field f : fields) { if (f.isEnumConstant() && f.isAnnotationPresent(RequiredServerVersion.class)) { RequiredServerVersion ewsEnum = f .getAnnotation(RequiredServerVersion.class); String fieldName = f.getName(); ExchangeVersion exchangeVersion = ewsEnum.version(); dict.put(fieldName, exchangeVersion); } } return dict; }
HashMap<String,String> expl = null; for (Field f : ClassUtil.getDeclaredFields(enumType)) { if (!f.isEnumConstant()) { continue;
continue; if (field.isEnumConstant()) { visitEnumValue(field); } else {
public ReflectionEnumConstantDeclaration(Field enumConstant, TypeSolver typeSolver) { if (!enumConstant.isEnumConstant()) { throw new IllegalArgumentException("The given field does not represent an enum constant"); } this.enumConstant = enumConstant; this.typeSolver = typeSolver; }
@Override public boolean matches(final Field field) { final int modifiers = field.getModifiers(); return ((!Modifier.isStatic(modifiers)) && (!field.isEnumConstant()) && (!field.getType().isPrimitive())); } }
/** * Checks if a specified field is a static reference. * * @param field the field to check. * @return true if the field is static reference; false otherwise. */ private static boolean isStaticReference(Field field) { return Modifier.isStatic(field.getModifiers()) && !(field.getType().isPrimitive() || field.isEnumConstant() || field.isSynthetic()); }
private static Stream<Field> getFields(Class<?> c) { return Stream.of(c.getFields()) .filter( field -> !(field.isEnumConstant() || field.isSynthetic() || Modifier.isStatic(field.getModifiers()))); }