Java Code Examples for com.openpojo.reflection.PojoClass#isConcrete()

The following examples show how to use com.openpojo.reflection.PojoClass#isConcrete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstanceFactory.java    From openpojo with Apache License 2.0 6 votes vote down vote up
private static Object doGetInstance(PojoClass pojoClass, Object[] parameters) {
  if (!pojoClass.isConcrete()) {
    throw ReflectionException.getInstance(String.format("[%s] is not a concrete class, can't create new instance", pojoClass));
  }

  Object instance;
  final List<PojoMethod> constructors = pojoClass.getPojoConstructors();
  for (final PojoMethod constructor : constructors) {
    if (areEquivalentParameters(upCast(constructor.getParameterTypes()), getTypes(parameters))) {
      instance = constructor.invoke(null, parameters);
      initializeBusinessKeys(pojoClass, instance);
      return instance;
    }
  }
  throw ReflectionException.getInstance(String.format("No matching constructor for [%s] found using parameters[%s]",
      pojoClass.getClazz(), Arrays.toString(getTypes(parameters))));
}
 
Example 2
Source File: PojoClassImplTest.java    From openpojo with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsInterfaceIsAbstractIsConcrete() {
  final String message = "Class type check failed on [%s], actual class returned [%s], PojoClass returned [%s]!!";
  for (final PojoClass pojoClass : PojoClassFactory.getPojoClassesRecursively(SAMPLE_CLASSES_PKG, null)) {
    final Class<?> actualClass = pojoClass.getClazz();
    Affirm.affirmTrue(String.format(message, actualClass.getName() + ".isInterface()", actualClass.isInterface(),
        pojoClass.isInterface()), pojoClass.isInterface() == actualClass.isInterface());
    Affirm.affirmTrue(String.format(message, actualClass.getName() + ".isAbstract()",
        Modifier.isAbstract(actualClass.getModifiers())
            && !Modifier.isInterface(actualClass.getModifiers()), pojoClass.isAbstract()),
        pojoClass.isAbstract() == (Modifier.isAbstract(actualClass.getModifiers())
            && !Modifier.isInterface(actualClass.getModifiers())));

    final boolean expectedValue = !(Modifier.isAbstract(actualClass.getModifiers())
        || actualClass.isInterface()
        || actualClass.isEnum());
    final boolean actualValue = pojoClass.isConcrete();
    Affirm.affirmTrue(String.format(message, actualClass.getName() + ".isConcrete()", expectedValue, actualValue),
        actualValue == expectedValue);
  }
}
 
Example 3
Source File: TestClassMustBeProperlyNamedRule.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void evaluate(PojoClass pojoClass) {
  if (!pojoClass.isConcrete() || properlyNamed(pojoClass))
    return;

  for (Class<? extends Annotation> annotation : loadedAnnotations) {
    if (isAnnotatedOrParentAnnotated(pojoClass, annotation)) {
      Affirm.fail("Test class [" + pojoClass.getName() + "] does not start with " + prefixes.toString() + " or ends with "
          + suffixes.toString());
    }
  }
}
 
Example 4
Source File: FilterNonConcrete.java    From openpojo with Apache License 2.0 4 votes vote down vote up
public boolean include(final PojoClass pojoClass) {
  return pojoClass.isConcrete();
}