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:gemlite.core.util.Util.java

public final static boolean isAbstractFunction(Class<?> c) {
    int modifiers = c.getModifiers();
    return Modifier.isAbstract(modifiers);
}

From source file:gemlite.core.util.Util.java

public final static boolean isPublicFunction(Class<?> c) {
    int modifiers = c.getModifiers();
    return Modifier.isPublic(modifiers);
}

From source file:com.crudetech.junit.categories.Categories.java

static Class<?>[] allTestClassesInClassPathMatchingPattern(String pattern) throws InitializationError {
    List<Class<?>> classes = new ArrayList<Class<?>>();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metaDataReaderFactory = new CachingMetadataReaderFactory();
    try {//from ww  w . j  a v a2 s. com
        String classPattern = "classpath:" + pattern.replace('.', '/') + ".class";
        Resource[] res = resolver.getResources(classPattern);
        for (Resource r : res) {
            if (!r.isReadable()) {
                continue;
            }
            MetadataReader reader = metaDataReaderFactory.getMetadataReader(r);
            Class<?> c = Class.forName(reader.getClassMetadata().getClassName());

            if (Modifier.isAbstract(c.getModifiers())) {
                continue;
            }
            classes.add(c);
        }
        return classes.toArray(new Class<?>[classes.size()]);
    } catch (Exception e) {
        throw new InitializationError(e);
    }
}

From source file:org.robobinding.util.MethodUtils.java

/**
 * <p>//from   w  ww .  ja  v a2 s  . co  m
 * Returns an accessible method (that is, one that can be invoked via
 * reflection) that implements the specified Method. If no such method can
 * be found, return <code>null</code>.
 * </p>
 * 
 * @param method
 *            The method that we wish to call
 * @return The accessible method
 */
public static Method getAccessibleMethod(Method method) {
    if (!MemberUtils.isAccessible(method)) {
        return null;
    }
    // If the declaring class is public, we are done
    final Class<?> cls = method.getDeclaringClass();
    if (Modifier.isPublic(cls.getModifiers())) {
        return method;
    }
    final String methodName = method.getName();
    final Class<?>[] parameterTypes = method.getParameterTypes();

    // Check the implemented interfaces and subinterfaces
    method = getAccessibleMethodFromInterfaceNest(cls, methodName, parameterTypes);

    // Check the superclass chain
    if (method == null) {
        method = getAccessibleMethodFromSuperclass(cls, methodName, parameterTypes);
    }
    return method;
}

From source file:com.curl.orb.security.RemoteServiceAnnotationChecker.java

/**
 * Check the PublicService annotation. Throw AccessException if false.
 * /*from w w  w. j a va2  s  .  co m*/
 * @param cls the class
 * @throws AccessException
 */
public static void check(Class<?> cls, Environment environment) throws AccessException {
    // ignore security
    if (environment == null)
        return;

    RemoteService remoteServiceAnnotation = (RemoteService) cls.getAnnotation(RemoteService.class);
    if (!Modifier.isPublic(cls.getModifiers()) || remoteServiceAnnotation == null
            || !environment.contain(remoteServiceAnnotation.value())) {
        Log log = LogFactory.getLog(RemoteServiceAnnotationChecker.class);
        log.debug("Cannot allow to access the class [" + cls.getName() + "]");
        throw new AccessException("Cannot allow to access the class [" + cls.getName() + "]");
    }
    // TODO: Cache the class(cls). Which is faster, cache or annotation?
}

From source file:ru.runa.af.web.system.TaskHandlerClassesInformation.java

private static void searchInJar(String jarName, JarInputStream jarInputStream) throws IOException {
    boolean matches = false;
    for (String patternFileName : BotStationResources.getTaskHandlerJarNames()) {
        if (FilenameUtils.wildcardMatch(jarName, patternFileName)) {
            matches = true;/*from  w  w  w. j av  a  2 s .co  m*/
            break;
        }
    }
    if (!matches) {
        log.debug("Ignored " + jarName);
        return;
    }
    log.info("Searching in " + jarName);
    ZipEntry entry;
    while ((entry = jarInputStream.getNextEntry()) != null) {
        if (entry.getName().endsWith(".class")) {
            try {
                String className = entry.getName();
                int lastIndexOfDotSymbol = className.lastIndexOf('.');
                className = className.substring(0, lastIndexOfDotSymbol).replace('/', '.');
                // If we can't load class - just move to next class.
                Class<?> someClass = ClassLoaderUtil.loadClass(className);
                if (TaskHandler.class.isAssignableFrom(someClass)
                        && !Modifier.isAbstract(someClass.getModifiers())) {
                    taskHandlerImplementationClasses.add(someClass.getCanonicalName());
                }
            } catch (Throwable e) {
                log.warn("Error on loading task handler for " + e.getMessage());
            }
        }
    }
}

From source file:org.grouplens.grapht.util.Types.java

/**
 * <p>//from  www.  j ava 2s.  c  om
 * Return true if the type is not abstract and not an interface. This will
 * return true essentially when the class "should" have a default
 * constructor or a constructor annotated with {@link Inject @Inject} to be
 * used properly.
 * <p>
 * As another special rule, if the input type is {@link Void}, false is
 * returned because for most intents and purposes, it is not instantiable.
 * 
 * @param type The type to test
 * @return True if it should be instantiable
 */
public static boolean shouldBeInstantiable(Class<?> type) {
    return !Modifier.isAbstract(type.getModifiers()) && !type.isInterface() && !Void.class.equals(type);
}

From source file:com.alta189.bukkit.script.event.EventScanner.java

public static void scanBukkit() {
    Reflections reflections = new Reflections(new ConfigurationBuilder()
            .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.bukkit")))
            .setUrls(ClasspathHelper.forClassLoader(ClasspathHelper.contextClassLoader(),
                    ClasspathHelper.staticClassLoader())));

    Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class);

    BScript plugin = BScript.getInstance();
    plugin.info(/*from w  w w .j  a  v a 2s . c o  m*/
            "Found " + classes.size() + " classes extending " + Event.class.getCanonicalName() + " in Bukkit");
    for (Class<? extends Event> clazz : classes) {
        if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
            continue;
        }
        bukkitEvent.put(clazz.getSimpleName(), clazz);

        String className = clazz.getCanonicalName();
        if (className == null) {
            className = clazz.getName();
        }
        events.put(className, clazz);
        simpleNameEvents.put(clazz.getSimpleName(), clazz);
        plugin.debug(className);
    }
}

From source file:com.discovery.darchrow.lang.ClassUtil.java

/**
 * ??.//from w w  w . j av a2  s.  com
 * 
 * @param ownerClass
 *            class
 * @return true
 * @see java.lang.Class#getModifiers()
 * @see java.lang.reflect.Modifier#isInterface(int)
 */
public static boolean isInterface(Class<?> ownerClass) {
    // ?? Java 
    int flag = ownerClass.getModifiers();
    // ??
    return Modifier.isInterface(flag);
}

From source file:alluxio.cli.CommandUtils.java

/**
 * Get instances of all subclasses of {@link Command} in a sub-package called "command" the given
 * package./*w w  w.ja va2s  . c om*/
 *
 * @param pkgName package prefix to look in
 * @param classArgs type of args to instantiate the class
 * @param objectArgs args to instantiate the class
 * @return a mapping from command name to command instance
 */
public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) {
    Map<String, Command> commandsMap = new HashMap<>();
    Reflections reflections = new Reflections(Command.class.getPackage().getName());
    for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
        // Add commands from <pkgName>.command.*
        if (cls.getPackage().getName().equals(pkgName + ".command")
                && !Modifier.isAbstract(cls.getModifiers())) {
            // Only instantiate a concrete class
            Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs);
            commandsMap.put(cmd.getCommandName(), cmd);
        }
    }
    return commandsMap;
}