类 ClassTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.ClassTool
This tool is meant to simplify reflective lookup of information about
a Class and its Fields, Methods, and Constructors.
This is ideally aimed at those wishing to generate documentation, demo code, or
other content based on runtime reflection of a specified Class or Classes. It was not
designed with reflective execution of code in mind and thus provides no facilities
for code execution, nor direct access to the actual methods, constructors or fields
of the class being inspected.
Example tools.xml config:
<tools>
<toolbox scope="application">
<tool class="org.apache.velocity.tools.generic.ClassTool"
inspect="com.org.Foo"/>
</toolbox>
</tools>
If no Class to be inspected is specified, the default is java.lang.Object.
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Id: ClassTool.java 463298 2006-10-12 16:10:32Z henning $
- 作者:
- Nathan Bubna
-
嵌套类概要
嵌套类修饰符和类型类说明static classClassTool.CallableSub<T extends ClassTool.CallableSub>static classA simplified wrapping interface for inspecting features of aConstructorin an inspected Class.static classA simplified wrapping interface for inspecting features of aFieldin an inspected Class.static classA simplified wrapping interface for inspecting features of aMethodin an inspected Class.static classClassTool.Sub<T extends ClassTool.Sub> -
字段概要
字段修饰符和类型字段说明protected List<ClassTool.ConstructorSub>protected List<ClassTool.FieldSub>static final Stringprotected List<ClassTool.MethodSub>static final Stringprotected Class从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser values) Configure this toolReturns theAnnotations of the Class being inspected.Returns aListofClassTool.ConstructorSubs for each constructor declared constructor in the inspected class.Returns aListofClassTool.FieldSubs for each field declared field in the inspected class.Returns the fully-qualified name for the inspected Class.Returns aListofClassTool.MethodSubs for each method declared method in the inspected class.getName()Returns the simple name (i.e. full name with package name removed) of the inspected Class.Returns the name of the package to which the inspected Class belongs.booleanReturns the current showDeprecated setting.getSuper()Returns a new ClassTool instance that is inspecting the superclass of the Class being inspected by this instance.getType()Returns theClassbeing inspected by this instance.getTypes()Returns a new ClassTool instance that is inspecting the the specifiedClass.Returns a new ClassTool instance that is inspecting the Class of the specifiedObject.Returns a new ClassTool instance that is inspecting the Class with the specified name.booleanReturns true if the inspected Class is declared abstract.booleanReturns true if the inspected Class has been deprecated.protected static booleanisDeprecated(AnnotatedElement element) Check if an annotation deprecates its classbooleanisFinal()Returns true if the inspected Class is declared final.booleanReturns true if the inspected Class is an interface.booleanReturns true if the inspected Class is declared private.booleanReturns true if the inspected Class is declared protected.booleanisPublic()Returns true if the inspected Class is declared public.booleanisStatic()Returns true if the inspected Class is an inner class that has been declared static or is a standard outer class..booleanisStrict()Returns true if the inspected Class is declared strictfp (uses strict floating point math).protected voidSet the class to inspectbooleanReturns true if a call to newInstance() on the Class being inspected is successful; otherwise returns false.toString()从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
构造器详细资料
-
ClassTool
public ClassTool()Creates an instance with target type ofObject. -
ClassTool
Creates a new instance that inspects the specified type and otherwise shares the configuration values of the specified "parent" ClassTool instance.- 参数:
tool- parent class tooltype- class to inspect
-
-
方法详细资料
-
configure
Configure this tool- 覆盖:
configure在类中SafeConfig- 参数:
values- configuration values
-
setType
Set the class to inspect- 参数:
type- the class to inspect
-
isDeprecated
Check if an annotation deprecates its class- 参数:
element- annotation- 返回:
- deprecation status
-
getShowDeprecated
public boolean getShowDeprecated()Returns the current showDeprecated setting.- 返回:
- flag value
-
getType
Returns theClassbeing inspected by this instance.- 返回:
- inspected class
-
inspect
Returns a new ClassTool instance that is inspecting the Class with the specified name. If the specified Class cannot be found, then this will returnnull. All other configuration settings will be copied to the new instance.- 参数:
name- class name- 返回:
- new class tool
-
inspect
Returns a new ClassTool instance that is inspecting the Class of the specifiedObject. If the specified object is null, then this will returnnull. All other configuration settings will be copied to the new instance.- 参数:
obj- object instance to inspect- 返回:
- new class tool
-
getSuper
Returns a new ClassTool instance that is inspecting the superclass of the Class being inspected by this instance. If the current inspectee has no super class, then this will returnnull. All other configuration settings will be copied to the new instance.- 返回:
- parent class tool
-
inspect
Returns a new ClassTool instance that is inspecting the the specifiedClass. If the specified class is null, then this will returnnull. All other configuration settings will be copied to the new instance. IfSafeConfig.isSafeMode()istrueand the specified Class is not declaredpublic, then this will returnnull.- 参数:
type- class to inspect- 返回:
- new class tool
-
getPackage
Returns the name of the package to which the inspected Class belongs.- 返回:
- package name
-
getName
Returns the simple name (i.e. full name with package name removed) of the inspected Class.- 返回:
- inspected class simple name
-
getFullName
Returns the fully-qualified name for the inspected Class.- 返回:
- inspected class name
-
supportsNewInstance
public boolean supportsNewInstance()Returns true if a call to newInstance() on the Class being inspected is successful; otherwise returns false. Unlike calling newInstance() directly from a template, this will not throw an Exception if it fails, as all Exceptions are caught.- 返回:
- new instances supported or not
-
isDeprecated
public boolean isDeprecated()Returns true if the inspected Class has been deprecated.- 返回:
- deprecation status
-
isPublic
public boolean isPublic()Returns true if the inspected Class is declared public.- 返回:
- whether the inspected class is public
-
isProtected
public boolean isProtected()Returns true if the inspected Class is declared protected.- 返回:
- whether the inspected class is protected
-
isPrivate
public boolean isPrivate()Returns true if the inspected Class is declared private.- 返回:
- whether the inspected class is private
-
isStatic
public boolean isStatic()Returns true if the inspected Class is an inner class that has been declared static or is a standard outer class..- 返回:
- whether the inspected class is static
-
isFinal
public boolean isFinal()Returns true if the inspected Class is declared final.- 返回:
- whether the inspected class is final
-
isInterface
public boolean isInterface()Returns true if the inspected Class is an interface.- 返回:
- whether the inspected class is an interface
-
isStrict
public boolean isStrict()Returns true if the inspected Class is declared strictfp (uses strict floating point math).- 返回:
- whether the inspected class is strictfp
-
isAbstract
public boolean isAbstract()Returns true if the inspected Class is declared abstract.- 返回:
- whether the inspected class is abstract
-
getMethods
Returns aListofClassTool.MethodSubs for each method declared method in the inspected class. However, in safe mode (which *is* the default), this will only return the public methods. You must configure safe mode to be off to receive a list of all methods.- 返回:
- methods inspectors list
-
getConstructors
Returns aListofClassTool.ConstructorSubs for each constructor declared constructor in the inspected class. However, in safe mode (which *is* the default), this will only return the public constructors. You must configure safe mode to be off to receive a list of all constructors.- 返回:
- constructors inspectors list
-
getFields
Returns aListofClassTool.FieldSubs for each field declared field in the inspected class. However, in safe mode (which *is* the default), this will only return the public fields. You must configure safe mode to be off to receive a list of all fields.- 返回:
- fields inspectors list
-
getTypes
Returns aSetof allClasses that are part of the signatures (i.e. parameters or return types) of the inspected Class's methods, constructors and fields.- 返回:
- referenced classes set
-
getAnnotations
Returns theAnnotations of the Class being inspected.- 返回:
- annotation list
-
toString
-