List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:xiaofei.library.hermes.util.TypeUtils.java
public static void validateClass(Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Class object is null."); }// w w w . ja v a 2 s .com if (clazz.isPrimitive() || clazz.isInterface()) { return; } if (clazz.isAnnotationPresent(WithinProcess.class)) { throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName() + ". Class with a WithinProcess annotation presented on it cannot be accessed" + " from outside the process."); } if (clazz.isAnonymousClass()) { throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName() + ". Anonymous class cannot be accessed from outside the process."); } if (clazz.isLocalClass()) { throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName() + ". Local class cannot be accessed from outside the process."); } if (Context.class.isAssignableFrom(clazz)) { return; } if (Modifier.isAbstract(clazz.getModifiers())) { throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName() + ". Abstract class cannot be accessed from outside the process."); } }
From source file:eu.qualityontime.commons.MethodUtils.java
/** * <p>//from w ww. j a v a 2s . c o m * Return an accessible method (that is, one that can be invoked via * reflection) by scanning through the superclasses. If no such method can * be found, return <code>null</code>. * </p> * * @param clazz * Class to be checked * @param methodName * Method name of the method we wish to call * @param parameterTypes * The parameter type signatures */ private static Method getAccessibleMethodFromSuperclass(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) { Class<?> parentClazz = clazz.getSuperclass(); while (parentClazz != null) { if (Modifier.isPublic(parentClazz.getModifiers())) { try { return parentClazz.getMethod(methodName, parameterTypes); } catch (final NoSuchMethodException e) { return null; } } parentClazz = parentClazz.getSuperclass(); } return null; }
From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java
private boolean _isJSONWebServiceClass(Class<?> clazz) { if (!clazz.isAnonymousClass() && !clazz.isArray() && !clazz.isEnum() && !clazz.isLocalClass() && !clazz.isPrimitive() && !(clazz.isMemberClass() ^ Modifier.isStatic(clazz.getModifiers()))) { return true; }/* w ww. j av a2 s . c o m*/ return false; }
From source file:org.atemsource.atem.impl.pojo.ScannedPojoEntityTypeRepository.java
protected synchronized AbstractEntityType createEntityType(final Class clazz) { AbstractEntityType entityType;// w w w . ja v a2 s . com entityType = beanCreator.create(entityTypeClass); entityType.setEntityClass(clazz); entityType.setRepository(this); entityType.setAbstractType(clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())); entityType.setCode(clazz.getName()); addEntityTypeToLookup(clazz, entityType); return entityType; }
From source file:org.kuali.rice.krad.bo.ModuleConfiguration.java
/** * @param externalizableBusinessObjectImplementations the externalizableBusinessObjectImplementations to set *///from ww w .jav a 2 s.c o m public void setExternalizableBusinessObjectImplementations( Map<Class, Class> externalizableBusinessObjectImplementations) { if (externalizableBusinessObjectImplementations != null) { for (Class implClass : externalizableBusinessObjectImplementations.values()) { int implModifiers = implClass.getModifiers(); if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) { throw new RuntimeException("Externalizable business object implementation class " + implClass.getName() + " must be a non-interface, non-abstract class"); } } } this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations; }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test @SuppressWarnings("unchecked") public void enumAtRootCreatesATopLevelType() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/enum/enumAsRoot.json", "com.example"); Class<Enum> rootEnumClass = (Class<Enum>) resultsClassLoader.loadClass("com.example.enums.EnumAsRoot"); assertThat(rootEnumClass.isEnum(), is(true)); assertThat(isPublic(rootEnumClass.getModifiers()), is(true)); }
From source file:org.mule.util.scan.ClasspathScanner.java
protected <T> void addClassToSet(Class<T> c, Set<Class<T>> set, int flags) { if (c != null) { synchronized (set) { if (c.isInterface()) { if (hasFlag(flags, INCLUDE_INTERFACE)) { set.add(c);/*from w ww .j av a 2 s. c o m*/ } } else if (Modifier.isAbstract(c.getModifiers())) { if (hasFlag(flags, INCLUDE_ABSTRACT)) { set.add(c); } } else { set.add(c); } } } }
From source file:org.syncope.core.rest.controller.TaskController.java
@PreAuthorize("hasRole('TASK_LIST')") @RequestMapping(method = RequestMethod.GET, value = "/jobActionsClasses") public ModelAndView getJobActionClasses() { CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory(); Set<String> jobActionsClasses = new HashSet<String>(); try {/* ww w. j a va2 s . c o m*/ for (Resource resource : resResolver.getResources("classpath*:**/*.class")) { ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource) .getClassMetadata(); if (ArrayUtils.contains(metadata.getInterfaceNames(), SyncJobActions.class.getName())) { try { Class jobClass = Class.forName(metadata.getClassName()); if (!Modifier.isAbstract(jobClass.getModifiers())) { jobActionsClasses.add(jobClass.getName()); } } catch (ClassNotFoundException e) { LOG.error("Could not load class {}", metadata.getClassName(), e); } } } } catch (IOException e) { LOG.error("While searching for class implementing {}", SyncJobActions.class.getName(), e); } ModelAndView result = new ModelAndView(); result.addObject(jobActionsClasses); return result; }
From source file:org.assertj.assertions.generator.AssertionGeneratorTest.java
@Test public void should_generate_assertion_for_classes_in_package_using_provided_class_loader() throws Exception { ClassLoader customClassLoader = new MyClassLoader(Thread.currentThread().getContextClassLoader()); Set<Class<?>> classes = collectClasses(customClassLoader, "org.assertj.assertions.generator.data"); for (Class<?> clazz : classes) { assertThat(clazz.isAnonymousClass()).as("check that " + clazz.getSimpleName() + " is not anonymous") .isFalse();/* ww w.j a v a 2 s .com*/ assertThat(clazz.isLocalClass()).as("check that " + clazz.getSimpleName() + " is not local").isFalse(); assertThat(isPublic(clazz.getModifiers())).as("check that " + clazz.getSimpleName() + " is public") .isTrue(); logger.info("Generating assertions for {}", clazz.getName()); final ClassDescription classDescription = converter.convertToClassDescription(clazz); File customAssertionFile = assertionGenerator.generateCustomAssertionFor(classDescription); logger.info("Generated {} assertions file -> {}", clazz.getSimpleName(), customAssertionFile.getAbsolutePath()); } }
From source file:org.assertj.assertions.generator.AssertionGeneratorTest.java
@Test public void should_generate_assertion_for_classes_in_package() throws Exception { Set<Class<?>> classes = collectClasses("org.assertj.assertions.generator.data"); for (Class<?> clazz : classes) { assertThat(clazz.isAnonymousClass()).as("check that <" + clazz.getSimpleName() + "> is not anonymous") .isFalse();/*from ww w . j a va2 s. c o m*/ assertThat(clazz.isLocalClass()).as("check that " + clazz.getSimpleName() + " is not local").isFalse(); assertThat(isPublic(clazz.getModifiers())).as("check that " + clazz.getSimpleName() + " is public") .isTrue(); logger.info("Generating assertions for {}", clazz.getName()); final ClassDescription classDescription = converter.convertToClassDescription(clazz); File customAssertionFile = assertionGenerator.generateCustomAssertionFor(classDescription); logger.info("Generated {} assertions file -> {}", clazz.getSimpleName(), customAssertionFile.getAbsolutePath()); } }