Example usage for java.lang Class getModifiers

List of usage examples for java.lang Class getModifiers

Introduction

In this page you can find the example usage for java.lang Class getModifiers.

Prototype

@HotSpotIntrinsicCandidate
public native int getModifiers();

Source Link

Document

Returns the Java language modifiers for this class or interface, encoded in an integer.

Usage

From source file:edu.mit.media.funf.config.DefaultRuntimeTypeAdapterFactory.java

public static boolean isTypeInstatiable(Class<?> type) {
    int modifiers = type.getModifiers();
    if (!(Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers))) {
        try {//from   w  ww.jav a  2  s. co  m
            Constructor<?> noArgConstructor = type.getConstructor();
            return Modifier.isPublic(noArgConstructor.getModifiers());
        } catch (SecurityException e) {
        } catch (NoSuchMethodException e) {
        }
    }
    return false;
}

From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java

@SuppressWarnings("unchecked")
public static Class<? extends IInternalNameNode> loadNameNodeType(String typeName)
        throws ClassNotFoundException, ReflectiveOperationException {
    Class<?> givenType = Class.forName(typeName);
    if (!IInternalNameNode.class.isAssignableFrom(givenType) || givenType.isInterface()
            || Modifier.isAbstract(givenType.getModifiers())) {
        throw new IllegalArgumentException(
                typeName + " is not a concrete class deriving from IInternalNameNode");
    }//from   ww w.j av a2  s .co m

    return (Class<? extends IInternalNameNode>) givenType;
}

From source file:li.klass.fhem.testsuite.category.CategorySuite.java

private static Class<?>[] getSuiteClasses() {
    String basePath = getBasePath();
    File basePathFile = new File(basePath);

    Collection javaFiles = FileUtils.listFiles(basePathFile, new String[] { "java" }, true);

    ArrayList<Class<?>> result = new ArrayList<Class<?>>();
    for (Object fileObject : javaFiles) {
        File file = (File) fileObject;
        Class<?> cls = toClass(file, basePath);

        if (cls == null || Modifier.isAbstract(cls.getModifiers())) {
            continue;
        }/*w ww.j  a  va2 s .  co m*/

        result.add(cls);
    }

    return result.toArray(new Class<?>[result.size()]);
}

From source file:name.ikysil.beanpathdsl.dynamic.DynamicBeanPath.java

/**
 * Continue bean path construction from a bean of specified class.
 *
 * @param <T> type of the bean/*from   w ww .j av a 2 s .  co  m*/
 * @param clazz class of the bean
 * @return instance of the bean class instrumented to capture getters and setters invocations
 */
@SuppressWarnings("unchecked")
public static <T> T expr(Class<T> clazz) {
    try {
        T result;
        if (Modifier.isFinal(clazz.getModifiers())) {
            result = clazz.newInstance();
        } else {
            ProxyFactory pf = new ProxyFactory();
            if (clazz.isInterface()) {
                pf.setSuperclass(Object.class);
                pf.setInterfaces(new Class<?>[] { clazz });
            } else {
                pf.setSuperclass(clazz);
            }
            pf.setFilter(new DefaultMethodFilter());
            result = (T) pf.create(new Class<?>[0], new Object[0], new DefaultMethodHandler(clazz));
        }
        return result;
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | IllegalArgumentException
            | InvocationTargetException ex) {
        throw new IllegalStateException(String.format("Can't instantiate %s", clazz.getName()), ex);
    }
}

From source file:org.apache.hadoop.hbase.hbql.impl.Utils.java

public static void checkForDefaultConstructors(final Class clazz) {

    if (!clazz.getName().contains("hadoop"))
        return;/*from   w  w  w.ja v  a 2  s . co  m*/

    if (Modifier.isStatic(clazz.getModifiers()))
        return;

    if (classList.contains(clazz))
        return;
    else
        classList.add(clazz);

    if (!hasDefaultConstructor(clazz))
        System.out.println(clazz.getName() + " is missing null constructor");

    Field[] fields = clazz.getDeclaredFields();

    for (final Field field : fields) {
        Class dclazz = field.getType();
        checkForDefaultConstructors(dclazz);
    }

    fields = clazz.getFields();

    for (final Field field : fields) {
        Class dclazz = field.getType();
        checkForDefaultConstructors(dclazz);
    }
}

From source file:Main.java

/**
 * Method for finding enclosing class for non-static inner classes
 *//*from w w  w. j  a va  2s.  co  m*/
public static Class<?> getOuterClass(Class<?> type) {
    // as above, GAE has some issues...
    try {
        // one more: method locals, anonymous, are not good:
        if (type.getEnclosingMethod() != null) {
            return null;
        }
        if (!Modifier.isStatic(type.getModifiers())) {
            return type.getEnclosingClass();
        }
    } catch (SecurityException e) {
    } catch (NullPointerException e) {
    }
    return null;
}

From source file:gaffer.rest.service.SimpleGraphConfigurationService.java

private static void keepPublicConcreteClasses(final Collection<Class> classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        while (itr.hasNext()) {
            final Class clazz = itr.next();
            if (null != clazz) {
                final int modifiers = clazz.getModifiers();
                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)
                        || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
                    itr.remove();/*from w w  w  .  j a v  a 2  s . c o  m*/
                }
            }
        }
    }
}

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  ww. j  a va 2  s  .co  m
    return !Modifier.isAbstract(clazz.getModifiers());
}

From source file:org.jbpm.instance.migration.MigrationUtils.java

private static boolean isConcreteClass(Class type) {
    return !type.isInterface() && !Modifier.isAbstract(type.getModifiers());
}

From source file:cz.lbenda.common.ClassLoaderHelper.java

@SuppressWarnings("unchecked")
public static List<String> instancesOfClass(Class clazz, List<String> libs, boolean abstractClass,
        boolean interf) {
    List<String> classNames = new ArrayList<>();
    ClassLoader clr = createClassLoader(libs, false);
    List<String> result = new ArrayList<>();
    libs.forEach(lib -> {/* w w w  . j  ava  2 s  . c  o m*/
        try (ZipFile file = new ZipFile(lib)) {
            file.stream().forEach(entry -> {
                if (entry.getName().equals("META-INF/services/" + clazz.getName())) {
                    try {
                        String string = IOUtils.toString(file.getInputStream(entry));
                        String[] lines = string.split("\n");
                        for (String line : lines) {
                            result.add(line.trim());
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                } else if (entry.getName().endsWith(".class")) {
                    String className = entry.getName().substring(0, entry.getName().length() - 6).replace("/",
                            ".");
                    classNames.add(className);
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });

    classNames.forEach(cc -> {
        try {
            Class cla = clr.loadClass(cc);
            if ((interf || !cla.isInterface()) && (abstractClass || !Modifier.isAbstract(cla.getModifiers()))
                    && clazz.isAssignableFrom(cla)) {
                if (!result.contains(cc)) {
                    result.add(cc);
                }
            }
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            /* It's common to try to create class which haven't class which need*/ }
    });
    return result;
}