ClassUtils { public static String canonicalName(Class clazz) { StringBuilder name = new StringBuilder(); if ( clazz.isArray() ) { name.append( canonicalName( clazz.getComponentType() ) ); name.append( "[]" ); } else if ( clazz.getDeclaringClass() == null ) { name.append( clazz.getName() ); } else { name.append( canonicalName( clazz.getDeclaringClass() ) ); name.append( "." ); name.append( clazz.getName().substring( clazz.getDeclaringClass().getName().length() + 1 ) ); } return name.toString(); }  static boolean areNullSafeEquals(Object obj1, Object obj2); static String convertResourceToClassName(final String pResourceName); static String convertClassToResourcePath(final Class cls); static String convertClassToResourcePath(final String pName); static String stripExtension(final String pResourceName); static String toJavaCasing(final String pName); static String clazzName(final File base,
                                   final File file); static String relative(final File base,
                                  final File file); static String canonicalName(Class clazz); static Class<?> loadClass(String className,
                                     ClassLoader classLoader); static Object instantiateObject(String className); static Object instantiateObject(String className,
                                           ClassLoader classLoader); static Object instantiateObject(String className,
                                           ClassLoader classLoader, Object...args); static Object instantiateObject(String className, Object...args); static void addImportStylePatterns(Map<String, Object> patterns,
                                              String str); static boolean isMatched(Map<String, Object> patterns,
                                    String className); static String getPackage(Class<?> cls); static Class<?> findClass(String name, Collection<String> availableImports, ClassLoader cl); static Class<?> findClass(String className, ClassLoader cl); static List<String> getAccessibleProperties( Class<?> clazz ); static Field getField(Class<?> clazz, String field); static Method getAccessor(Class<?> clazz, String field); static Method getSetter(Class<?> clazz, String field, Class<?> parameterType); static Member getFieldOrAccessor( Class clazz, String property); static Class extractGenericType(Class<?> clazz, final String methodName); static boolean isTypeCompatibleWithArgumentType( Class<?> actual, Class<?> formal ); static boolean isAssignable( Class<?> type, Object obj ); static boolean isConvertible( Class<?> srcPrimitive, Class<?> tgtPrimitive ); static boolean isFinal(Class<?> clazz); static boolean isInterface(Class<?> clazz); static String getter2property(String methodName); static String setter2property(String methodName); static boolean isGetter(String methodName); static boolean isSetter(String methodName); static T deepClone(T origin); static T deepClone(T origin, ClassLoader classLoader); static T deepClone(T origin, ClassLoader classLoader, Map<String, Object> cloningResources); static Class<?> convertFromPrimitiveType(Class<?> type); static Class<?> convertToPrimitiveType(Class<?> type); static Class<?> convertPrimitiveNameToType( String typeName ); static Set<Class<?>> getAllImplementedInterfaceNames( Class<?> klass ); static Set<Class<?>> getMinimalImplementedInterfaceNames( Class<?> klass ); static boolean isCaseSenstiveOS(); static boolean isWindows(); static boolean isOSX(); static boolean isJboss(); static boolean isAndroid(); static Class<?> findCommonSuperClass(Class<?> c1, Class<?> c2); static Class<?> getClassFromName(String className); static Class<?> getClassFromName(String className, boolean initialize, ClassLoader classLoader); static Class<?> safeLoadClass(ClassLoader cl, String name); static String getSimpleName(Class<?> c); static String getCanonicalSimpleName(Class<?> c); static String getCanonicalSimpleName(Class<?> c, char separator); static final boolean IS_ANDROID; }
@Test public void testCanonicalNameSimpleClass() { String name = ClassUtils.canonicalName( ClassUtilsTest.class ); assertEquals( "org.drools.core.util.ClassUtilsTest", name ); }
@Test public void testCanonicalNameInnerClass() { String name = ClassUtils.canonicalName( A.class ); assertEquals( "org.drools.core.util.ClassUtilsTest.A", name ); }
@Test public void testCanonicalNameInnerInnerClass() { String name = ClassUtils.canonicalName( A.B.class ); assertEquals( "org.drools.core.util.ClassUtilsTest.A.B", name ); }
@Test public void testCanonicalNameArray() { String name = ClassUtils.canonicalName( Object[].class ); assertEquals( "java.lang.Object[]", name ); }
@Test public void testCanonicalNameMultiIndexArray() { String name = ClassUtils.canonicalName( Object[][][].class ); assertEquals( "java.lang.Object[][][]", name ); }
@Test public void testCanonicalNameMultiIndexArrayInnerClass() { String name = ClassUtils.canonicalName( A.B[][][].class ); assertEquals( "org.drools.core.util.ClassUtilsTest.A.B[][][]", name ); }
@Test public void testCanonicalNameMultiIndexArrayPrimitives() { String name = ClassUtils.canonicalName( long[][][].class ); assertEquals( "long[][][]", name ); }