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.codehaus.groovy.grails.commons.metaclass.BaseApiProvider.java

private boolean isNotExcluded(Method method, final int modifiers) {
    final String name = method.getName();

    if (EXCLUDED_METHODS.contains(name))
        return false;

    boolean isStatic = Modifier.isStatic(modifiers);

    // skip plain setters/getters by default for instance methods (non-static)
    if (!isStatic && (GrailsClassUtils.isSetter(name, method.getParameterTypes())
            || GrailsClassUtils.isGetter(name, method.getParameterTypes()))) {
        return false;
    }/*  ww w .j  a  va  2 s.c  o m*/

    int minParameters = isStatic ? 0 : 1;

    return Modifier.isPublic(modifiers) && !(method.isSynthetic() || method.isBridge())
            && !Modifier.isAbstract(modifiers) && !name.contains("$")
            && (method.getParameterTypes().length >= minParameters);
}

From source file:grails.core.ArtefactHandlerAdapter.java

/**
 * <p>Checks that class's name ends in the suffix specified for this handler.</p>
 * <p>Override for more complex criteria</p>
 * @param clazz The class to check/* www  .java 2 s  . c  om*/
 * @return true if it is an artefact of this type
 */
public boolean isArtefactClass(@SuppressWarnings("rawtypes") Class clazz) {
    if (clazz == null)
        return false;

    boolean ok = clazz.getName().endsWith(artefactSuffix) && !Closure.class.isAssignableFrom(clazz);
    if (ok && !allowAbstract) {
        ok &= !Modifier.isAbstract(clazz.getModifiers());
    }
    return ok;
}

From source file:org.opt4j.config.ModuleAutoFinder.java

/**
 * Returns all not abstract classes that implement {@link PropertyModule}.
 * /*from ww  w. j a v a  2  s .  co m*/
 * @return all property modules
 */
protected Collection<Class<? extends Module>> getAll() {

    Starter starter = new Starter();
    Collection<File> files = starter.addPlugins();

    classLoader = ClassLoader.getSystemClassLoader();

    String paths = System.getProperty("java.class.path");
    StringTokenizer st = new StringTokenizer(paths, ";\n:");

    while (st.hasMoreTokens()) {
        String path = st.nextToken();
        File f = new File(path);

        if (f.exists()) {
            try {
                f = f.getCanonicalFile();
                files.add(f);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    List<Class<?>> classes = new ArrayList<Class<?>>();

    for (File file : files) {

        if (isJar(file)) {

            try {
                classes.addAll(getAllClasses(new ZipFile(file)));
            } catch (ZipException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (UnsupportedClassVersionError e) {
                System.err.println(file + " not supported: bad version number");
            }
        } else {
            classes.addAll(getAllClasses(file));
        }
    }

    List<Class<? extends Module>> modules = new ArrayList<Class<? extends Module>>();

    for (Class<?> clazz : classes) {
        if (Opt4JModule.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
            Class<? extends Module> module = clazz.asSubclass(Module.class);
            Ignore i = module.getAnnotation(Ignore.class);

            if (i == null && !module.isAnonymousClass() && accept.transform(module)
                    && !ignore.transform(module)) {
                modules.add(module);
                invokeOut("Add module: " + module.toString());
            }
        }
    }

    return modules;

}

From source file:io.smartspaces.workbench.project.test.JunitTestClassDetector.java

/**
 * Is the class a JUnit test class?/* ww  w. j av  a 2 s  .  co m*/
 *
 * @param potentialTestClass
 *          the class to test
 * @param log
 *          the logger to use
 *
 * @return {@code true} if the class is testable and can be instantiated
 */
private boolean isTestClass(Class<?> potentialTestClass, Log log) {
    if (potentialTestClass.isInterface() || !classHasPublicConstructor(potentialTestClass, log)) {
        return false;
    }

    // Do not attempt to run tests on abstract test classes.
    if (Modifier.isAbstract(potentialTestClass.getModifiers())) {
        return false;
    }

    for (Method method : potentialTestClass.getMethods()) {
        if (method.isAnnotationPresent(Test.class)) {

            // No need to check any more if we have 1
            return true;
        }
    }

    return false;
}

From source file:org.apache.openjpa.enhance.ApplicationIdTool.java

/**
 * Constructs a new tool instance capable of generating an
 * object id class for <code>meta</code>.
 *//*from  w  ww .j  a v a2 s.  co m*/
public ApplicationIdTool(OpenJPAConfiguration conf, Class type, ClassMetaData meta) {
    _log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);

    _type = type;
    _meta = meta;
    if (_meta != null) {
        _abstract = Modifier.isAbstract(_meta.getDescribedType().getModifiers());
        _fields = getDeclaredPrimaryKeyFields(_meta);
    }
}

From source file:uk.gov.gchq.gaffer.schemabuilder.service.SchemaBuilderService.java

private static void keepPublicConcreteClasses(final Collection<Class> classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        for (Class clazz = null; itr.hasNext(); 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 ww .  j a  v  a  2  s .  co  m
                }
            }
        }
    }
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

private static boolean isSaaj13(SOAPElement soapElement) {
    try {/* www. jav  a  2 s.  c o m*/
        Method m = soapElement.getClass().getMethod("getElementQName", new Class[0]);
        // we might be using the SAAJ 1.3 API, while the impl is 1.2
        // let's see if the method is not abstract
        if (Modifier.isAbstract(m.getModifiers())) {
            logger.warn("Detected SAAJ API version 1.3, while implementation provides version 1.2. "
                    + "Please replace the SAAJ API jar with a version that corresponds to your runtime"
                    + " implementation (which might be provided by your app server).");
            return false;
        } else {
            return true;
        }
    } catch (NoSuchMethodException e) {
        // getElementQName not found
        return false;
    }
}

From source file:org.mule.module.extension.internal.util.IntrospectionUtils.java

public static void checkInstantiable(Class<?> declaringClass, boolean requireDefaultConstructor) {
    checkArgument(declaringClass != null, "declaringClass cannot be null");

    if (requireDefaultConstructor) {
        checkArgument(hasDefaultConstructor(declaringClass),
                String.format("Class %s cannot be instantiated since it doesn't have a default constructor",
                        declaringClass.getName()));
    }/*from w  ww  . j  av a 2 s . c o m*/

    checkArgument(!declaringClass.isInterface(),
            String.format("Class %s cannot be instantiated since it's an interface", declaringClass.getName()));
    checkArgument(!Modifier.isAbstract(declaringClass.getModifiers()),
            String.format("Class %s cannot be instantiated since it's abstract", declaringClass.getName()));
}

From source file:com.github.helenusdriver.driver.impl.CreateSchemasImpl.java

/**
 * Find all keyspaces./*w w w.  java  2 s .com*/
 *
 * @author paouelle
 *
 * @return a map of all the keyspaces along with the list of POJO class info
 *         associated with them
 * @throws IllegalArgumentException if an @Entity annotated class is missing the
 *         Keyspace annotation or two entities defines the same keyspace with
 *         different options or an @Entitiy annotated class doesn't represent
 *         a valid POJO class or if no entities are found
 */
private Map<Keyspace, List<ClassInfoImpl<?>>> findKeyspaces() {
    final Map<String, Keyspace> keyspaces = new HashMap<>(25);
    final Map<Keyspace, List<ClassInfoImpl<?>>> cinfos = new HashMap<>(25);
    final Reflections reflections = new Reflections(pkg);

    // search for all POJO annotated classes with @Entity
    for (final Class<?> clazz : reflections
            .getTypesAnnotatedWith(com.github.helenusdriver.persistence.Entity.class, true)) {
        // skip abstract POJO classes
        if (Modifier.isAbstract(clazz.getModifiers())) {
            continue;
        }
        final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz);
        final Keyspace k = cinfo.getKeyspace();
        final Keyspace old = keyspaces.put(k.name(), k);
        List<ClassInfoImpl<?>> cs = cinfos.get(k);

        if (cs == null) {
            cs = new ArrayList<>(25);
            cinfos.put(k, cs);
        }
        cs.add(cinfo);
        if ((old != null) && !k.equals(old)) {
            // duplicate annotation found with different attribute
            throw new IllegalArgumentException("two different @Keyspace annotations found with class '"
                    + clazz.getName() + "': " + old + " and: " + k);
        }
    }
    // search for all POJO annotated classes with @RootEntity
    for (final Class<?> clazz : reflections
            .getTypesAnnotatedWith(com.github.helenusdriver.persistence.RootEntity.class, true)) {
        // skip classes that are not directly annotated
        if (ReflectionUtils.findFirstClassAnnotatedWith(clazz,
                com.github.helenusdriver.persistence.RootEntity.class) != clazz) {
            continue;
        }
        final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz);
        final Keyspace k = cinfo.getKeyspace();
        final Keyspace old = keyspaces.put(k.name(), k);
        List<ClassInfoImpl<?>> cs = cinfos.get(k);

        if (cs == null) {
            cs = new ArrayList<>(25);
            cinfos.put(k, cs);
        }
        cs.add(cinfo);
        if ((old != null) && !k.equals(old)) {
            // duplicate annotation found with different attribute
            throw new IllegalArgumentException("two different @Keyspace annotations found with class '"
                    + clazz.getName() + "': " + old + " and: " + k);
        }
    }
    // search for all POJO annotated classes with @UDTEntity
    for (final Class<?> clazz : reflections
            .getTypesAnnotatedWith(com.github.helenusdriver.persistence.UDTEntity.class, true)) {
        // skip abstract POJO classes
        if (Modifier.isAbstract(clazz.getModifiers())) {
            continue;
        }
        final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz);
        final Keyspace k = cinfo.getKeyspace();
        final Keyspace old = keyspaces.put(k.name(), k);
        List<ClassInfoImpl<?>> cs = cinfos.get(k);

        if (cs == null) {
            cs = new ArrayList<>(25);
            cinfos.put(k, cs);
        }
        cs.add(cinfo);
        if ((old != null) && !k.equals(old)) {
            // duplicate annotation found with different attribute
            throw new IllegalArgumentException("two different @Keyspace annotations found with class '"
                    + clazz.getName() + "': " + old + " and: " + k);
        }
    }
    org.apache.commons.lang3.Validate.isTrue(!cinfos.isEmpty(),
            "no classes annotated with @Entity, @RootEntity, or @UDTEntity found in package: %s", pkg);
    return cinfos;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@SuppressWarnings("unchecked")
@Test//from w  ww .ja  v  a2s .  c o  m
public void publicAbstractMethodStartingWithAdd() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withModifiers(Modifier.ABSTRACT);
    memberCriteria.named(Pattern.compile("add.*"));
    memberCriteria.setMemberIterateOrder(ReflectFacade.getMemberNameComparator());
    Collection<Class<?>> iteratedTypes = new ArrayList<Class<?>>(Arrays.asList(List.class, Collection.class));
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        iteratedTypes.remove(member.getDeclaringClass());
        String name = member.getName();
        assertTrue(name.startsWith("add"));
        int modifiers = member.getModifiers();
        assertTrue(Modifier.isAbstract(modifiers));
    }
    assertTrue("Some types have not been iterated. " + iteratedTypes, iteratedTypes.isEmpty());
}