Example usage for java.lang Class isLocalClass

List of usage examples for java.lang Class isLocalClass

Introduction

In this page you can find the example usage for java.lang Class isLocalClass.

Prototype

public boolean isLocalClass() 

Source Link

Document

Returns true if and only if the underlying class is a local class.

Usage

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.");
    }/*from   w ww  .j  a v  a  2s  .  c  om*/
    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:com.sunchenbin.store.feilong.core.lang.ClassUtil.java

/**
 *  class info map for LOGGER.//from   w  w  w.  j  a  v  a 2s .  c  o m
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (Validator.isNullOrEmpty(klass)) {
        return Collections.emptyMap();
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.sunchenbin.store.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.sunchenbin.store.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? ,voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,?,?????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false,?true,JVM???,java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}

From source file:name.ikysil.beanpathdsl.codegen.Context.java

private boolean isExcluded(Class<?> clazz) {
    if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface()
            || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers())
            || (clazz.getPackage() == null)) {
        return true;
    }/*from w  w  w.  j  a v a 2s  . co  m*/
    IncludedClass includedConfig = includedClasses.get(clazz);
    if (includedConfig != null) {
        return false;
    }
    ExcludedClass excludedConfig = excludedClasses.get(clazz);
    if (excludedConfig != null) {
        return true;
    }
    for (ExcludedPackage excludedPackage : excludedPackages) {
        if (excludedPackage.match(clazz.getPackage())) {
            return true;
        }
    }
    return false;
}

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;
    }//from   w  ww . j a va 2 s .c om

    return false;
}

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();//from   w w w .  j  a  v  a  2 s.co 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());
    }
}

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   w  w w .j  a  v a  2  s .  c  om
        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:com.feilong.commons.core.lang.ClassUtil.java

/**
 *  class info map for log.//from w ww  .  ja  va 2s  .  com
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    //"clz.getCanonicalName()": "com.feilong.commons.core.date.DatePattern",
    //"clz.getName()": "com.feilong.commons.core.date.DatePattern",
    //"clz.getSimpleName()": "DatePattern",

    // getCanonicalName ( Java Language Specification ??) && getName
    //??class?array?
    // getName[[Ljava.lang.String?getCanonicalName?
    map.put("clz.getCanonicalName()", klass.getCanonicalName());
    map.put("clz.getName()", klass.getName());
    map.put("clz.getSimpleName()", klass.getSimpleName());

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,??????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false?trueJVM???java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
    //      Class<?> klass = this.getClass();
    //
    //      TypeVariable<?>[] typeParameters = klass.getTypeParameters();
    //      TypeVariable<?> typeVariable = typeParameters[0];
    //
    //      Type[] bounds = typeVariable.getBounds();
    //
    //      Type bound = bounds[0];
    //
    //      if (log.isDebugEnabled()){
    //         log.debug("" + (bound instanceof ParameterizedType));
    //      }
    //
    //      Class<T> modelClass = ReflectUtil.getGenericModelClass(klass);
    //      return modelClass;
}

From source file:cn.webwheel.DefaultMain.java

@SuppressWarnings("unchecked")
private void autoMap(String root, String pkg, String name) {
    Class cls;
    try {/* ww w  .j  ava  2s . c o m*/
        cls = Class.forName(pkg + "." + name);
    } catch (ClassNotFoundException e) {
        return;
    }
    if (cls.isMemberClass() && !Modifier.isStatic(cls.getModifiers())) {
        return;
    }
    if (cls.isAnonymousClass() || cls.isLocalClass() || !Modifier.isPublic(cls.getModifiers())
            || Modifier.isAbstract(cls.getModifiers())) {
        return;
    }

    name = name.replace('$', '.');

    for (Method method : cls.getMethods()) {

        String pathPrefix = pkg.substring(root.length()).replace('.', '/') + '/';
        String path = pathPrefix + name + '.' + method.getName();

        Action action = getAction(cls, method);
        if (action == null)
            continue;

        if (!action.value().isEmpty()) {
            if (action.value().startsWith("?")) {
                path = path + action.value();
            } else if (action.value().startsWith(".")) {
                path = pathPrefix + name + action.value();
            } else if (!action.value().startsWith("/")) {
                path = pathPrefix + action.value();
            } else {
                path = action.value();
            }
        }
        ActionBinder binder = map(path);
        if (!action.rest().isEmpty()) {
            String rest = action.rest();
            if (!rest.startsWith("/"))
                rest = pathPrefix + rest;
            binder = binder.rest(rest);
        }
        SetterConfig cfg = binder.with(cls, method);
        if (!action.charset().isEmpty()) {
            cfg = cfg.setCharset(action.charset());
        }
        if (action.fileUploadFileSizeMax() != 0) {
            cfg = cfg.setFileUploadFileSizeMax(action.fileUploadFileSizeMax());
        }
        if (action.fileUploadSizeMax() != 0) {
            cfg.setFileUploadSizeMax(action.fileUploadSizeMax());
        }
        if (action.setterPolicy() != SetterPolicy.Auto) {
            cfg.setSetterPolicy(action.setterPolicy());
        }
    }
}

From source file:fr.exanpe.tapestry.tldgen.taglib.builder.StructureBuilder.java

/**
 * Builds the output taglib structure/* w  w w  . java  2s  .co  m*/
 * 
 * @param rootPackage the root package to look the components for
 * @param supportedPackages all sub packages to scan
 * @param urls the urls used to scan the packages
 * @return the structure containing the information on the taglib to generate
 * @throws MojoExecutionException if any unexpected error occurs
 */
public Taglib build(String rootPackage, String[] supportedPackages, URL[] urls) throws MojoExecutionException {
    Taglib taglib = new Taglib();

    log.debug("Creating taglib object model...");

    for (String subPackage : supportedPackages) {
        String pkgname = rootPackage + "." + subPackage;

        log.debug("Processing taglib for full package named : " + pkgname);

        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(pkgname))).setUrls(urls)
                .setScanners(new TypesScanner()));

        Store store = reflections.getStore();

        // Return classes anaylised by TypeScanner
        Multimap<String, String> classes = store.getStoreMap().values().iterator().next();

        log.debug(String.format("%s classes to analyse for %s package...", classes.keySet().size(), pkgname));

        // Loop on found classes
        for (final String s : classes.keySet()) {
            Class<?> c;
            try {
                log.debug(String.format("Load class %s into classloader", s));
                c = Thread.currentThread().getContextClassLoader().loadClass(s);
            } catch (ClassNotFoundException e) {
                // should not happen as it has just been parsed by Reflection...
                log.error(e);
                throw new MojoExecutionException("Class loader internal error for class :" + s, e);
            }

            if (!c.isAnnotation() && !c.isAnonymousClass() && !c.isEnum() && !c.isInterface()
                    && !c.isLocalClass() && !c.isMemberClass() && !c.isSynthetic()
                    && !Modifier.isAbstract(c.getModifiers())) {
                log.debug("Processing Tag : " + c.getName());

                Tag tag = buildTagFromClass(rootPackage, c);
                taglib.getTags().add(tag);
            }
        }
    }

    log.debug("Taglib object model completed");
    return taglib;
}

From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java

private void handleClassFile(final File f, final JarEntry j) throws IOException, RuntimeException {
    final String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
    try {//w  w  w . ja v a  2s .  c  om
        final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
        final Ats ats = Ats.inClassHierarchy(candidate);
        if ((this.allowedClassNames.isEmpty() || this.allowedClassNames.contains(candidate.getName())
                || this.allowedClassNames.contains(candidate.getCanonicalName())
                || this.allowedClassNames.contains(candidate.getSimpleName()))
                && (ats.has(Workflow.class) || ats.has(Activities.class))
                && !Modifier.isAbstract(candidate.getModifiers())
                && !Modifier.isInterface(candidate.getModifiers()) && !candidate.isLocalClass()
                && !candidate.isAnonymousClass()) {
            if (ats.has(Workflow.class)) {
                this.workflowClasses.add(candidate);
                LOG.debug("Discovered workflow implementation class: " + candidate.getName());
            } else {
                this.activityClasses.add(candidate);
                LOG.debug("Discovered activity implementation class: " + candidate.getName());
            }
        }
    } catch (final ClassNotFoundException e) {
        LOG.debug(e, e);
    }
}