Java Class.isEnum Examples

Java Class.isEnum - 30 examples found. These are the top rated real world Java examples of Class.isEnum extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private Set<Class<?>> filterInputClasses(Set<Class<?>> referencedClasses) {
    Set<Class<?>> typesToUse = Sets.newHashSet();
    for (Class<?> beanClass : referencedClasses) {
      if (beanClass.isEnum()) {
        typesToUse.add(beanClass);
        continue;
      }
      if (beanClass.equals(void.class)) {
        continue;
      }
      if (beanClass instanceof Class && beanClass.isEnum()) {
        typesToUse.add(beanClass);
        continue;
      }
      if (beanClass == URI.class) {
        continue;
      }

      // Classes directly passed in to typescript-generator need to be directly serializable, so
      // filter out the ones that serializers
      // exist for.
      SerializationConfig serializationConfig = OBJECT_MAPPER.getSerializationConfig();
      final JavaType simpleType = OBJECT_MAPPER.constructType(beanClass);
      try {
        final JsonSerializer<?> jsonSerializer =
            BeanSerializerFactory.instance.createSerializer(serializationConfig, simpleType, null);
        if (jsonSerializer == null || jsonSerializer instanceof BeanSerializer) {
          typesToUse.add(beanClass);
        }
      } catch (Exception e) {

      }
    }
    return typesToUse;
  }
Example #2
0
 @SuppressWarnings("rawtypes")
 protected Object loadObject(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   Class clazz = getClassAtDepth(field.getGenericType(), depth);
   if (ConfigObject.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     return getConfigObject(clazz, cs.getConfigurationSection(path));
   } else if (Location.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) {
     return getLocation((String) cs.get(path));
   } else if (Vector.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) {
     return getVector((String) cs.get(path));
   } else if (Map.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     return getMap(field, cs.getConfigurationSection(path), path, depth);
   } else if (clazz.isEnum() && isString(cs.get(path))) {
     return getEnum(clazz, (String) cs.get(path));
   } else if (List.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     Class subClazz = getClassAtDepth(field.getGenericType(), depth + 1);
     if (ConfigObject.class.isAssignableFrom(subClazz)
         || Location.class.isAssignableFrom(subClazz)
         || Vector.class.isAssignableFrom(subClazz)
         || Map.class.isAssignableFrom(subClazz)
         || List.class.isAssignableFrom(subClazz)
         || subClazz.isEnum()) {
       return getList(field, cs.getConfigurationSection(path), path, depth);
     } else {
       return cs.get(path);
     }
   } else {
     return cs.get(path);
   }
 }
Example #3
0
 @SuppressWarnings("rawtypes")
 protected Object saveObject(
     Object obj, Field field, ConfigurationSection cs, String path, int depth) throws Exception {
   Class clazz = getClassAtDepth(field.getGenericType(), depth);
   if (ConfigObject.class.isAssignableFrom(clazz) && isConfigObject(obj)) {
     return getConfigObject((ConfigObject) obj, path, cs);
   } else if (Location.class.isAssignableFrom(clazz) && isLocation(obj)) {
     return getLocation((Location) obj);
   } else if (Vector.class.isAssignableFrom(clazz) && isVector(obj)) {
     return getVector((Vector) obj);
   } else if (Map.class.isAssignableFrom(clazz) && isMap(obj)) {
     return getMap((Map) obj, field, cs, path, depth);
   } else if (clazz.isEnum() && isEnum(clazz, obj)) {
     return getEnum((Enum) obj);
   } else if (List.class.isAssignableFrom(clazz) && isList(obj)) {
     Class subClazz = getClassAtDepth(field.getGenericType(), depth + 1);
     if (ConfigObject.class.isAssignableFrom(subClazz)
         || Location.class.isAssignableFrom(subClazz)
         || Vector.class.isAssignableFrom(subClazz)
         || Map.class.isAssignableFrom(subClazz)
         || List.class.isAssignableFrom(subClazz)
         || subClazz.isEnum()) {
       return getList((List) obj, field, cs, path, depth);
     } else {
       return obj;
     }
   } else {
     return obj;
   }
 }
Example #4
0
  /**
   * Checks if the class under test has compliant modifiers compared to the API.
   *
   * @return true if modifiers are compliant.
   */
  private boolean checkClassModifiersCompliance() {
    int reflectionModifier = mClass.getModifiers();
    int apiModifier = mModifier;

    // If the api class isn't abstract
    if (((apiModifier & Modifier.ABSTRACT) == 0)
        &&
        // but the reflected class is
        ((reflectionModifier & Modifier.ABSTRACT) != 0)
        &&
        // and it isn't an enum
        !isEnumType()) {
      // that is a problem
      return false;
    }
    // ABSTRACT check passed, so mask off ABSTRACT
    reflectionModifier &= ~Modifier.ABSTRACT;
    apiModifier &= ~Modifier.ABSTRACT;

    if (isAnnotation()) {
      reflectionModifier &= ~CLASS_MODIFIER_ANNOTATION;
    }
    if (mClass.isInterface()) {
      reflectionModifier &= ~(Modifier.INTERFACE);
    }
    if (isEnumType() && mClass.isEnum()) {
      reflectionModifier &= ~CLASS_MODIFIER_ENUM;
    }

    return ((reflectionModifier == apiModifier) && (isEnumType() == mClass.isEnum()));
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  public static void enterA2Mode() {
    System.err.println("APV::enterA2Mode");
    try {
      Class epdControllerClass = Class.forName("android.hardware.EpdController");
      Class epdControllerRegionClass = Class.forName("android.hardware.EpdController$Region");
      Class epdControllerRegionParamsClass =
          Class.forName("android.hardware.EpdController$RegionParams");
      Class epdControllerWaveClass = Class.forName("android.hardware.EpdController$Wave");

      Object[] waveEnums = null;
      if (epdControllerWaveClass.isEnum()) {
        System.err.println("EpdController Wave Enum successfully retrived.");
        waveEnums = epdControllerWaveClass.getEnumConstants();
      }

      Object[] regionEnums = null;
      if (epdControllerRegionClass.isEnum()) {
        System.err.println("EpdController Region Enum successfully retrived.");
        regionEnums = epdControllerRegionClass.getEnumConstants();
      }

      Constructor RegionParamsConstructor =
          epdControllerRegionParamsClass.getConstructor(
              new Class[] {
                Integer.TYPE,
                Integer.TYPE,
                Integer.TYPE,
                Integer.TYPE,
                epdControllerWaveClass,
                Integer.TYPE
              });

      Object localRegionParams =
          RegionParamsConstructor.newInstance(
              new Object[] {0, 0, 600, 800, waveEnums[2], 16}); // Wave = DU

      Method epdControllerSetRegionMethod =
          epdControllerClass.getMethod(
              "setRegion",
              new Class[] {String.class, epdControllerRegionClass, epdControllerRegionParamsClass});
      epdControllerSetRegionMethod.invoke(
          null, new Object[] {"APV-ReadingView", regionEnums[2], localRegionParams});

      Thread.sleep(100L);
      localRegionParams =
          RegionParamsConstructor.newInstance(
              new Object[] {0, 0, 600, 800, waveEnums[3], 14}); // Wave = A2
      epdControllerSetRegionMethod.invoke(
          null, new Object[] {"APV-ReadingView", regionEnums[2], localRegionParams});

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private static int putEnumTypeInHash(Class<?> type, Hashtable<String, Class<?>> enums) {
    Class<?> flagsType = QFlags.class.isAssignableFrom(type) ? type : null;
    Class<?> enumType = type.isEnum() ? type : null;
    if (enumType == null && flagsType != null) {
      enumType = getEnumForQFlags(flagsType);
    }

    if (enumType == null) return 0;

    // Since Qt supports enums that are not part of the meta object
    // we need to check whether the enum can actually be used in
    // a property.
    Class<?> enclosingClass = enumType.getEnclosingClass();
    if (enclosingClass != null
        && ((!QObject.class.isAssignableFrom(enclosingClass) && !Qt.class.equals(enclosingClass))
            || enumType.isAnnotationPresent(QtBlockedEnum.class))) {
      return -1;
    }

    int enumConstantCount = 0;
    if (!enums.contains(enumType.getName())) {
      enums.put(enumType.getName(), enumType);

      enumConstantCount = enumType.getEnumConstants().length;
    }

    if (flagsType != null && !enums.contains(flagsType.getName()))
      enums.put(flagsType.getName(), flagsType);

    return enumConstantCount;
  }