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.mrgeo.mapalgebra.MapAlgebraParser.java

private void init() {
    OpImageRegistrar.registerMrGeoOps();

    // include any computationally expensive operations in the cached ops list.
    // This will cause the tiles to be cached. It is also a good idea to add
    // operations that read from multiple sources to the cached list.
    cachedOps.add("slope");

    parser = ParserAdapterFactory.createParserAdapter();
    parser.initialize();//w w w . j  a v a 2  s.  c om

    // register mapops
    Reflections reflections = new Reflections("org.mrgeo");

    Set<Class<? extends MapOp>> subTypes = reflections.getSubTypesOf(MapOp.class);

    log.debug("Registering MapOps:");
    for (Class<? extends MapOp> clazz : subTypes) {
        try {
            if (!Modifier.isAbstract(clazz.getModifiers())) {
                registerFunctions(clazz);
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    for (String n : mapOps.keySet()) {
        parser.addFunction(n);
    }

    _loadFactoryFunctions();

    parser.afterFunctionsLoaded();
}

From source file:org.kuali.rice.krad.service.impl.RemoteModuleServiceBase.java

/**
 * @see org.kuali.rice.krad.service.ModuleService#getExternalizableBusinessObjectImplementation(java.lang.Class)
 *///from ww  w.  ja  v  a 2  s.  c  o m
@Override
public <E extends ExternalizableBusinessObject> Class<E> getExternalizableBusinessObjectImplementation(
        Class<E> externalizableBusinessObjectInterface) {
    if (getModuleConfiguration() == null) {
        throw new IllegalStateException(
                "Module configuration has not been initialized for the module service.");
    }
    Map<Class, Class> ebos = getModuleConfiguration().getExternalizableBusinessObjectImplementations();
    if (ebos == null) {
        return null;
    }
    if (ebos.containsValue(externalizableBusinessObjectInterface)) {
        return externalizableBusinessObjectInterface;
    } else {
        Class<E> implementationClass = ebos.get(externalizableBusinessObjectInterface);

        int implClassModifiers = implementationClass.getModifiers();
        if (Modifier.isInterface(implClassModifiers) || Modifier.isAbstract(implClassModifiers)) {
            throw new RuntimeException("Implementation class must be non-abstract class: ebo interface: "
                    + externalizableBusinessObjectInterface.getName() + " impl class: "
                    + implementationClass.getName() + " module: "
                    + getModuleConfiguration().getNamespaceCode());
        }
        return implementationClass;
    }

}

From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java

/**
 * Interfaces, enums, annotations, and abstract classes cannot be
 * instantiated./*  w  ww .  j  a  v a 2s .c o m*/
 * 
 * @param actionClass
 *            class to check
 * @return returns true if the class cannot be instantiated or should be
 *         ignored
 */
protected boolean cannotInstantiate(Class<?> actionClass) {
    return actionClass.isAnnotation() || actionClass.isInterface() || actionClass.isEnum()
            || (actionClass.getModifiers() & Modifier.ABSTRACT) != 0 || actionClass.isAnonymousClass();
}

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

/**
 * Instantiates a new <code>RootClassInfoImpl</code> object.
 *
 * @author paouelle//from   ww  w  .j  a  v a2s  .c o m
 *
 * @param  mgr the non-<code>null</code> statement manager
 * @param  clazz the root class of POJO for which to get a class info object for
 * @param  types the non-<code>null</code> map of all type class infos
 * @throws NullPointerException if <code>clazz</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>clazz</code> or any of its type
 *         classes don't represent valid POJO classes
 */
private RootClassInfoImpl(StatementManagerImpl mgr, Class<T> clazz,
        Map<Class<? extends T>, TypeClassInfoImpl<? extends T>> types) {
    super(mgr, clazz, RootEntity.class);
    // first make sure the class is abstract
    org.apache.commons.lang3.Validate.isTrue(Modifier.isAbstract(clazz.getModifiers()),
            "root entity class '%s', must be abstract", clazz.getSimpleName());
    this.ctypes = types;
    this.ntypes = types.values().stream()
            .collect(Collectors.toMap(tcinfo -> tcinfo.getType(), tcinfo -> tcinfo));
    validateAndComplementSchema();
}

From source file:com.fitbur.testify.integration.IntegrationTestVerifier.java

@Override
public void configuration() {
    doPrivileged((PrivilegedAction<Object>) () -> {
        String testClassName = testContext.getTestClassName();
        CutDescriptor cutDescriptor = testContext.getCutDescriptor();
        Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values();

        if (testContext.getCutCount() == 1) {
            checkState(testContext.getConstructorCount() == 1,
                    "Class under test '%s' defined in test class '%s' has %s constructors. "
                            + "Please insure that the class under test has one and only one constructor.",
                    cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount());
        }/*from  ww w .j a v  a  2  s .  c o m*/
        // insure that only one field has Cut annotation on it.
        if (testContext.getCutCount() > 1) {
            checkState(false, "Found more than one class under test in test class %s. Please insure "
                    + "that only one field is annotated with @Cut.", testClassName);
        }

        //insure that there is a field annotated with @Cut defined or one or more
        //fields annotated with @Real or @Inject
        if (testContext.getCutCount() == 0 && fieldDescriptors.isEmpty()) {
            checkState(false,
                    "Test class '%s' does not define a field annotated with @Cut "
                            + "nor does it define field(s) annotated with @Real or @Inject. "
                            + "Please insure the test class defines a single field annotated "
                            + "with @Cut or defines at least one field annotated with @Real " + "or @Inject.",
                    testClassName);
        }

        //insure need providers have default constructors.
        testContext.getAnnotations(Need.class).parallelStream().map(Need::value).forEach(p -> {
            try {
                p.getDeclaredConstructor();
            } catch (NoSuchMethodException e) {
                checkState(false,
                        "Need provider '%s' defined in test class '%s' does not have a "
                                + "zero argument default constructor. Please insure that the need "
                                + "provider defines an accessible zero argument default constructor.",
                        testClassName, p.getSimpleName());
            }
        });

        fieldDescriptors.parallelStream().forEach(p -> {

            Field field = p.getField();
            Class<?> fieldType = p.getType();
            String fieldName = p.getName();
            String fieldTypeName = p.getTypeName();

            checkState(!fieldType.isArray(),
                    "Field '%s' in test class '%s' can not be configured because '%s'"
                            + " is an array. Please consider using a List instead of arrays.",
                    fieldName, testClassName, fieldTypeName);
            Fake fake = field.getDeclaredAnnotation(Fake.class);
            if (fake != null) {
                checkState(!isFinal(fieldType.getModifiers()),
                        "Can not fake field '%s' in test class '%s' because '%s'" + " is a final class.",
                        fieldName, testClassName, fieldTypeName);
            }

            Real real = field.getDeclaredAnnotation(Real.class);
            if (real != null && real.value()) {
                checkState(!isFinal(fieldType.getModifiers()),
                        "Can not create delegated fake of field '%s' in test class '%s' "
                                + "because '%s' is a final class.",
                        fieldName, testClassName, fieldTypeName);
            }
        });

        return null;
    });
}

From source file:com.fitbur.testify.system.SystemTestVerifier.java

@Override
public void configuration() {
    doPrivileged((PrivilegedAction<Object>) () -> {
        String testClassName = testContext.getTestClassName();
        CutDescriptor cutDescriptor = testContext.getCutDescriptor();
        Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values();

        if (testContext.getCutCount() == 1) {
            checkState(testContext.getConstructorCount() == 1,
                    "Class under test '%s' defined in test class '%s' has %s constructors. "
                            + "Please insure that the class under test has one and only one constructor.",
                    cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount());
        }//ww w. j a v a 2 s  .  c o m
        // insure that only one field has Cut annotation on it.
        if (testContext.getCutCount() > 1) {
            checkState(false, "Found more than one class under test in %s. Please insure "
                    + "that only one field is annotated with @Cut.", testClassName);
        }

        //insure that there is a field annotated with @Cut defined or one or more
        //fields annotated with @Real or @Inject
        if (testContext.getCutCount() == 0 && fieldDescriptors.isEmpty()) {
            checkState(false,
                    "Test class '%s' does not define a field annotated with @Cut "
                            + "nor does it define field(s) annotated with @Real or @Inject. "
                            + "Please insure the test class defines a single field annotated "
                            + "with @Cut or defines at least one field annotated with @Real " + "or @Inject.",
                    testClassName);
        }

        //insure need providers have default constructors.
        testContext.getAnnotations(Need.class).parallelStream().map(Need::value).forEach(p -> {
            try {
                p.getDeclaredConstructor();
            } catch (NoSuchMethodException e) {
                checkState(false,
                        "Need provider '%s' defined in test class '%s' does not have a "
                                + "zero argument default constructor. Please insure that the need "
                                + "provider defines an accessible zero argument default constructor.",
                        testClassName, p.getSimpleName());
            }
        });

        fieldDescriptors.parallelStream().forEach(p -> {
            Field field = p.getField();
            Class<?> fieldType = p.getType();
            String fieldName = p.getName();
            String fieldTypeName = p.getTypeName();

            checkState(!fieldType.isArray(),
                    "Field '%s' in test class '%s' can not be configured because '%s'"
                            + " is an array. Please consider using a List instead of arrays.",
                    fieldName, testClassName, fieldTypeName);
            Fake fake = field.getDeclaredAnnotation(Fake.class);
            if (fake != null) {
                checkState(!isFinal(fieldType.getModifiers()),
                        "Can not fake field '%s' in test class '%s' because '%s'" + " is a final class.",
                        fieldName, testClassName, fieldTypeName);
            }

            Real real = field.getDeclaredAnnotation(Real.class);
            if (real != null && real.value()) {
                checkState(!isFinal(fieldType.getModifiers()),
                        "Can not create delegated fake of field '%s' in test class '%s' "
                                + "because '%s' is a final class.",
                        fieldName, testClassName, fieldTypeName);
            }

        });

        return null;
    });
}

From source file:org.apache.struts2.config.ClasspathPackageProvider.java

/**
 * Scan a list of packages for Action classes.
 *
 * This method loads classes that implement the Action interface
 * or have a class name that ends with the letters "Action".
 *
 * @param pkgs A list of packages to load
 * @see #processActionClass/* w  w  w  . j a  v a 2 s  .  com*/
 */
protected void loadPackages(String[] pkgs) {

    packageLoader = new PackageLoader();
    ResolverUtil<Class> resolver = new ResolverUtil<Class>();
    resolver.find(createActionClassTest(), pkgs);

    Set<? extends Class<? extends Class>> actionClasses = resolver.getClasses();
    for (Object obj : actionClasses) {
        Class cls = (Class) obj;
        if (!Modifier.isAbstract(cls.getModifiers())) {
            processActionClass(cls, pkgs);
        }
    }

    for (PackageConfig config : packageLoader.createPackageConfigs()) {
        configuration.addPackageConfig(config.getName(), config);
    }
}

From source file:org.evosuite.setup.TestClusterGenerator.java

public static boolean canUse(Class<?> c) {
    //if (Throwable.class.isAssignableFrom(c))
    //   return false;
    if (Modifier.isPrivate(c.getModifiers()))
        return false;

    if (!Properties.USE_DEPRECATED && c.isAnnotationPresent(Deprecated.class)) {
        logger.debug("Skipping deprecated class {}", c.getName());
        return false;
    }/*from  ww  w .  ja  v a  2s  .  c om*/

    if (c.isAnonymousClass()) {
        return false;
    }

    if (ANONYMOUS_MATCHER1.matcher(c.getName()).matches()) {
        logger.debug("{} looks like an anonymous class, ignoring it", c);
        return false;
    }

    if (ANONYMOUS_MATCHER2.matcher(c.getName()).matches()) {
        logger.debug("{} looks like an anonymous class, ignoring it", c);
        return false;
    }

    if (c.getName().startsWith("junit"))
        return false;

    if (isEvoSuiteClass(c) && !MockList.isAMockClass(c.getCanonicalName())) {
        return false;
    }

    if (c.getEnclosingClass() != null) {
        if (!canUse(c.getEnclosingClass()))
            return false;
    }

    if (c.getDeclaringClass() != null) {
        if (!canUse(c.getDeclaringClass()))
            return false;
    }

    // If the SUT is not in the default package, then
    // we cannot import classes that are in the default
    // package
    if (!c.isArray() && !c.isPrimitive() && !Properties.CLASS_PREFIX.isEmpty() && !c.getName().contains(".")) {
        return false;
    }

    if (Modifier.isPublic(c.getModifiers())) {
        return true;
    }

    // If default access rights, then check if this class is in the same package as the target class
    if (!Modifier.isPrivate(c.getModifiers())) {
        //              && !Modifier.isProtected(c.getModifiers())) {
        String packageName = ClassUtils.getPackageName(c);
        if (packageName.equals(Properties.CLASS_PREFIX)) {
            return true;
        }
    }

    logger.debug("Not public");
    return false;
}

From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java

@Cache
public List<Class<? extends StereotypeRenderer>> getRenderers() {
    try {//  w w w.j  a va2  s.co m
        List<Class<? extends StereotypeRenderer>> buildList = new ArrayList<Class<? extends StereotypeRenderer>>();
        ClassFinder cf = new ClassFinder("", true);
        cf.addInterfaceFilter(StereotypeRenderer.class);
        Set<Class> results = cf.find();
        for (Class clazz : results) {
            // mustn't add abstract classes or stereotypes
            if (!Modifier.isAbstract(clazz.getModifiers())) {
                buildList.add(clazz);
            }
        }
        Collections.sort(buildList, new Comparator() {

            public int compare(Object o1, Object o2) {
                Class c1 = (Class) o1;
                Class c2 = (Class) o2;
                return c1.getName().compareTo(c2.getName());
            }
        });
        return buildList;
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex);
        throw new IllegalStateException("Unable to load list of components.", ex);
    }
}

From source file:ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition.java

@SuppressWarnings("unchecked")
void populateScanAlso(Set<Class<? extends IBase>> theScanAlso) {
    for (ScannedField next : myScannedFields) {
        if (IBase.class.isAssignableFrom(next.getElementType())) {
            if (next.getElementType().isInterface() == false
                    && Modifier.isAbstract(next.getElementType().getModifiers()) == false) {
                theScanAlso.add((Class<? extends IBase>) next.getElementType());
            }/*from  w  w w. j av a  2 s  .  c o  m*/
        }
        for (Class<? extends IBase> nextChildType : next.getChoiceTypes()) {
            if (nextChildType.isInterface() == false
                    && Modifier.isAbstract(nextChildType.getModifiers()) == false) {
                theScanAlso.add(nextChildType);
            }
        }
    }
}