一、前言
关于hotswap的hotswap-agent-1.1.0-SNAPSHOT.jar源码包中org.hotswap.agent.util.spring.util.ClassUtils类工具类,对获取默认类加载器getDefaultClassLoader、获取当前线程加载器overrideThreadContextClassLoader、修改类名称resolveClassName、根据实例对象获取class对象getUserClass、类型匹配matchesTypeName、类字符串转换classNamesToString等相关处理。
二、源码说明
package org.hotswap.agent.util.spring.util;@b@@b@import java.beans.Introspector;@b@import java.lang.reflect.Array;@b@import java.lang.reflect.Constructor;@b@import java.lang.reflect.Method;@b@import java.lang.reflect.Modifier;@b@import java.lang.reflect.Proxy;@b@import java.util.Arrays;@b@import java.util.Collection;@b@import java.util.Collections;@b@import java.util.HashMap;@b@import java.util.HashSet;@b@import java.util.IdentityHashMap;@b@import java.util.Iterator;@b@import java.util.LinkedHashSet;@b@import java.util.Map;@b@import java.util.Map.Entry;@b@import java.util.Set;@b@@b@public abstract class ClassUtils@b@{@b@ public static final String ARRAY_SUFFIX = "[]";@b@ private static final String INTERNAL_ARRAY_PREFIX = "[";@b@ private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";@b@ private static final char PACKAGE_SEPARATOR = 46;@b@ private static final char PATH_SEPARATOR = 47;@b@ private static final char INNER_CLASS_SEPARATOR = 36;@b@ public static final String CGLIB_CLASS_SEPARATOR = "$$";@b@ public static final String CLASS_FILE_SUFFIX = ".class";@b@ private static final Map<java.lang.Class<?>, java.lang.Class<?>> primitiveWrapperTypeMap = new IdentityHashMap(8);@b@ private static final Map<java.lang.Class<?>, java.lang.Class<?>> primitiveTypeToWrapperMap = new IdentityHashMap(8);@b@ private static final Map<String, java.lang.Class<?>> primitiveTypeNameMap = new HashMap(32);@b@ private static final Map<String, java.lang.Class<?>> commonClassCache = new HashMap(32);@b@@b@ private static void registerCommonClasses(java.lang.Class<?>[] commonClasses)@b@ {@b@ java.lang.Class[] arr$ = commonClasses; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { java.lang.Class clazz = arr$[i$];@b@ commonClassCache.put(clazz.getName(), clazz);@b@ }@b@ }@b@@b@ public static ClassLoader getDefaultClassLoader()@b@ {@b@ ClassLoader cl = null;@b@ try {@b@ cl = Thread.currentThread().getContextClassLoader();@b@ }@b@ catch (Throwable localThrowable1) {@b@ }@b@ if (cl == null)@b@ {@b@ cl = ClassUtils.class.getClassLoader();@b@ if (cl == null)@b@ {@b@ try@b@ {@b@ cl = ClassLoader.getSystemClassLoader();@b@ }@b@ catch (Throwable localThrowable2)@b@ {@b@ }@b@ }@b@ }@b@ return cl;@b@ }@b@@b@ public static ClassLoader overrideThreadContextClassLoader(ClassLoader classLoaderToUse)@b@ {@b@ Thread currentThread = Thread.currentThread();@b@ ClassLoader threadContextClassLoader = currentThread.getContextClassLoader();@b@ if ((classLoaderToUse != null) && (!(classLoaderToUse.equals(threadContextClassLoader)))) {@b@ currentThread.setContextClassLoader(classLoaderToUse);@b@ return threadContextClassLoader;@b@ }@b@ return null;@b@ }@b@@b@ public static java.lang.Class<?> forName(String name, ClassLoader classLoader)@b@ throws ClassNotFoundException, LinkageError@b@ {@b@ String elementName;@b@ java.lang.Class elementClass;@b@ Assert.notNull(name, "Name must not be null");@b@@b@ java.lang.Class clazz = resolvePrimitiveClassName(name);@b@ if (clazz == null)@b@ clazz = (java.lang.Class)commonClassCache.get(name);@b@@b@ if (clazz != null) {@b@ return clazz;@b@ }@b@@b@ if (name.endsWith("[]")) {@b@ String elementClassName = name.substring(0, name.length() - "[]".length());@b@ elementClass = forName(elementClassName, classLoader);@b@ return Array.newInstance(elementClass, 0).getClass();@b@ }@b@@b@ if ((name.startsWith("[L")) && (name.endsWith(";"))) {@b@ elementName = name.substring("[L".length(), name.length() - 1);@b@ elementClass = forName(elementName, classLoader);@b@ return Array.newInstance(elementClass, 0).getClass();@b@ }@b@@b@ if (name.startsWith("[")) {@b@ elementName = name.substring("[".length());@b@ elementClass = forName(elementName, classLoader);@b@ return Array.newInstance(elementClass, 0).getClass();@b@ }@b@@b@ ClassLoader clToUse = classLoader;@b@ if (clToUse == null)@b@ clToUse = getDefaultClassLoader();@b@ try@b@ {@b@ return ((clToUse != null) ? clToUse.loadClass(name) : java.lang.Class.forName(name));@b@ } catch (ClassNotFoundException ex) {@b@ String innerClassName;@b@ int lastDotIndex = name.lastIndexOf(46);@b@ if (lastDotIndex != -1)@b@ innerClassName = new StringBuilder().append(name.substring(0, lastDotIndex)).append('$').append(name.substring(lastDotIndex + 1)).toString();@b@ try {@b@ return ((clToUse != null) ? clToUse.loadClass(innerClassName) : java.lang.Class.forName(innerClassName));@b@ }@b@ catch (ClassNotFoundException localClassNotFoundException1)@b@ {@b@ throw ex;@b@ }@b@ }@b@ }@b@@b@ public static java.lang.Class<?> resolveClassName(String className, ClassLoader classLoader)@b@ throws IllegalArgumentException@b@ {@b@ try@b@ {@b@ return forName(className, classLoader);@b@ } catch (ClassNotFoundException ex) {@b@ throw new IllegalArgumentException(new StringBuilder().append("Cannot find class [").append(className).append("]").toString(), ex);@b@ } catch (LinkageError ex) {@b@ throw new IllegalArgumentException(new StringBuilder().append("Error loading class [").append(className).append("]: problem with class file or dependent class.").toString(), ex);@b@ }@b@ }@b@@b@ public static java.lang.Class<?> resolvePrimitiveClassName(String name)@b@ {@b@ java.lang.Class result = null;@b@@b@ if ((name != null) && (name.length() <= 8))@b@ {@b@ result = (java.lang.Class)primitiveTypeNameMap.get(name);@b@ }@b@ return result;@b@ }@b@@b@ public static boolean isPresent(String className, ClassLoader classLoader)@b@ {@b@ try@b@ {@b@ forName(className, classLoader);@b@ return true;@b@ } catch (Throwable ex) {@b@ }@b@ return false;@b@ }@b@@b@ public static java.lang.Class<?> getUserClass(Object instance)@b@ {@b@ Assert.notNull(instance, "Instance must not be null");@b@ return getUserClass(instance.getClass());@b@ }@b@@b@ public static java.lang.Class<?> getUserClass(java.lang.Class<?> clazz)@b@ {@b@ if ((clazz != null) && (clazz.getName().contains("$$"))) {@b@ java.lang.Class superclass = clazz.getSuperclass();@b@ if ((superclass != null) && (Object.class != superclass))@b@ return superclass;@b@ }@b@@b@ return clazz;@b@ }@b@@b@ public static boolean isCacheSafe(java.lang.Class<?> clazz, ClassLoader classLoader)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ try {@b@ ClassLoader target = clazz.getClassLoader();@b@ if (target == null)@b@ return true;@b@@b@ ClassLoader cur = classLoader;@b@ if (cur == target)@b@ return true;@b@ do {@b@ if (cur == null) break label42;@b@ cur = cur.getParent(); }@b@ while (cur != target);@b@ return true;@b@@b@ label42: return false;@b@ } catch (SecurityException ex) {@b@ }@b@ return true;@b@ }@b@@b@ public static String getShortName(String className)@b@ {@b@ Assert.hasLength(className, "Class name must not be empty");@b@ int lastDotIndex = className.lastIndexOf(46);@b@ int nameEndIndex = className.indexOf("$$");@b@ if (nameEndIndex == -1)@b@ nameEndIndex = className.length();@b@@b@ String shortName = className.substring(lastDotIndex + 1, nameEndIndex);@b@ shortName = shortName.replace('$', '.');@b@ return shortName;@b@ }@b@@b@ public static String getShortName(java.lang.Class<?> clazz)@b@ {@b@ return getShortName(getQualifiedName(clazz));@b@ }@b@@b@ public static String getShortNameAsProperty(java.lang.Class<?> clazz)@b@ {@b@ String shortName = getShortName(clazz);@b@ int dotIndex = shortName.lastIndexOf(46);@b@ shortName = (dotIndex != -1) ? shortName.substring(dotIndex + 1) : shortName;@b@ return Introspector.decapitalize(shortName);@b@ }@b@@b@ public static String getClassFileName(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ String className = clazz.getName();@b@ int lastDotIndex = className.lastIndexOf(46);@b@ return new StringBuilder().append(className.substring(lastDotIndex + 1)).append(".class").toString();@b@ }@b@@b@ public static String getPackageName(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return getPackageName(clazz.getName());@b@ }@b@@b@ public static String getPackageName(String fqClassName)@b@ {@b@ Assert.notNull(fqClassName, "Class name must not be null");@b@ int lastDotIndex = fqClassName.lastIndexOf(46);@b@ return ((lastDotIndex != -1) ? fqClassName.substring(0, lastDotIndex) : "");@b@ }@b@@b@ public static String getQualifiedName(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ if (clazz.isArray())@b@ return getQualifiedNameForArray(clazz);@b@@b@ return clazz.getName();@b@ }@b@@b@ private static String getQualifiedNameForArray(java.lang.Class<?> clazz)@b@ {@b@ StringBuilder result = new StringBuilder();@b@ while (clazz.isArray()) {@b@ clazz = clazz.getComponentType();@b@ result.append("[]");@b@ }@b@ result.insert(0, clazz.getName());@b@ return result.toString();@b@ }@b@@b@ public static String getQualifiedMethodName(Method method)@b@ {@b@ Assert.notNull(method, "Method must not be null");@b@ return new StringBuilder().append(method.getDeclaringClass().getName()).append(".").append(method.getName()).toString();@b@ }@b@@b@ public static String getDescriptiveType(Object value)@b@ {@b@ if (value == null)@b@ return null;@b@@b@ java.lang.Class clazz = value.getClass();@b@ if (Proxy.isProxyClass(clazz)) {@b@ StringBuilder result = new StringBuilder(clazz.getName());@b@ result.append(" implementing ");@b@ java.lang.Class[] ifcs = clazz.getInterfaces();@b@ for (int i = 0; i < ifcs.length; ++i) {@b@ result.append(ifcs[i].getName());@b@ if (i < ifcs.length - 1)@b@ result.append(',');@b@ }@b@@b@ return result.toString(); }@b@ if (clazz.isArray())@b@ return getQualifiedNameForArray(clazz);@b@@b@ return clazz.getName();@b@ }@b@@b@ public static boolean matchesTypeName(java.lang.Class<?> clazz, String typeName)@b@ {@b@ return ((typeName != null) && (((typeName.equals(clazz.getName())) || (typeName.equals(clazz.getSimpleName())) || ((clazz.isArray()) && (typeName.equals(getQualifiedNameForArray(clazz)))))));@b@ }@b@@b@ public static boolean hasConstructor(java.lang.Class<?> clazz, java.lang.Class<?>[] paramTypes)@b@ {@b@ return (getConstructorIfAvailable(clazz, paramTypes) != null);@b@ }@b@@b@ public static <T> Constructor<T> getConstructorIfAvailable(java.lang.Class<T> clazz, java.lang.Class<?>[] paramTypes)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ try {@b@ return clazz.getConstructor(paramTypes); } catch (NoSuchMethodException ex) {@b@ }@b@ return null;@b@ }@b@@b@ public static boolean hasMethod(java.lang.Class<?> clazz, String methodName, java.lang.Class<?>[] paramTypes)@b@ {@b@ return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);@b@ }@b@@b@ public static Method getMethod(java.lang.Class<?> clazz, String methodName, java.lang.Class<?>[] paramTypes)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ Assert.notNull(methodName, "Method name must not be null");@b@ if (paramTypes != null)@b@ try {@b@ return clazz.getMethod(methodName, paramTypes);@b@ } catch (NoSuchMethodException ex) {@b@ throw new IllegalStateException(new StringBuilder().append("Expected method not found: ").append(ex).toString());@b@ }@b@@b@ Set candidates = new HashSet(1);@b@ Method[] methods = clazz.getMethods();@b@ Method[] arr$ = methods; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Method method = arr$[i$];@b@ if (methodName.equals(method.getName()))@b@ candidates.add(method);@b@ }@b@@b@ if (candidates.size() == 1)@b@ return ((Method)candidates.iterator().next());@b@ if (candidates.isEmpty())@b@ throw new IllegalStateException(new StringBuilder().append("Expected method not found: ").append(clazz).append(".").append(methodName).toString());@b@@b@ throw new IllegalStateException(new StringBuilder().append("No unique method found: ").append(clazz).append(".").append(methodName).toString());@b@ }@b@@b@ public static Method getMethodIfAvailable(java.lang.Class<?> clazz, String methodName, java.lang.Class<?>[] paramTypes)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ Assert.notNull(methodName, "Method name must not be null");@b@ if (paramTypes != null)@b@ try {@b@ return clazz.getMethod(methodName, paramTypes);@b@ } catch (NoSuchMethodException ex) {@b@ return null;@b@ }@b@@b@ Set candidates = new HashSet(1);@b@ Method[] methods = clazz.getMethods();@b@ Method[] arr$ = methods; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Method method = arr$[i$];@b@ if (methodName.equals(method.getName()))@b@ candidates.add(method);@b@ }@b@@b@ if (candidates.size() == 1)@b@ return ((Method)candidates.iterator().next());@b@@b@ return null;@b@ }@b@@b@ public static int getMethodCountForName(java.lang.Class<?> clazz, String methodName)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ Assert.notNull(methodName, "Method name must not be null");@b@ int count = 0;@b@ Method[] declaredMethods = clazz.getDeclaredMethods();@b@ Method[] arr$ = declaredMethods; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Method method = arr$[i$];@b@ if (methodName.equals(method.getName()))@b@ ++count;@b@ }@b@@b@ java.lang.Class[] ifcs = clazz.getInterfaces();@b@ java.lang.Class[] arr$ = ifcs; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { java.lang.Class ifc = arr$[i$];@b@ count += getMethodCountForName(ifc, methodName);@b@ }@b@ if (clazz.getSuperclass() != null)@b@ count += getMethodCountForName(clazz.getSuperclass(), methodName);@b@@b@ return count;@b@ }@b@@b@ public static boolean hasAtLeastOneMethodWithName(java.lang.Class<?> clazz, String methodName)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ Assert.notNull(methodName, "Method name must not be null");@b@ Method[] declaredMethods = clazz.getDeclaredMethods();@b@ Method[] arr$ = declaredMethods; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Method method = arr$[i$];@b@ if (method.getName().equals(methodName))@b@ return true;@b@ }@b@@b@ java.lang.Class[] ifcs = clazz.getInterfaces();@b@ java.lang.Class[] arr$ = ifcs; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { java.lang.Class ifc = arr$[i$];@b@ if (hasAtLeastOneMethodWithName(ifc, methodName))@b@ return true;@b@ }@b@@b@ return ((clazz.getSuperclass() != null) && (hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName)));@b@ }@b@@b@ public static Method getMostSpecificMethod(Method method, java.lang.Class<?> targetClass)@b@ {@b@ if ((method != null) && (isOverridable(method, targetClass)) && (targetClass != null) && (!(targetClass.equals(method.getDeclaringClass()))))@b@ try {@b@ if (Modifier.isPublic(method.getModifiers()))@b@ try {@b@ return targetClass.getMethod(method.getName(), method.getParameterTypes());@b@ } catch (NoSuchMethodException ex) {@b@ return method;@b@ }@b@@b@ specificMethod = ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());@b@ return ((specificMethod != null) ? specificMethod : method);@b@ }@b@ catch (SecurityException specificMethod)@b@ {@b@ }@b@@b@@b@ return method;@b@ }@b@@b@ public static boolean isUserLevelMethod(Method method)@b@ {@b@ Assert.notNull(method, "Method must not be null");@b@ return ((method.isBridge()) || ((!(method.isSynthetic())) && (!(isGroovyObjectMethod(method)))));@b@ }@b@@b@ private static boolean isGroovyObjectMethod(Method method) {@b@ return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");@b@ }@b@@b@ private static boolean isOverridable(Method method, java.lang.Class<?> targetClass)@b@ {@b@ if (Modifier.isPrivate(method.getModifiers()))@b@ return false;@b@@b@ if ((Modifier.isPublic(method.getModifiers())) || (Modifier.isProtected(method.getModifiers())))@b@ return true;@b@@b@ return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));@b@ }@b@@b@ public static Method getStaticMethod(java.lang.Class<?> clazz, String methodName, java.lang.Class<?>[] args)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ Assert.notNull(methodName, "Method name must not be null");@b@ try {@b@ Method method = clazz.getMethod(methodName, args);@b@ return ((Modifier.isStatic(method.getModifiers())) ? method : null); } catch (NoSuchMethodException ex) {@b@ }@b@ return null;@b@ }@b@@b@ public static boolean isPrimitiveWrapper(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return primitiveWrapperTypeMap.containsKey(clazz);@b@ }@b@@b@ public static boolean isPrimitiveOrWrapper(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return ((clazz.isPrimitive()) || (isPrimitiveWrapper(clazz)));@b@ }@b@@b@ public static boolean isPrimitiveArray(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return ((clazz.isArray()) && (clazz.getComponentType().isPrimitive()));@b@ }@b@@b@ public static boolean isPrimitiveWrapperArray(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return ((clazz.isArray()) && (isPrimitiveWrapper(clazz.getComponentType())));@b@ }@b@@b@ public static java.lang.Class<?> resolvePrimitiveIfNecessary(java.lang.Class<?> clazz)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ return (((clazz.isPrimitive()) && (clazz != Void.TYPE)) ? (java.lang.Class)primitiveTypeToWrapperMap.get(clazz) : clazz);@b@ }@b@@b@ public static boolean isAssignable(java.lang.Class<?> lhsType, java.lang.Class<?> rhsType)@b@ {@b@ Assert.notNull(lhsType, "Left-hand side type must not be null");@b@ Assert.notNull(rhsType, "Right-hand side type must not be null");@b@ if (lhsType.isAssignableFrom(rhsType))@b@ return true;@b@@b@ if (lhsType.isPrimitive()) {@b@ java.lang.Class resolvedPrimitive = (java.lang.Class)primitiveWrapperTypeMap.get(rhsType);@b@ if ((resolvedPrimitive != null) && (lhsType.equals(resolvedPrimitive)))@b@ return true;@b@@b@ break label86: }@b@ java.lang.Class resolvedWrapper = (java.lang.Class)primitiveTypeToWrapperMap.get(rhsType);@b@@b@ label86: return ((resolvedWrapper != null) && (lhsType.isAssignableFrom(resolvedWrapper)));@b@ }@b@@b@ public static boolean isAssignableValue(java.lang.Class<?> type, Object value)@b@ {@b@ Assert.notNull(type, "Type must not be null");@b@ return ((!(type.isPrimitive())) ? true : (value != null) ? isAssignable(type, value.getClass()) : false);@b@ }@b@@b@ public static String convertResourcePathToClassName(String resourcePath)@b@ {@b@ Assert.notNull(resourcePath, "Resource path must not be null");@b@ return resourcePath.replace('/', '.');@b@ }@b@@b@ public static String convertClassNameToResourcePath(String className)@b@ {@b@ Assert.notNull(className, "Class name must not be null");@b@ return className.replace('.', '/');@b@ }@b@@b@ public static String addResourcePathToPackagePath(java.lang.Class<?> clazz, String resourceName)@b@ {@b@ Assert.notNull(resourceName, "Resource name must not be null");@b@ if (!(resourceName.startsWith("/")))@b@ return new StringBuilder().append(classPackageAsResourcePath(clazz)).append("/").append(resourceName).toString();@b@@b@ return new StringBuilder().append(classPackageAsResourcePath(clazz)).append(resourceName).toString();@b@ }@b@@b@ public static String classPackageAsResourcePath(java.lang.Class<?> clazz)@b@ {@b@ if (clazz == null)@b@ return "";@b@@b@ String className = clazz.getName();@b@ int packageEndIndex = className.lastIndexOf(46);@b@ if (packageEndIndex == -1)@b@ return "";@b@@b@ String packageName = className.substring(0, packageEndIndex);@b@ return packageName.replace('.', '/');@b@ }@b@@b@ public static String classNamesToString(java.lang.Class<?>[] classes)@b@ {@b@ return classNamesToString(Arrays.asList(classes));@b@ }@b@@b@ public static String classNamesToString(Collection<java.lang.Class<?>> classes)@b@ {@b@ if (CollectionUtils.isEmpty(classes))@b@ return "[]";@b@@b@ StringBuilder sb = new StringBuilder("[");@b@ for (Iterator it = classes.iterator(); it.hasNext(); ) {@b@ java.lang.Class clazz = (java.lang.Class)it.next();@b@ sb.append(clazz.getName());@b@ if (it.hasNext())@b@ sb.append(", ");@b@ }@b@@b@ sb.append("]");@b@ return sb.toString();@b@ }@b@@b@ public static java.lang.Class<?>[] toClassArray(Collection<java.lang.Class<?>> collection)@b@ {@b@ if (collection == null)@b@ return null;@b@@b@ return ((java.lang.Class[])collection.toArray(new java.lang.Class[collection.size()]));@b@ }@b@@b@ public static java.lang.Class<?>[] getAllInterfaces(Object instance)@b@ {@b@ Assert.notNull(instance, "Instance must not be null");@b@ return getAllInterfacesForClass(instance.getClass());@b@ }@b@@b@ public static java.lang.Class<?>[] getAllInterfacesForClass(java.lang.Class<?> clazz)@b@ {@b@ return getAllInterfacesForClass(clazz, null);@b@ }@b@@b@ public static java.lang.Class<?>[] getAllInterfacesForClass(java.lang.Class<?> clazz, ClassLoader classLoader)@b@ {@b@ Set ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);@b@ return ((java.lang.Class[])ifcs.toArray(new java.lang.Class[ifcs.size()]));@b@ }@b@@b@ public static Set<java.lang.Class<?>> getAllInterfacesAsSet(Object instance)@b@ {@b@ Assert.notNull(instance, "Instance must not be null");@b@ return getAllInterfacesForClassAsSet(instance.getClass());@b@ }@b@@b@ public static Set<java.lang.Class<?>> getAllInterfacesForClassAsSet(java.lang.Class<?> clazz)@b@ {@b@ return getAllInterfacesForClassAsSet(clazz, null);@b@ }@b@@b@ public static Set<java.lang.Class<?>> getAllInterfacesForClassAsSet(java.lang.Class<?> clazz, ClassLoader classLoader)@b@ {@b@ Assert.notNull(clazz, "Class must not be null");@b@ if ((clazz.isInterface()) && (isVisible(clazz, classLoader)))@b@ return Collections.singleton(clazz);@b@@b@ Set interfaces = new LinkedHashSet();@b@ while (clazz != null) {@b@ java.lang.Class[] ifcs = clazz.getInterfaces();@b@ java.lang.Class[] arr$ = ifcs; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { java.lang.Class ifc = arr$[i$];@b@ interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));@b@ }@b@ clazz = clazz.getSuperclass();@b@ }@b@ return interfaces;@b@ }@b@@b@ public static java.lang.Class<?> createCompositeInterface(java.lang.Class<?>[] interfaces, ClassLoader classLoader)@b@ {@b@ Assert.notEmpty(interfaces, "Interfaces must not be empty");@b@ Assert.notNull(classLoader, "ClassLoader must not be null");@b@ return Proxy.getProxyClass(classLoader, interfaces);@b@ }@b@@b@ public static java.lang.Class<?> determineCommonAncestor(java.lang.Class<?> clazz1, java.lang.Class<?> clazz2)@b@ {@b@ if (clazz1 == null)@b@ return clazz2;@b@@b@ if (clazz2 == null)@b@ return clazz1;@b@@b@ if (clazz1.isAssignableFrom(clazz2))@b@ return clazz1;@b@@b@ if (clazz2.isAssignableFrom(clazz1))@b@ return clazz2;@b@@b@ java.lang.Class ancestor = clazz1;@b@ do {@b@ ancestor = ancestor.getSuperclass();@b@ if ((ancestor == null) || (Object.class == ancestor))@b@ return null;@b@ }@b@ while (!(ancestor.isAssignableFrom(clazz2)));@b@ return ancestor;@b@ }@b@@b@ public static boolean isVisible(java.lang.Class<?> clazz, ClassLoader classLoader)@b@ {@b@ if (classLoader == null)@b@ return true;@b@ try@b@ {@b@ java.lang.Class actualClass = classLoader.loadClass(clazz.getName());@b@ return (clazz == actualClass);@b@ }@b@ catch (ClassNotFoundException ex) {@b@ }@b@ return false;@b@ }@b@@b@ public static boolean isCglibProxy(Object object)@b@ {@b@ return isCglibProxyClass(object.getClass());@b@ }@b@@b@ public static boolean isCglibProxyClass(java.lang.Class<?> clazz)@b@ {@b@ return ((clazz != null) && (isCglibProxyClassName(clazz.getName())));@b@ }@b@@b@ public static boolean isCglibProxyClassName(String className)@b@ {@b@ return ((className != null) && (className.contains("$$")));@b@ }@b@@b@ static@b@ {@b@ primitiveWrapperTypeMap.put(Boolean.class, Boolean.TYPE);@b@ primitiveWrapperTypeMap.put(Byte.class, Byte.TYPE);@b@ primitiveWrapperTypeMap.put(Character.class, Character.TYPE);@b@ primitiveWrapperTypeMap.put(Double.class, Double.TYPE);@b@ primitiveWrapperTypeMap.put(Float.class, Float.TYPE);@b@ primitiveWrapperTypeMap.put(Integer.class, Integer.TYPE);@b@ primitiveWrapperTypeMap.put(Long.class, Long.TYPE);@b@ primitiveWrapperTypeMap.put(Short.class, Short.TYPE);@b@@b@ for (Map.Entry entry : primitiveWrapperTypeMap.entrySet()) {@b@ primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());@b@ registerCommonClasses(new java.lang.Class[] { (java.lang.Class)entry.getKey() });@b@ }@b@@b@ Set primitiveTypes = new HashSet(32);@b@ primitiveTypes.addAll(primitiveWrapperTypeMap.values());@b@ primitiveTypes.addAll(Arrays.asList(new java.lang.Class[] { [Z.class, [B.class, [C.class, [D.class, [F.class, [I.class, [J.class, [S.class }));@b@ primitiveTypes.add(Void.TYPE);@b@ for (java.lang.Class primitiveType : primitiveTypes) {@b@ primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);@b@ }@b@@b@ registerCommonClasses(new java.lang.Class[] { [Ljava.lang.Boolean.class, [Ljava.lang.Byte.class, [Ljava.lang.Character.class, [Ljava.lang.Double.class, [Ljava.lang.Float.class, [Ljava.lang.Integer.class, [Ljava.lang.Long.class, [Ljava.lang.Short.class });@b@ registerCommonClasses(new java.lang.Class[] { Number.class, [Ljava.lang.Number.class, String.class, [Ljava.lang.String.class, Object.class, [Ljava.lang.Object.class, java.lang.Class.class, [Ljava.lang.Class.class });@b@ registerCommonClasses(new java.lang.Class[] { Throwable.class, Exception.class, RuntimeException.class, Error.class, StackTraceElement.class, [Ljava.lang.StackTraceElement.class });@b@ }@b@}