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:org.jboss.arquillian.spring.integration.javaconfig.utils.DefaultConfigurationClassesProcessor.java

private void throwExceptionIfConfigurationClassDeclaredFinal(Class<?> configurationCandidate) {
    if (Modifier.isFinal(configurationCandidate.getModifiers())) {
        throw new RuntimeException(buildValidationMessage(configurationCandidate,
                VALIDATION_MESSAGE_SUFFIX_INNER_CONFIGURATION_CLASS_DECLARED_FINAL));
    }/* ww w .  ja v a  2s .co m*/
}

From source file:org.jboss.arquillian.spring.integration.javaconfig.utils.DefaultConfigurationClassesProcessor.java

private void throwExceptionIfConfiguratoinClassNotDeclaredStatic(Class<?> configurationCandidate) {
    if (!Modifier.isStatic(configurationCandidate.getModifiers())) {
        throw new RuntimeException(buildValidationMessage(configurationCandidate,
                VALIDATION_MESSAGE_SUFFIX_INNER_CLASS_DECLARED_NOT_STATIC));
    }/*from   w w w.j  ava  2  s  . c om*/
}

From source file:org.openmhealth.schema.service.SchemaClassServiceImpl.java

@PostConstruct
public void initializeSchemaIds() throws IllegalAccessException, InvocationTargetException,
        InstantiationException, NoSuchMethodException {

    Reflections reflections = new Reflections(SCHEMA_CLASS_PACKAGE);

    for (Class<? extends SchemaSupport> schemaClass : reflections.getSubTypesOf(SchemaSupport.class)) {

        if (schemaClass.isInterface() || Modifier.isAbstract(schemaClass.getModifiers())) {
            continue;
        }/*from  w ww  .  j av  a  2  s .c o  m*/

        SchemaId schemaId;

        if (schemaClass.isEnum()) {
            schemaId = schemaClass.getEnumConstants()[0].getSchemaId();
        } else {
            Constructor<? extends SchemaSupport> constructor = schemaClass.getDeclaredConstructor();
            constructor.setAccessible(true);
            schemaId = constructor.newInstance().getSchemaId();
        }

        schemaIds.add(schemaId);
    }
}

From source file:org.pushio.webapp.helper.json.SerializeConfig.java

public ObjectSerializer createJavaBeanSerializer(Class<?> clazz) {
    if (!Modifier.isPublic(clazz.getModifiers())) {
        MyJavaBeanSerializer bean = new MyJavaBeanSerializer(clazz);
        return bean;
    }//w  ww. java 2s.  co m
    return new MyJavaBeanSerializer(clazz);
}

From source file:com.intelligentsia.dowsers.entity.serializer.EntityMapper.java

/**
 * Method that can be used to parse JSON to specified Java value, using
 * reader provided./*from   w w  w  . j  av a  2 s .c o m*/
 * 
 * @param reader
 * @param valueType
 * @return
 * @throws DowsersException
 */
@SuppressWarnings("unchecked")
public <T> T readValue(final Reader reader, final Class<T> valueType) throws DowsersException {
    if (valueType.isInterface() || Modifier.isAbstract(valueType.getModifiers())) {
        try {
            final EntityProxy entityProxy = mapper.readValue(reader, EntityProxy.class);
            return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                    new Class[] { valueType, EntityProxyHandler.class }, entityProxy);
        } catch (final Throwable e) {
            throw new DowsersException(e);
        }
    }
    try {
        return mapper.readValue(reader, valueType);
    } catch (final Throwable e) {
        throw new DowsersException(e);
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeXmlSerializerFactoryTest.java

@SuppressWarnings({ "RawUseOfParameterizedType" })
public void testASerializerCanBeBuiltForEveryChange() throws Exception {
    List<String> errors = new ArrayList<String>();
    for (Class<? extends Change> aClass : domainReflections.getSubTypesOf(Change.class)) {
        if (Modifier.isPublic(aClass.getModifiers()) && !Modifier.isAbstract(aClass.getModifiers())
                && !aClass.isAnonymousClass()) {
            Change c = aClass.newInstance();
            try {
                factory.createXmlSerializer(c);
            } catch (StudyCalendarError sce) {
                errors.add(String.format("Failure with %s: %s", c, sce.getMessage()));
            }/*w w  w .  ja  va 2s  .c  o  m*/
        }
    }
    if (!errors.isEmpty()) {
        fail(StringUtils.join(errors.iterator(), '\n'));
    }
}

From source file:org.unitils.mock.core.proxy.ProxyService.java

/**
 * Creates an instance of the given type. First we try to create an instance using the default constructor.
 * No constructor or class-initialization will be called.
 *
 * @param <T>   The type of the instance
 * @param clazz The class for which an instance is requested
 * @return An instance of the given class
 *///from w ww.jav  a 2s.  c o m
public <T> T createUninitializedInstanceOfType(Class<T> clazz) {
    if (clazz.isInterface() || isAbstract(clazz.getModifiers())) {
        throw new UnitilsException("Cannot create instance of an interface or abstract type: " + clazz);
    }
    Objenesis objenesis = new ObjenesisStd();
    return objenesis.newInstance(clazz);
}

From source file:blue.lapis.pore.converter.wrapper.WrapperConverterTest.java

private Object create() {
    Class<?> base = interfaces.get(0);

    if (!base.isInterface() && Modifier.isFinal(base.getModifiers())) {
        if (base == Location.class) {
            return new Location(mock(Extent.class), 0, 0, 0);
        }//from   ww  w. j  a  v  a  2s . c  o m
    }

    Object mock;
    if (interfaces.size() == 1) {
        mock = mock(base);
    } else {
        mock = mock(base, withSettings().extraInterfaces(
                interfaces.subList(1, interfaces.size()).toArray(new Class<?>[interfaces.size() - 1])));
    }
    // o.b.BlockState's subclasses break this test because of incongruencies between SpongeAPI and Bukkit
    // this code basically assures that a NullPointerException won't be thrown while converting
    if (base.getPackage().getName().startsWith("org.spongepowered.api.block.tileentity")) {
        Location loc = new Location(mock(Extent.class), 0, 0, 0);
        BlockState state = mock(BlockState.class);
        when(loc.getBlock()).thenReturn(state);
        when(((TileEntity) mock).getLocation()).thenReturn(loc);
        when(((TileEntity) mock).getBlock()).thenReturn(state);
    }
    return mock;
}

From source file:org.drools.guvnor.server.contenthandler.ModelContentHandler.java

private boolean isClassVisible(ClassLoader cl, String className, String assetPackageName) {
    try {/*  ww w  .  ja  v a  2 s.c  o  m*/
        Class<?> cls = cl.loadClass(className);
        int modifiers = cls.getModifiers();
        if (Modifier.isPublic(modifiers)) {
            return true;
        }
        String packageName = className.substring(0, className.lastIndexOf("."));
        if (!packageName.equals(assetPackageName)) {
            return false;
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:de.lmu.ifi.dbs.jfeaturelib.utils.PackageScanner.java

public List<Class<T>> scanForClass(Package thePackage, Class<T> needle)
        throws IOException, UnsupportedEncodingException, URISyntaxException {
    List<String> binaryNames = getNames(thePackage);
    List<Class<T>> list = new ArrayList<>();

    ClassLoader loader = ClassLoader.getSystemClassLoader();
    for (String binaryName : binaryNames) {
        if (binaryName.contains("$") && !includeInnerClasses) {
            log.debug("Skipped inner class: " + binaryName);
            continue;
        }// w w  w .  jav  a2 s.c  o m

        try {
            Class<?> clazz = loader.loadClass(binaryName);
            int modifiers = clazz.getModifiers();
            if ((modifiers & Modifier.INTERFACE) != 0 && !includeInterfaces) {
                log.debug("Skipped interface: " + binaryName);
                continue;
            }
            if ((modifiers & Modifier.ABSTRACT) != 0 && !includeAbstractClasses) {
                log.debug("Skipped abstract class: " + binaryName);
                continue;
            }
            if (needle.isAssignableFrom(clazz)) {
                log.debug("added class/interface/..: " + binaryName);
                list.add((Class<T>) clazz);
            }
        } catch (ClassNotFoundException e) {
            // This should never happen
            log.warn("couldn't find class (?!): " + binaryName, e);
        }
    }
    return list;
}