From 0eeb7c904c84d44bab0101d568e22bfa8177c34c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Jan 2006 18:30:30 +0000 Subject: [PATCH] Fix formatting to lang standards git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@360513 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/ClassUtils.java | 118 ++++++++++-------- 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/src/java/org/apache/commons/lang/ClassUtils.java b/src/java/org/apache/commons/lang/ClassUtils.java index f96d8d397..4d830fe46 100644 --- a/src/java/org/apache/commons/lang/ClassUtils.java +++ b/src/java/org/apache/commons/lang/ClassUtils.java @@ -518,92 +518,102 @@ public class ClassUtils { return cls.getName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0; } + // Class loading + // ---------------------------------------------------------------------- /** - * Returns the class represented by className using the classLoader. This implementation - * supports names like "java.lang.String[]" as well as "[Ljava.lang.String;". + * Returns the class represented by className using the + * classLoader. This implementation supports names like + * "java.lang.String[]" as well as "[Ljava.lang.String;". * - * @param classLoader the class loader to use to load the class - * @param className the class name + * @param classLoader the class loader to use to load the class + * @param className the class name * @param initialize whether the class must be initialized * @return the class represented by className using the classLoader * @throws ClassNotFoundException if the class is not found */ - public static Class getClass( ClassLoader classLoader, String className, boolean initialize ) - throws ClassNotFoundException { + public static Class getClass( + ClassLoader classLoader, String className, boolean initialize) throws ClassNotFoundException { Class clazz; - if( abbreviationMap.containsKey( className ) ) { - clazz = Class.forName( "[" + abbreviationMap.get( className ), initialize, classLoader ).getComponentType(); - } - else { - clazz = Class.forName( toProperClassName( className ), initialize, classLoader ); + if (abbreviationMap.containsKey(className)) { + String clsName = "[" + abbreviationMap.get(className); + clazz = Class.forName(clsName, initialize, classLoader).getComponentType(); + } else { + clazz = Class.forName(toProperClassName(className), initialize, classLoader); } return clazz; } /** - * Returns the (initialized) class represented by className using the classLoader. This - * implementation supports names like "java.lang.String[]" as well as + * Returns the (initialized) class represented by className + * using the classLoader. This implementation supports names + * like "java.lang.String[]" as well as * "[Ljava.lang.String;". * - * @param classLoader the class loader to use to load the class - * @param className the class name + * @param classLoader the class loader to use to load the class + * @param className the class name * @return the class represented by className using the classLoader * @throws ClassNotFoundException if the class is not found */ - public static Class getClass( ClassLoader classLoader, String className ) throws ClassNotFoundException { - return getClass( classLoader, className, true ); + public static Class getClass(ClassLoader classLoader, String className) throws ClassNotFoundException { + return getClass(classLoader, className, true); } /** - * Returns the (initialized )class represented by className using the current thread's context class - * loader. This implementation supports names like "java.lang.String[]" as well as - * "[Ljava.lang.String;". - * - * @param className the class name - * @return the class represented by className using the current thread's context class loader - * @throws ClassNotFoundException if the class is not found - */ - public static Class getClass( String className ) throws ClassNotFoundException { - return getClass( Thread.currentThread().getContextClassLoader() == null ? ClassUtils.class.getClassLoader() : - Thread.currentThread().getContextClassLoader(), className, true ); - } - - /** - * Returns the class represented by className using the current thread's context class loader. This - * implementation supports names like "java.lang.String[]" as well as + * Returns the (initialized )class represented by className + * using the current thread's context class loader. This implementation + * supports names like "java.lang.String[]" as well as * "[Ljava.lang.String;". * * @param className the class name - * @param initialize whether the class must be initialized * @return the class represented by className using the current thread's context class loader * @throws ClassNotFoundException if the class is not found */ - public static Class getClass( String className, boolean initialize ) throws ClassNotFoundException { - return getClass( Thread.currentThread().getContextClassLoader() == null ? ClassUtils.class.getClassLoader() : - Thread.currentThread().getContextClassLoader(), className, initialize ); + public static Class getClass(String className) throws ClassNotFoundException { + return getClass(className, true); } - private static String toProperClassName( String className ) { - className = StringUtils.deleteWhitespace( className ); - if( className == null ) { - throw new NullArgumentException( "className" ); - } - else if( className.endsWith( "[]" ) ) { - final StringBuffer classNameBuffer = new StringBuffer(); - while( className.endsWith( "[]" ) ) { - className = className.substring( 0, className.length() - 2 ); - classNameBuffer.append( "[" ); + /** + * Returns the class represented by className using the + * current thread's context class loader. This implementation supports + * names like "java.lang.String[]" as well as + * "[Ljava.lang.String;". + * + * @param className the class name + * @param initialize whether the class must be initialized + * @return the class represented by className using the current thread's context class loader + * @throws ClassNotFoundException if the class is not found + */ + public static Class getClass(String className, boolean initialize) throws ClassNotFoundException { + ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); + ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL; + return getClass(loader, className, initialize ); + } + + /** + * Converts a class name to a JLS stle class name. + * + * @param className the class name + * @return the converted name + */ + private static String toProperClassName(String className) { + className = StringUtils.deleteWhitespace(className); + if (className == null) { + throw new NullArgumentException("className"); + } else if (className.endsWith("[]")) { + StringBuffer classNameBuffer = new StringBuffer(); + while (className.endsWith("[]")) { + className = className.substring(0, className.length() - 2); + classNameBuffer.append("["); } - final String abbreviation = ( String ) abbreviationMap.get( className ); - if( abbreviation != null ) { - classNameBuffer.append( abbreviation ); - } - else { - classNameBuffer.append( "L" ).append( className ).append( ";" ); + String abbreviation = (String) abbreviationMap.get(className); + if (abbreviation != null) { + classNameBuffer.append(abbreviation); + } else { + classNameBuffer.append("L").append(className).append(";"); } className = classNameBuffer.toString(); - } return className; } + }