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:Main.java

public static void main(String[] args) throws Exception {
    Class<?> clazz = String.class;
    int modifier = clazz.getModifiers();

    if (Modifier.isAbstract(modifier)) {
        System.out.println("isAbstract");
    }/* w  w  w  .  j a v  a2 s.com*/
}

From source file:grails.util.RunTests.java

public static void main(String[] args) {
    int exitCode = 0;
    try {// ww w.j a va 2s .c om
        log.info("Bootstrapping Grails from classpath");
        ConfigurableApplicationContext appCtx = (ConfigurableApplicationContext) GrailsUtil
                .bootstrapGrailsFromClassPath();
        GrailsApplication application = (GrailsApplication) appCtx.getBean(GrailsApplication.APPLICATION_ID);

        Class[] allClasses = application.getAllClasses();
        log.debug("Going through [" + allClasses.length + "] classes");
        TestSuite s = new TestSuite();
        for (int i = 0; i < allClasses.length; i++) {
            Class clazz = allClasses[i];
            if (TestCase.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
                log.debug("Adding test [" + clazz.getName() + "]");
                s.addTest(new GrailsTestSuite(appCtx, clazz));
            } else {
                log.debug("[" + clazz.getName() + "] is not a test case.");
            }
        }
        String[] beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor.class);
        PersistenceContextInterceptor interceptor = null;
        if (beanNames.length > 0) {
            interceptor = (PersistenceContextInterceptor) appCtx.getBean(beanNames[0]);
        }

        try {
            if (interceptor != null) {
                interceptor.init();
            }
            TestResult r = TestRunner.run(s);
            exitCode = r.errorCount() + r.failureCount();
            if (exitCode > 0) {
                System.err.println("Tests failed!");
            }
            if (interceptor != null)
                interceptor.flush();
        } finally {
            if (interceptor != null)
                interceptor.destroy();
        }
    } catch (Exception e) {
        log.error("Error executing tests: " + e.getMessage(), e);
        exitCode = 1;
    } finally {
        System.exit(exitCode);
    }
}

From source file:at.tuwien.ifs.somtoolbox.doc.RunnablesReferenceCreator.java

public static void main(String[] args) {
    ArrayList<Class<? extends SOMToolboxApp>> runnables = SubClassFinder.findSubclassesOf(SOMToolboxApp.class,
            true);//from w w w. j ava  2s  . com
    Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR);

    StringBuilder sbIndex = new StringBuilder(runnables.size() * 50);
    StringBuilder sbDetails = new StringBuilder(runnables.size() * 200);

    sbIndex.append("\n<table border=\"0\">\n");

    Type lastType = null;

    for (Class<? extends SOMToolboxApp> c : runnables) {
        try {
            // Ignore abstract classes and interfaces
            if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) {
                continue;
            }

            Type type = Type.getType(c);
            if (type != lastType) {
                sbIndex.append("  <tr> <td colspan=\"2\"> <h5> " + type + " Applications </h5> </td> </tr>\n");
                sbDetails.append("<h2> " + type + " Applications </h2>\n");
                lastType = type;
            }
            String descr = "N/A";
            try {
                descr = (String) c.getDeclaredField("DESCRIPTION").get(null);
            } catch (Exception e) {
            }
            String longDescr = "descr";
            try {
                longDescr = (String) c.getDeclaredField("LONG_DESCRIPTION").get(null);
            } catch (Exception e) {
            }

            sbIndex.append("  <tr>\n");
            sbIndex.append("    <td> <a href=\"#").append(c.getSimpleName()).append("\">")
                    .append(c.getSimpleName()).append("</a> </td>\n");
            sbIndex.append("    <td> ").append(descr).append(" </td>\n");
            sbIndex.append("  </tr>\n");

            sbDetails.append("<h3 id=\"").append(c.getSimpleName()).append("\">").append(c.getSimpleName())
                    .append("</h3>\n");
            sbDetails.append("<p>").append(longDescr).append("</p>\n");

            try {
                Parameter[] options = (Parameter[]) c.getField("OPTIONS").get(null);
                JSAP jsap = AbstractOptionFactory.registerOptions(options);
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                PrintStream ps = new PrintStream(os);
                AbstractOptionFactory.printHelp(jsap, c.getName(), ps);
                sbDetails.append("<pre>").append(StringEscapeUtils.escapeHtml(os.toString())).append("</pre>");
            } catch (Exception e1) { // we didn't find the options => let the class be invoked ...
            }

        } catch (SecurityException e) {
            // Should not happen - no Security
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    sbIndex.append("</table>\n\n");
    System.out.println(sbIndex);
    System.out.println(sbDetails);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static boolean isAbstractClass(Class clazz) {
    int modifier = clazz.getModifiers();
    return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier);
}

From source file:Main.java

private static void getClassModifier(Class clazz) {
    int modifier = clazz.getModifiers();

    if (Modifier.isAbstract(modifier)) {
        System.out.println(clazz.getName() + " class modifier is abstract");
    }/*from  ww  w. ja v a  2s. c o m*/
}

From source file:ModifierUtil.java

public static boolean isAbstract(Member member) {
    return Modifier.isAbstract(member.getModifiers());
}

From source file:ModifierUtil.java

public static boolean isAbstract(Class<?> clazz) {
    return Modifier.isAbstract(clazz.getModifiers());
}

From source file:DeclarationInfoDemo.java

public static void printModifiers(final Class dataType) {
    final int modifiers = dataType.getModifiers();
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }/*from  ww  w. j a v a  2s .c  o  m*/
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isPublic(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isAbstract(modifiers)) {
        System.out.print("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        System.out.print("final ");
    }
    if (Modifier.isNative(modifiers)) {
        System.out.print("native ");
    }
    if (Modifier.isInterface(modifiers)) {
        System.out.print("interface ");
    }
    if (Modifier.isStatic(modifiers)) {
        System.out.print("static ");
    }
    if (Modifier.isStrict(modifiers)) {
        System.out.print("strict ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        System.out.print("synchronized ");
    }
    if (Modifier.isTransient(modifiers)) {
        System.out.print("transient ");
    }
    if (Modifier.isVolatile(modifiers)) {
        System.out.print("volatile ");
    }
    System.out.println(dataType.getName());
}

From source file:org.openlegacy.utils.ClassUtils.java

public static boolean isAbstract(Class<?> cls) {
    return Modifier.isAbstract(cls.getModifiers());
}

From source file:Main.java

private static Set<Method> findMethodsCompatibleWith(boolean staticMethod, Set<Method> methods,
        String methodName, Class<?>[] argTypes) {
    final Set<Method> list = new HashSet<Method>(methods);
    for (final Iterator<Method> it = list.iterator(); it.hasNext();) {
        final Method method = it.next();
        if (!methodName.equals(method.getName())) {
            it.remove();/* ww  w. j  a  va  2s  .c o m*/
            continue;
        }
        if (argTypes.length != method.getParameterTypes().length) {
            it.remove();
            continue;
        }
        if (Modifier.isAbstract(method.getModifiers())
                || Modifier.isStatic(method.getModifiers()) != staticMethod) {
            it.remove();
            continue;
        }
        if (!isMethodArgCompatible(method, argTypes)) {
            it.remove();
            continue;
        }

    }
    return list;
}