| org.apache.tapestry.services.ClassTransformation
ClassTransformation | public interface ClassTransformation extends AnnotationProvider(Code) | | Contains class-specific information used when transforming an raw class into an executable class.
Much of this information is somewhat like ordinary reflection, but applies to a class that has
not yet been loaded.
Transformation is primarily about identifying annotations on fields and on methods and changing
the class, adding new interfaces, fields and methods, and deleting some existing fields.
A ClassTransformation contains all the state data specific to a particular class being
transformed. A number of workers will operate upon the ClassTransformation to effect
the desired changes before the true class is loaded into memory.
Instances of this class are not designed to be thread safe, access to an instance should be
restricted to a single thread. In fact, the design of this type is to allow stateless singletons
in multiple threads to work on thread-specific data (within the ClassTransformation). *
The majority of methods concern the declared members (field and methods) of a specific
class, rather than any fields or methods inherited from a base class.
|
Method Summary | |
String | addField(int modifiers, String type, String suggestedName) Defines a new declared field for the class. | void | addImplementedInterface(Class interfaceClass) Transforms the class to implement the indicated interface. | String | addInjectedField(Class type, String suggestedName, Object value) Defines a new protected instance variable whose initial value is provided
statically, via a constructor parameter. | void | addMethod(MethodSignature signature, String methodBody) Adds a new method to the transformed class. | void | claimField(String fieldName, Object tag) Claims a field so as to ensure that only a single annotation is applied to any single field. | void | extendConstructor(String statement) Adds a statement to the constructor. | void | extendMethod(MethodSignature methodSignature, String methodBody) Extends an existing method. | List<String> | findFields(FieldFilter filter) Finds all unclaimed fields matched by the provided filter. | List<String> | findFieldsOfType(String type) Generates a list of the names of declared instance fields that exactly match the specified
type. | List<String> | findFieldsWithAnnotation(Class<? extends Annotation> annotationClass) Generates a list of the names of declared instance fields that have the indicated annotation.
Non-private and static fields are ignored. | List<MethodSignature> | findMethods(MethodFilter filter) Finds all methods matched by the provided filter. | List<MethodSignature> | findMethodsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all methods defined in the class that are marked with the provided annotation. | List<String> | findUnclaimedFields() Finds any declared instance fields that have not been claimed (via
ClassTransformation.claimField(String,Object) ) and returns the names of those fields. | String | getClassName() Returns the fully qualified class name of the class being transformed. | T | getFieldAnnotation(String fieldName, Class<T> annotationClass) Finds an annotation on a declared instance field. | int | getFieldModifiers(String fieldName) Returns the modifiers for the named field. | String | getFieldType(String fieldName) Obtains the type of a declared instance field. | Log | getLog() Returns a log, based on the class name being transformed, to which warnings or errors
concerning the class being transformed may be logged. | T | getMethodAnnotation(MethodSignature method, Class<T> annotationClass) Finds an annotation on a declared method. | String | getMethodIdentifier(MethodSignature signature) Converts a signature to a string used to identify the method; this consists of the
MethodSignature.getMediumDescription appended with source file information and line
number information (when available). | String | getResourcesFieldName() Returns the name of a field that provides the
org.apache.tapestry.ComponentResources for the transformed component. | void | injectField(String fieldName, Object value) Converts the field into a read only field whose value is the provided value. | boolean | isField(String fieldName) Returns true if the indicated name is a private instance field. | void | makeReadOnly(String fieldName) Changes the field to be read only. | String | newMemberName(String suggested) Returns the name of a new member (field or method). | String | newMemberName(String prefix, String baseName) As with
ClassTransformation.newMemberName(String) , but the suggested name is constructed from the
prefix and base name. | void | removeField(String fieldName) Removes a field entirely; this is useful for fields that are replaced entirely by computed
values. | void | replaceReadAccess(String fieldName, String methodName) Replaces all read-references to the specified field with invocations of the specified method
name. | void | replaceWriteAccess(String fieldName, String methodName) Replaces all write accesses to the specified field with invocations of the specified method
name. | Class | toClass(String type) Converts a type name into a corresponding class (possibly, a transformed class). |
addField | String addField(int modifiers, String type, String suggestedName)(Code) | | Defines a new declared field for the class. The suggestedName may be modified to ensure
uniqueness.
Parameters: modifiers - modifiers for the field (typically, java.lang.reflect.Modifier.PRIVATE) Parameters: type - the type for the field, as a string Parameters: suggestedName - the desired name for the field, which may be modified (for uniqueness) whenreturned the (uniqued) name for the field |
addImplementedInterface | void addImplementedInterface(Class interfaceClass)(Code) | | Transforms the class to implement the indicated interface. If the class (or its super class)
does not already implement the interface, then the interface is added, and default
implementations of any methods of the interface are added.
TODO: Checking that the names of methods in the interface do not conflict with the names of
methods present in the (unmodified) class.
Parameters: interfaceClass - the interface to be implemented by the class throws: IllegalArgumentException - if the interfaceClass argument does not represent an interface |
addInjectedField | String addInjectedField(Class type, String suggestedName, Object value)(Code) | | Defines a new protected instance variable whose initial value is provided
statically, via a constructor parameter. The transformation caches the result, so calling
this method repeatedly with the same type and value will return the same field name. Caching
extends to the parent transformation, so that a value injected into a parent class will be
available (via the protected instance variable) to subclasses.
Parameters: type - the type of object to inject Parameters: suggestedName - the suggested name for the new field Parameters: value - to be injected. This value is retained. the actual name of the injected field |
addMethod | void addMethod(MethodSignature signature, String methodBody)(Code) | | Adds a new method to the transformed class. Replaces any existing method declared for the
class. When overriding a super-class method, you should use
ClassTransformation.extendMethod(MethodSignature,String) , or you should remember to invoke the super
class implemetation explicitly. Use this method to control when the super-class
implementation is invoked.
|
claimField | void claimField(String fieldName, Object tag)(Code) | | Claims a field so as to ensure that only a single annotation is applied to any single field.
When a transformation occurs (driven by a field annotation), the first thing that occurs is
to claim the field, on behalf of the annotation.
Parameters: fieldName - the name of the field that is being claimed Parameters: tag - a non-null object that represents why the field is being tagged (this is typicallya specific annotation on the field) throws: IllegalArgumentException - if the fieldName does not correspond to a declared instance field throws: IllegalStateException - if the field is already claimed for some other tag |
extendConstructor | void extendConstructor(String statement)(Code) | | Adds a statement to the constructor. The statement is added as is, though a newline is added.
Parameters: statement - the statement to add, which should end with a semicolon |
extendMethod | void extendMethod(MethodSignature methodSignature, String methodBody)(Code) | | Extends an existing method. The provided method body is inserted at the end of the existing
method (i.e.
javassist.CtBehavior.insertAfter(java.lang.String) ). To access or
change the return value, use the $_ pseudo variable.
The method may be declared in the class, or may be inherited from a super-class. For
inherited methods, a method is added that first invokes the super implementation. Use
ClassTransformation.addMethod(MethodSignature,String) when it is necessary to control when the
super-class method is invoked.
Parameters: signature - the signature of the method to extend Parameters: methodBody - the body of code throws: IllegalArgumentException - if the provided Javassist method body can not be compiled |
findFields | List<String> findFields(FieldFilter filter)(Code) | | Finds all unclaimed fields matched by the provided filter. Only considers unclaimed, private,
instance fields.
Parameters: filter - passed each field name and field type the names of all matched fields, in ascending order |
findFieldsWithAnnotation | List<String> findFieldsWithAnnotation(Class<? extends Annotation> annotationClass)(Code) | | Generates a list of the names of declared instance fields that have the indicated annotation.
Non-private and static fields are ignored. Only the names of private instance fields are
returned. Any
ClassTransformation.claimField(String,Object) claimed fields are excluded.
|
findMethods | List<MethodSignature> findMethods(MethodFilter filter)(Code) | | Finds all methods matched by the provided filter.
Parameters: filter - Passed each method signature, it may include or exclude each potential a list of matching method signatures (which may be empty) in ascending order |
findMethodsWithAnnotation | List<MethodSignature> findMethodsWithAnnotation(Class<? extends Annotation> annotationClass)(Code) | | Finds all methods defined in the class that are marked with the provided annotation.
Parameters: annotationClass - a list of method signature (which may be empty) in ascending order |
getClassName | String getClassName()(Code) | | Returns the fully qualified class name of the class being transformed.
|
getFieldAnnotation | T getFieldAnnotation(String fieldName, Class<T> annotationClass)(Code) | | Finds an annotation on a declared instance field.
< Parameters: T - >constrains parameter and return value to Annotation types Parameters: fieldName - the name of the field, which must exist Parameters: annotationClass - the type of annotation to access the annotation if present, or null otherwise throws: IllegalArgumentException - if the fieldName does not correspond to a declared field |
getFieldModifiers | int getFieldModifiers(String fieldName)(Code) | | Returns the modifiers for the named field.
|
getFieldType | String getFieldType(String fieldName)(Code) | | Obtains the type of a declared instance field.
Parameters: fieldName - the type of the field, as a string throws: IllegalArgumentException - if the fieldName does not correspond to a declared instance field |
getLog | Log getLog()(Code) | | Returns a log, based on the class name being transformed, to which warnings or errors
concerning the class being transformed may be logged.
|
getMethodAnnotation | T getMethodAnnotation(MethodSignature method, Class<T> annotationClass)(Code) | | Finds an annotation on a declared method.
< Parameters: T - >constrains parameter and return value to Annotation types Parameters: method - the method signature to search Parameters: annotationClass - the type of annotation to access the annotation if present, or null otherwise throws: IllegalArgumentException - if the method signature does not correspond to a declared method |
getMethodIdentifier | String getMethodIdentifier(MethodSignature signature)(Code) | | Converts a signature to a string used to identify the method; this consists of the
MethodSignature.getMediumDescription appended with source file information and line
number information (when available).
Parameters: signature - a string that identifies the class, method name, types of parameters, source file andsource line number |
getResourcesFieldName | String getResourcesFieldName()(Code) | | Returns the name of a field that provides the
org.apache.tapestry.ComponentResources for the transformed component. This will be a protected field, accessible to the class and
subclasses.
name of field |
injectField | void injectField(String fieldName, Object value)(Code) | | Converts the field into a read only field whose value is the provided value. This is used
when converting an existing field into a read-only injected value.
Parameters: fieldName - name of field to convert Parameters: value - the value provided by the field |
isField | boolean isField(String fieldName)(Code) | | Returns true if the indicated name is a private instance field.
Parameters: fieldName - true if field exists |
makeReadOnly | void makeReadOnly(String fieldName)(Code) | | Changes the field to be read only. Any existing code that changes the field will cause a
runtime exception.
Parameters: fieldName - name of field to so change |
newMemberName | String newMemberName(String suggested)(Code) | | Returns the name of a new member (field or method). Ensures that the resulting name does not
conflict with any existing member (declared by the underlying class, or inherited from a base
class).
Parameters: suggested - the suggested value for the member a unique name for the member |
newMemberName | String newMemberName(String prefix, String baseName)(Code) | | As with
ClassTransformation.newMemberName(String) , but the suggested name is constructed from the
prefix and base name. An underscore will seperate the prefix from the base name.
Parameters: prefix - for the generated name Parameters: baseName - an name, often of an existing field or method a unique name |
toClass | Class toClass(String type)(Code) | | Converts a type name into a corresponding class (possibly, a transformed class). Primitive
type names are returned as wrapper types.
|
|
|