Example usage for org.apache.commons.lang3 ClassUtils convertClassesToClassNames

List of usage examples for org.apache.commons.lang3 ClassUtils convertClassesToClassNames

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ClassUtils convertClassesToClassNames.

Prototype

public static List<String> convertClassesToClassNames(final List<Class<?>> classes) 

Source Link

Document

Given a List of Class objects, this method converts them into class names.

A new List is returned.

Usage

From source file:org.javaan.bytecode.ReflectionClassContextBuilder.java

private Type createTypeFromClass(String className) {
    Type type = null;/*from   w w w.  java  2s  .  c  om*/
    try {
        Class<?> clazz = Class.forName(className);
        if (clazz.isInterface()) {
            type = new Interface(className);
            Class<?>[] superInterfaces = clazz.getInterfaces();
            addInterface((Interface) type,
                    ClassUtils.convertClassesToClassNames(Arrays.asList(superInterfaces)));
            addMethods(type, clazz);
        } else {
            type = new Clazz(className);
            Class<?> superClass = clazz.getSuperclass();
            String superClassName = (superClass == null) ? null : superClass.getName();
            Class<?>[] implementedInterfaces = clazz.getInterfaces();
            addClass((Clazz) type, superClassName,
                    ClassUtils.convertClassesToClassNames(Arrays.asList(implementedInterfaces)));
            addMethods(type, clazz);
        }
    } catch (ClassNotFoundException e) {
        missingTypes.add(className);
        return null;
    }
    return type;
}

From source file:yoyo.framework.standard.shared.commons.lang.ClassUtilsTest.java

@Test
public void test() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
    List<Class<?>> classes = new ArrayList<Class<?>>() {
        {//from   www .j a  va 2 s . co m
            add(Integer.class);
            add(Long.class);
        }
    };
    assertThat(ClassUtils.convertClassesToClassNames(classes).toArray(),
            is(new Object[] { "java.lang.Integer", "java.lang.Long" }));
    List<String> classNames = new ArrayList<String>() {
        {
            add("java.lang.Integer");
            add("java.lang.Long");
        }
    };
    assertThat(ClassUtils.convertClassNamesToClasses(classNames).toArray(), is(classes.toArray()));
    assertThat(ClassUtils.getAllInterfaces(String.class).toArray(), is(new Object[] {
            java.io.Serializable.class, java.lang.Comparable.class, java.lang.CharSequence.class }));
    assertThat(ClassUtils.getAllSuperclasses(HashMap.class).toArray(),
            is(new Object[] { java.util.AbstractMap.class, java.lang.Object.class }));
    assertThat(ClassUtils.getClass("java.lang.String").toString(), is("class java.lang.String"));
    assertThat(ClassUtils.getPackageCanonicalName(String.class), is("java.lang"));
    assertThat(ClassUtils.getPackageName(String.class), is("java.lang"));
    assertThat(ClassUtils.getPublicMethod(String.class, "length", new Class[] {}), is(not(nullValue())));
    assertThat(ClassUtils.getShortCanonicalName(String.class), is("String"));
    assertThat(ClassUtils.getShortClassName(String.class), is("String"));
    assertThat(ClassUtils.getSimpleName(String.class), is("String"));
    assertThat(ClassUtils.isAssignable(String.class, Object.class), is(true));
    assertThat(ClassUtils.isInnerClass(Foo.class), is(true));
    assertThat(ClassUtils.isInnerClass(String.class), is(false));
    assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class), is(true));
    assertThat(ClassUtils.isPrimitiveOrWrapper(String.class), is(false));
    assertThat(ClassUtils.isPrimitiveWrapper(Integer.class), is(true));
    assertThat(ClassUtils.isPrimitiveWrapper(String.class), is(false));
    assertThat(ClassUtils.primitivesToWrappers(new Class[] { Integer.class, Long.class }),
            is(not(nullValue())));
    assertThat(ClassUtils.primitiveToWrapper(Integer.class), is(not(nullValue())));
    assertThat(ClassUtils.toClass(1L, 2L), is(not(nullValue())));
    assertThat(ClassUtils.wrappersToPrimitives(new Class[] { Integer.class, Long.class }),
            is(not(nullValue())));
    assertThat(ClassUtils.wrapperToPrimitive(Integer.class), is(not(nullValue())));
}