Example usage for java.lang.reflect Modifier isAbstract

List of usage examples for java.lang.reflect Modifier isAbstract

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isAbstract.

Prototype

public static boolean isAbstract(int mod) 

Source Link

Document

Return true if the integer argument includes the abstract modifier, false otherwise.

Usage

From source file:org.blocks4j.reconf.client.elements.ConfigurationItemElement.java

public static List<ConfigurationItemElement> from(ConfigurationRepositoryElement repository) {
    List<ConfigurationItemElement> result = new ArrayList<ConfigurationItemElement>();

    for (Method method : repository.getInterfaceClass().getMethods()) {
        if (Modifier.isAbstract(method.getModifiers())) {
            checkAnnotations(method);/*from  www  . j av a 2s .  c  om*/

            ConfigurationItem ann = method.getAnnotation(ConfigurationItem.class);

            if (ann != null) {
                result.add(createConfigurationItemElement(repository, method, ann));
            }
        }
    }

    return result;
}

From source file:com.yahoo.flowetl.core.util.KlassUtils.java

/**
 * Checks if a class is abstract.//  w w w.  j a va2s.  c om
 * 
 * @param klass
 *            the class to check
 * @return true, if it is an abstract class
 */
public static boolean isAbstract(Class<?> klass) {
    int modifiers = klass.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
        return true;
    }
    return false;
}

From source file:jenkins.plugins.git.MethodUtils.java

/**
 * Checks if the  method defined on the base type with the given arguments
 * are overridden in the given derived type.
 *//*  w w  w. java  2s  . c  o m*/
// TODO replace with core utility method once JENKINS-30002 is available in base version of Jenkins
static boolean isOverridden(@Nonnull Class base, @Nonnull Class derived, @Nonnull String methodName,
        @Nonnull Class... types) {
    Method baseMethod = getMethodImpl(base, methodName, types);
    Method derivedMethod = getMethodImpl(derived, methodName, types);
    return baseMethod == null ? derivedMethod != null && !Modifier.isAbstract(derivedMethod.getModifiers())
            : !baseMethod.equals(derivedMethod);
}

From source file:info.magnolia.objectfactory.Classes.java

public static boolean isConcrete(Class<?> clazz) {
    if (clazz == null) {
        // null class is not concrete .... ever
        return false;
    }/*from  w w  w.  j a v a 2  s. c o  m*/
    return !Modifier.isAbstract(clazz.getModifiers());
}

From source file:net.paslavsky.springrest.SpringRestClientAOPAdvisor.java

@Override
public boolean matches(Method method, Class<?> targetClass) {
    return !ReflectionUtils.isObjectMethod(method) && Modifier.isAbstract(method.getModifiers());
}

From source file:Main.java

public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass)
        throws ClassNotFoundException {
    Class<?> firstCls = obj.getClass();
    Long unoTypePtr = unoTypes.get(firstCls.getName());
    if (unoTypePtr != null) {
        return (long) unoTypePtr;
    } else {//from   www .  java  2 s .  c  o m
        if (typeHasFallbackClass) {
            Class<?> itf = unoFallbacks.get(fallbackTypePtr);
            if (itf == null) {
                throw new ClassNotFoundException(
                        "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr);
            }
            Class<?> currentCls = firstCls;
            while (true) {
                if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        unoTypes.put(firstCls.getName(), potential);
                        return (long) potential;
                    }
                } else {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
            }
        } else {
            Class<?> currentCls = firstCls;
            while (true) {
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                } else {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        if (Modifier.isAbstract(currentCls.getModifiers())) {
                            Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls);
                            if (fallbackClassPtr != null) {
                                unoTypes.put(firstCls.getName(), fallbackClassPtr);
                                return fallbackClassPtr;
                            }
                        } else {
                            unoTypes.put(firstCls.getName(), potential);
                            return (long) potential;
                        }
                    }
                }
            }
        }
    }
}

From source file:stormy.pythian.service.description.ClassRepository.java

public Set<Class<? extends Component>> getComponentClasses() {
    return filter(reflections.getSubTypesOf(Component.class), new Predicate<Class<?>>() {
        public boolean apply(Class<?> input) {
            return !Modifier.isAbstract(input.getModifiers());
        }//from  ww  w. j  ava 2  s.co m
    });
}

From source file:net.radai.beanz.util.ReflectionUtil.java

public static Collection<?> instantiateCollection(Class<?> collectionClass) {
    if (!Collection.class.isAssignableFrom(collectionClass)) {
        throw new IllegalArgumentException();
    }/*w  ww .  j  a v  a  2s .  co m*/
    if (!Modifier.isAbstract(collectionClass.getModifiers())) {
        try {
            //noinspection unchecked
            return (Collection<?>) collectionClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
    if (List.class.isAssignableFrom(collectionClass)) {
        return new ArrayList<>();
    }
    if (Set.class.isAssignableFrom(collectionClass)) {
        return new HashSet<>();
    }
    throw new UnsupportedOperationException();
}

From source file:org.evosuite.setup.TestUsageChecker.java

public static boolean canUse(Constructor<?> c) {

    if (c.isSynthetic()) {
        return false;
    }// w w w.j  av  a  2s  .c om

    // synthetic constructors are OK
    if (Modifier.isAbstract(c.getDeclaringClass().getModifiers()))
        return false;

    // TODO we could enable some methods from Object, like getClass
    //if (c.getDeclaringClass().equals(java.lang.Object.class))
    //   return false;// handled here to avoid printing reasons

    if (c.getDeclaringClass().equals(java.lang.Thread.class))
        return false;// handled here to avoid printing reasons

    if (c.getDeclaringClass().isAnonymousClass())
        return false;

    if (c.getDeclaringClass().isLocalClass()) {
        logger.debug("Skipping constructor of local class " + c.getName());
        return false;
    }

    if (c.getDeclaringClass().isMemberClass() && !TestUsageChecker.canUse(c.getDeclaringClass()))
        return false;

    if (!Properties.USE_DEPRECATED && c.isAnnotationPresent(Deprecated.class)) {
        final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
        if (Properties.hasTargetClassBeenLoaded() && !c.getDeclaringClass().equals(targetClass)) {
            logger.debug("Excluding deprecated constructor " + c.getName());
            return false;
        }
    }

    if (isForbiddenNonDeterministicCall(c)) {
        return false;
    }

    if (Modifier.isPublic(c.getModifiers())) {
        TestClusterUtils.makeAccessible(c);
        return true;
    }

    for (java.lang.reflect.Type paramType : c.getGenericParameterTypes()) {
        if (!canUse(paramType))
            return false;
    }

    // If default access rights, then check if this class is in the same package as the target class
    if (!Modifier.isPrivate(c.getModifiers())) {
        //              && !Modifier.isProtected(c.getModifiers())) {
        String packageName = ClassUtils.getPackageName(c.getDeclaringClass());
        if (packageName.equals(Properties.CLASS_PREFIX)) {
            TestClusterUtils.makeAccessible(c);
            return true;
        }
    }

    return false;
}

From source file:org.cruxframework.crux.core.ioc.IocContainerManager.java

public synchronized static void initialize() {
    if (!initialized) {
        initialized = true;//from w  ww  .  ja  v  a  2s . com
        try {
            Set<String> configurations = ClassScanner.searchClassesByInterface(IocConfiguration.class);
            if (configurations != null) {
                for (String configurationClassName : configurations) {
                    Class<?> configurationClass = Class.forName(configurationClassName);
                    if (!Modifier.isAbstract(configurationClass.getModifiers())
                            && IocContainerConfigurations.class.isAssignableFrom(configurationClass)) {
                        IocContainerConfigurations configuration = (IocContainerConfigurations) configurationClass
                                .newInstance();
                        if (configuration.isEnabled()) {
                            if (logger.isInfoEnabled()) {
                                logger.info("Configuring new ioc module [" + configurationClassName + "]...");
                            }
                            configuration.configure();
                        }
                    }
                }
            }

            configureAnnotatedClasses();
        } catch (Exception e) {
            logger.error("Error initializing ioc container.", e);
        }
    }
}