org.test4j.tools.commons
类 ClazzHelper

java.lang.Object
  继承者 org.test4j.tools.commons.ClazzHelper

public class ClazzHelper
extends Object


字段摘要
static String VALID_PACK_REGULAR
          package名称有效字符表达式
 
构造方法摘要
ClazzHelper()
           
 
方法摘要
static boolean classFileExistsInClasspath(String className)
           
static
<T> T
createInstanceOfType(String className)
          创建className的实例
Creates an instance of the class with the given name.
static boolean doesImportSchemaExport()
          类路径中是否有 org.hibernate.tool.hbm2ddl.SchemaExport class
static String exactBeanName(Method method)
          从void setBeanName(Type instance)方法中解析出beanName
static void generateClazz(String clazzName, byte[] r)
           
static List<Field> getAllFields(Class clazz, Collection<String> filters, boolean includeStatic, boolean includeFinal, boolean includeTransient)
          返回可以class中定义的字段(包含父类定义的)
static byte[] getBytes(Class clazz)
          读取class的字节码内容byte[]
static
<T> Class<T>
getClassForType(Type type)
          Gets the class instance for the given type instance.
static
<T> Class<T>
getClazz(String className)
          Gets the class for the given name.
static
<T extends Enum<?>>
T
getEnumValue(Class<T> enumClass, String enumValueName)
          根据字符串获取枚举值
Gets the enum value that has the given name.
static Type getGenericType(Field field)
          获得泛型字段的参数类类型
Gets the T from a Class field declaration.
static String getPackageRegex(String regexPackage)
          将带有星号的package名称转换为正则表达式
static String getPackFromClassName(String clazzName)
           
static String getPathFromPath(Class clazz)
          根据类名获得package的路径
a.b.c.ImplClazz 返回 "a/b/c"
if clazz==null, 返回 ""
static String getPathFromPath(String clazzName)
          根据类名获得package的路径
a.b.c.ImplClazz 返回 a/b/c
static Object getProxiedObject(Object target)
          如果是spring代理对象,获得被代理的目标对象
static Class getUnProxyType(Class clazz)
          返回非代理类的类型
static boolean isAbstract(Class clazz)
          是否是抽象类且非primitive类型
static boolean isAssignable(Type fromType, Type toType)
          Checks whether the given fromType is assignable to the given toType, also taking into account possible auto-boxing.
static boolean isClassAvailable(String className)
          Utility method that verifies whether the class with the given fully qualified classname is available in the classpath.
static boolean isClassFile(String classFileName)
          是否是class文件
static boolean isInnerClass(String className)
          是否是内部类
static boolean isInterfaceOrAbstract(Class type)
          判断类型是否是接口或者抽象类
static
<T> T
newInstance(Class<T> claz)
          创建claz对象实例
不是通过 new Construction()形式
static
<T> T
newInstance(Class<T> claz, ConstructorArgsGenerator argGenerator)
           
static String replaceFileSeparators(String clazzPath)
          将class的全路径替换为带.的class名称
ex: convert /a/b.class to a.b
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

VALID_PACK_REGULAR

public static final String VALID_PACK_REGULAR
package名称有效字符表达式

另请参见:
常量字段值
构造方法详细信息

ClazzHelper

public ClazzHelper()
方法详细信息

isClassAvailable

public static boolean isClassAvailable(String className)
Utility method that verifies whether the class with the given fully qualified classname is available in the classpath.

参数:
className - The name of the class
返回:
True if the class with the given name is available

getClazz

public static <T> Class<T> getClazz(String className)
Gets the class for the given name. An Test4JException is thrown when the class could not be loaded.

参数:
className - The name of the class, not null
返回:
The class, not null

classFileExistsInClasspath

public static boolean classFileExistsInClasspath(String className)
参数:
className - The name of the class to check, not null
返回:
True if the classfile exists in the classpath

doesImportSchemaExport

public static final boolean doesImportSchemaExport()
类路径中是否有 org.hibernate.tool.hbm2ddl.SchemaExport class

返回:

getPackFromClassName

public static final String getPackFromClassName(String clazzName)

getPathFromPath

public static final String getPathFromPath(String clazzName)
根据类名获得package的路径
a.b.c.ImplClazz 返回 a/b/c

参数:
clazzName -
返回:

getPathFromPath

public static final String getPathFromPath(Class clazz)
根据类名获得package的路径
a.b.c.ImplClazz 返回 "a/b/c"
if clazz==null, 返回 ""

参数:
clazzName -
返回:

generateClazz

public static final void generateClazz(String clazzName,
                                       byte[] r)
                                throws IOException
抛出:
IOException

getPackageRegex

public static String getPackageRegex(String regexPackage)
将带有星号的package名称转换为正则表达式

参数:
regexPackage - 带有星号的package名称,比如 com.**.service.*Impl
返回:

isInterfaceOrAbstract

public static boolean isInterfaceOrAbstract(Class type)
判断类型是否是接口或者抽象类

参数:
type -
返回:

exactBeanName

public static String exactBeanName(Method method)
从void setBeanName(Type instance)方法中解析出beanName

参数:
method -
返回:

createInstanceOfType

public static <T> T createInstanceOfType(String className)
创建className的实例
Creates an instance of the class with the given name. The class's no argument constructor is used to create an instance.

参数:
className - The name of the class, not null
返回:
An instance of this class
抛出:
Test4JException - if the class could not be found or no instance could be created

isAssignable

public static boolean isAssignable(Type fromType,
                                   Type toType)
Checks whether the given fromType is assignable to the given toType, also taking into account possible auto-boxing.
Check if the right-hand side type may be assigned to the left-hand side type following the Java generics rules.

参数:
fromType - The from type, not null
toType - The to type, not null
返回:
True if assignable

getEnumValue

public static <T extends Enum<?>> T getEnumValue(Class<T> enumClass,
                                                 String enumValueName)
根据字符串获取枚举值
Gets the enum value that has the given name.

参数:
enumClass - The enum class, not null
enumValueName - The name of the enum value, not null
返回:
The actual enum value, not null
抛出:
Test4JException - if no value could be found with the given name

getGenericType

public static Type getGenericType(Field field)
获得泛型字段的参数类类型
Gets the T from a Class field declaration. An exception is raised if the field type is not generic or has more than 1 generic type

参数:
field - The field to get the type from, not null
返回:
The declared generic type

getClassForType

public static <T> Class<T> getClassForType(Type type)
Gets the class instance for the given type instance.

参数:
type - The type to get a class instance for, not null
返回:
The class instance, not null

getBytes

public static byte[] getBytes(Class clazz)
读取class的字节码内容byte[]

参数:
clazz -
返回:

newInstance

public static <T> T newInstance(Class<T> claz)
创建claz对象实例
不是通过 new Construction()形式

类型参数:
T -
参数:
claz -
返回:

newInstance

public static <T> T newInstance(Class<T> claz,
                                ConstructorArgsGenerator argGenerator)

getAllFields

public static final List<Field> getAllFields(Class clazz,
                                             Collection<String> filters,
                                             boolean includeStatic,
                                             boolean includeFinal,
                                             boolean includeTransient)
返回可以class中定义的字段(包含父类定义的)

参数:
clazz -
filters - 需要过滤掉的字段
includeStatic - 是否包含static修饰的字段
includeFinal - 是否包含final修饰的字段
includeTransient - 是否包含transient修饰的字段
返回:

getUnProxyType

public static Class getUnProxyType(Class clazz)
返回非代理类的类型

参数:
type -
返回:

getProxiedObject

public static Object getProxiedObject(Object target)
如果是spring代理对象,获得被代理的目标对象

参数:
target -
返回:

isClassFile

public static boolean isClassFile(String classFileName)
是否是class文件

参数:
classFileName -
返回:

isInnerClass

public static boolean isInnerClass(String className)
是否是内部类

参数:
className -
返回:

replaceFileSeparators

public static String replaceFileSeparators(String clazzPath)
将class的全路径替换为带.的class名称
ex: convert /a/b.class to a.b

参数:
clazzPath -
返回:

isAbstract

public static boolean isAbstract(Class clazz)
是否是抽象类且非primitive类型

参数:
clazz -
返回:


Copyright © 2013. All rights reserved.