Java Class.getModifiers Examples

Java Class.getModifiers - 30 examples found. These are the top rated real world Java examples of Class.getModifiers extracted from open source projects. You can rate examples to help us improve the quality of examples.
 @SuppressWarnings("rawtypes")
 private <O extends Operator> O newInstance(Class<O> c) {
   if (c.isInterface()) {
     return null;
   }
   if (Modifier.isAbstract(c.getModifiers())) {
     return null;
   }
   final Class<?>[] paramTypes;
   final Object[] args;
   if (Modifier.isStatic(c.getModifiers())) {
     paramTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
     args = ArrayUtils.EMPTY_OBJECT_ARRAY;
   } else {
     paramTypes = new Class[] {getClass()};
     args = new Object[] {this};
   }
   final Constructor<O> cs = ConstructorUtils.getMatchingAccessibleConstructor(c, paramTypes);
   if (cs == null) {
     return null;
   }
   try {
     return cs.newInstance(args);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  boolean applyArgoController(Class<?> clazz, Pattern controllerPattern) {

    return ArgoController.class.isAssignableFrom(clazz)
        && controllerPattern.matcher(clazz.getName()).matches()
        && !Modifier.isInterface(clazz.getModifiers())
        && !Modifier.isAbstract(clazz.getModifiers())
        && Modifier.isPublic(clazz.getModifiers());
  }
Example #3
0
 /**
  * Retrieve the names of all the public static classes in the clazz
  *
  * @param clazz the object to inspect
  * @return list of all the names of public statics
  */
 public String[] getPublicStaticClassNames(Class<?> clazz) {
   Class<?>[] classes = clazz.getClasses();
   Set<String> classNames = new HashSet<String>();
   for (Class<?> clazz2 : classes) {
     if (Modifier.isPublic(clazz2.getModifiers()) && Modifier.isStatic(clazz2.getModifiers())) {
       classNames.add(clazz2.getSimpleName());
     }
   }
   return (String[]) classNames.toArray(new String[classNames.size()]);
 }
Example #4
0
 public static TypeImpl getIterableImpl(Class<?> iterClass) {
   if (iterClass == List.class || iterClass == Collection.class || iterClass == Iterable.class) {
     return new TypeImpl(iterClass, ArrayList.class);
   } else if (Modifier.isAbstract(iterClass.getModifiers())
       || Modifier.isInterface(iterClass.getModifiers())) {
     throw new RuntimeException(
         "Cannot find appropriate implementation of collection type: " + iterClass.getName());
   }
   return new TypeImpl(iterClass, iterClass);
 }
  /**
   * Does basic sanity checks to make sure the constructor can be properly invoked by our generated
   * class.
   *
   * @param clazz
   */
  private void validateClass(Class<? extends DataSerializable> clazz) {
    Assert.isTrue(
        !Modifier.isAbstract(clazz.getModifiers()), "Cannot instantiate abstract classes");
    Assert.isTrue(Modifier.isPublic(clazz.getModifiers()), "Only public classes are supported");
    try {
      Constructor<? extends DataSerializable> ctor = clazz.getConstructor();
      Assert.isTrue(Modifier.isPublic(ctor.getModifiers()), "Default constructor is not public");

    } catch (Exception ex) {
      throw new IllegalArgumentException("Class " + clazz + " unsuitable for instantiation", ex);
    }
  }
 public void test_immutable() throws Exception {
   Class<CopticChronology> cls = CopticChronology.class;
   assertTrue(Modifier.isPublic(cls.getModifiers()));
   assertTrue(Modifier.isFinal(cls.getModifiers()));
   Field[] fields = cls.getDeclaredFields();
   for (Field field : fields) {
     if (Modifier.isStatic(field.getModifiers()) == false) {
       assertTrue(Modifier.isPrivate(field.getModifiers()));
       assertTrue(Modifier.isFinal(field.getModifiers()));
     }
   }
 }