List of usage examples for org.apache.commons.lang3 ClassUtils getShortClassName
public static String getShortClassName(String className)
Gets the class name minus the package name from a String.
The string passed in is assumed to be a class name - it is not checked.
Note that this method differs from Class.getSimpleName() in that this will return "Map.Entry" whilst the java.lang.Class variant will simply return "Entry" .
From source file:org.evosuite.testcase.ConstructorStatement.java
/** * <p>/*from w w w . ja v a 2s. co m*/ * getReturnType * </p> * * @param clazz * a {@link java.lang.Class} object. * @return a {@link java.lang.String} object. */ public static String getReturnType(Class<?> clazz) { String retVal = ClassUtils.getShortClassName(clazz); if (primitiveClasses.contains(retVal)) return clazz.getSimpleName(); return retVal; }
From source file:org.evosuite.utils.generic.GenericClass.java
/** * <p>/* w w w. j a v a 2 s . c o m*/ * getSimpleName * </p> * * @return a {@link java.lang.String} object. */ public String getSimpleName() { // return raw_class.getSimpleName(); String name = ClassUtils.getShortClassName(rawClass).replace(";", "[]"); if (!isPrimitive() && primitiveClasses.contains(name)) return rawClass.getSimpleName().replace(";", "[]"); return name; }
From source file:uk.q3c.krail.core.validation.DefaultKrailInterpolator.java
/** * Find a an I18NKey from its full string representation (for example uk.q3c.krail.i18n.LabelKey.Yes). The full * string representation can be obtained using {@link I18NKey#fullName(I18NKey)} * * @param keyName/*from w w w . j a va2 s . com*/ * * @return the I18NKey for the supplied name, or null if not found for any reason */ protected I18NKey findI18NKey(String keyName) { String k = keyName.replace("{", "").replace("}", "").trim(); //This is cheating, using ClassUtils to split by '.', these are not package and class names String enumClassName = ClassUtils.getPackageCanonicalName(k); String constantName = ClassUtils.getShortClassName(k); Enum<?> enumConstant; try { Class<Enum> enumClass = (Class<Enum>) Class.forName(enumClassName); enumConstant = Enum.valueOf(enumClass, constantName); } catch (Exception e) { log.warn("Could not find an I18NKey for {}", k); enumConstant = null; } I18NKey key = (I18NKey) enumConstant; return key; }
From source file:uk.q3c.krail.core.validation.KrailInterpolator.java
/** * Find a an I18NKey from its full string representation (for example uk.q3c.krail.core.entity.LabelKey.Yes). The full * string representation can be obtained using {@link I18NKey#fullName(I18NKey)} * * @param keyName/* w w w .j a v a2s.com*/ * * @return the I18NKey for the supplied name, or null if not found for any reason */ protected I18NKey findI18NKey(String keyName) { String k = keyName.replace("{", "").replace("}", "").trim(); //This is cheating, using ClassUtils to split by '.', these are not package and class names String enumClassName = ClassUtils.getPackageCanonicalName(k); String constantName = ClassUtils.getShortClassName(k); Enum<?> enumConstant; try { Class<Enum> enumClass = (Class<Enum>) Class.forName(enumClassName); enumConstant = Enum.valueOf(enumClass, constantName); } catch (Exception e) { log.warn("Could not find an I18NKey for {}", k); enumConstant = null; } return (I18NKey) enumConstant; }
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<?>>() { {/*ww w . j ava 2s.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()))); }