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
This commit is contained in:
Stephen Colebourne 2006-01-01 18:30:30 +00:00
parent 42f9084b3b
commit 0eeb7c904c
1 changed files with 64 additions and 54 deletions

View File

@ -518,9 +518,12 @@ public class ClassUtils {
return cls.getName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0;
}
// Class loading
// ----------------------------------------------------------------------
/**
* Returns the class represented by <code>className</code> using the <code>classLoader</code>. This implementation
* supports names like "<code>java.lang.String[]</code>" as well as "<code>[Ljava.lang.String;</code>".
* Returns the class represented by <code>className</code> using the
* <code>classLoader</code>. This implementation supports names like
* "<code>java.lang.String[]</code>" as well as "<code>[Ljava.lang.String;</code>".
*
* @param classLoader the class loader to use to load the class
* @param className the class name
@ -528,21 +531,22 @@ public class ClassUtils {
* @return the class represented by <code>className</code> using the <code>classLoader</code>
* @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 <code>className</code> using the <code>classLoader</code>. This
* implementation supports names like "<code>java.lang.String[]</code>" as well as
* Returns the (initialized) class represented by <code>className</code>
* using the <code>classLoader</code>. This implementation supports names
* like "<code>java.lang.String[]</code>" as well as
* "<code>[Ljava.lang.String;</code>".
*
* @param classLoader the class loader to use to load the class
@ -550,27 +554,28 @@ public class ClassUtils {
* @return the class represented by <code>className</code> using the <code>classLoader</code>
* @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 <code>className</code> using the current thread's context class
* loader. This implementation supports names like "<code>java.lang.String[]</code>" as well as
* Returns the (initialized )class represented by <code>className</code>
* using the current thread's context class loader. This implementation
* supports names like "<code>java.lang.String[]</code>" as well as
* "<code>[Ljava.lang.String;</code>".
*
* @param className the class name
* @return the class represented by <code>className</code> 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 );
public static Class getClass(String className) throws ClassNotFoundException {
return getClass(className, true);
}
/**
* Returns the class represented by <code>className</code> using the current thread's context class loader. This
* implementation supports names like "<code>java.lang.String[]</code>" as well as
* Returns the class represented by <code>className</code> using the
* current thread's context class loader. This implementation supports
* names like "<code>java.lang.String[]</code>" as well as
* "<code>[Ljava.lang.String;</code>".
*
* @param className the class name
@ -578,32 +583,37 @@ public class ClassUtils {
* @return the class represented by <code>className</code> 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, boolean initialize) throws ClassNotFoundException {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL;
return getClass(loader, className, initialize );
}
private static String toProperClassName( String className ) {
className = StringUtils.deleteWhitespace( className );
if( className == null ) {
throw new NullArgumentException( "className" );
/**
* 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("[");
}
else if( className.endsWith( "[]" ) ) {
final 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;
}
}