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:
parent
42f9084b3b
commit
0eeb7c904c
|
@ -518,92 +518,102 @@ public class ClassUtils {
|
||||||
return cls.getName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0;
|
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
|
* Returns the class represented by <code>className</code> using the
|
||||||
* supports names like "<code>java.lang.String[]</code>" as well as "<code>[Ljava.lang.String;</code>".
|
* <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 classLoader the class loader to use to load the class
|
||||||
* @param className the class name
|
* @param className the class name
|
||||||
* @param initialize whether the class must be initialized
|
* @param initialize whether the class must be initialized
|
||||||
* @return the class represented by <code>className</code> using the <code>classLoader</code>
|
* @return the class represented by <code>className</code> using the <code>classLoader</code>
|
||||||
* @throws ClassNotFoundException if the class is not found
|
* @throws ClassNotFoundException if the class is not found
|
||||||
*/
|
*/
|
||||||
public static Class getClass( ClassLoader classLoader, String className, boolean initialize )
|
public static Class getClass(
|
||||||
throws ClassNotFoundException {
|
ClassLoader classLoader, String className, boolean initialize) throws ClassNotFoundException {
|
||||||
Class clazz;
|
Class clazz;
|
||||||
if( abbreviationMap.containsKey( className ) ) {
|
if (abbreviationMap.containsKey(className)) {
|
||||||
clazz = Class.forName( "[" + abbreviationMap.get( className ), initialize, classLoader ).getComponentType();
|
String clsName = "[" + abbreviationMap.get(className);
|
||||||
}
|
clazz = Class.forName(clsName, initialize, classLoader).getComponentType();
|
||||||
else {
|
} else {
|
||||||
clazz = Class.forName( toProperClassName( className ), initialize, classLoader );
|
clazz = Class.forName(toProperClassName(className), initialize, classLoader);
|
||||||
}
|
}
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the (initialized) class represented by <code>className</code> using the <code>classLoader</code>. This
|
* Returns the (initialized) class represented by <code>className</code>
|
||||||
* implementation supports names like "<code>java.lang.String[]</code>" as well as
|
* using the <code>classLoader</code>. This implementation supports names
|
||||||
|
* like "<code>java.lang.String[]</code>" as well as
|
||||||
* "<code>[Ljava.lang.String;</code>".
|
* "<code>[Ljava.lang.String;</code>".
|
||||||
*
|
*
|
||||||
* @param classLoader the class loader to use to load the class
|
* @param classLoader the class loader to use to load the class
|
||||||
* @param className the class name
|
* @param className the class name
|
||||||
* @return the class represented by <code>className</code> using the <code>classLoader</code>
|
* @return the class represented by <code>className</code> using the <code>classLoader</code>
|
||||||
* @throws ClassNotFoundException if the class is not found
|
* @throws ClassNotFoundException if the class is not found
|
||||||
*/
|
*/
|
||||||
public static Class getClass( ClassLoader classLoader, String className ) throws ClassNotFoundException {
|
public static Class getClass(ClassLoader classLoader, String className) throws ClassNotFoundException {
|
||||||
return getClass( classLoader, className, true );
|
return getClass(classLoader, className, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the (initialized )class represented by <code>className</code> using the current thread's context class
|
* Returns the (initialized )class represented by <code>className</code>
|
||||||
* loader. This implementation supports names like "<code>java.lang.String[]</code>" as well as
|
* using the current thread's context class loader. This implementation
|
||||||
* "<code>[Ljava.lang.String;</code>".
|
* supports names like "<code>java.lang.String[]</code>" as well as
|
||||||
*
|
|
||||||
* @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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>".
|
* "<code>[Ljava.lang.String;</code>".
|
||||||
*
|
*
|
||||||
* @param className the class name
|
* @param className the class name
|
||||||
* @param initialize whether the class must be initialized
|
|
||||||
* @return the class represented by <code>className</code> using the current thread's context class loader
|
* @return the class represented by <code>className</code> using the current thread's context class loader
|
||||||
* @throws ClassNotFoundException if the class is not found
|
* @throws ClassNotFoundException if the class is not found
|
||||||
*/
|
*/
|
||||||
public static Class getClass( String className, boolean initialize ) throws ClassNotFoundException {
|
public static Class getClass(String className) throws ClassNotFoundException {
|
||||||
return getClass( Thread.currentThread().getContextClassLoader() == null ? ClassUtils.class.getClassLoader() :
|
return getClass(className, true);
|
||||||
Thread.currentThread().getContextClassLoader(), className, initialize );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toProperClassName( String className ) {
|
/**
|
||||||
className = StringUtils.deleteWhitespace( className );
|
* Returns the class represented by <code>className</code> using the
|
||||||
if( className == null ) {
|
* current thread's context class loader. This implementation supports
|
||||||
throw new NullArgumentException( "className" );
|
* names like "<code>java.lang.String[]</code>" as well as
|
||||||
}
|
* "<code>[Ljava.lang.String;</code>".
|
||||||
else if( className.endsWith( "[]" ) ) {
|
*
|
||||||
final StringBuffer classNameBuffer = new StringBuffer();
|
* @param className the class name
|
||||||
while( className.endsWith( "[]" ) ) {
|
* @param initialize whether the class must be initialized
|
||||||
className = className.substring( 0, className.length() - 2 );
|
* @return the class represented by <code>className</code> using the current thread's context class loader
|
||||||
classNameBuffer.append( "[" );
|
* @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 );
|
String abbreviation = (String) abbreviationMap.get(className);
|
||||||
if( abbreviation != null ) {
|
if (abbreviation != null) {
|
||||||
classNameBuffer.append( abbreviation );
|
classNameBuffer.append(abbreviation);
|
||||||
}
|
} else {
|
||||||
else {
|
classNameBuffer.append("L").append(className).append(";");
|
||||||
classNameBuffer.append( "L" ).append( className ).append( ";" );
|
|
||||||
}
|
}
|
||||||
className = classNameBuffer.toString();
|
className = classNameBuffer.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
return className;
|
return className;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue