|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface ClassTransformation
Contains class-specific information used when transforming a raw component class into an executable component class.
An executable class is one that has been transformed to work within Tapestry. This includes adding interfaces
(Component) but also transforming access to fields, based on annotations and
naming conventions. Most of the changes are provided by different implementations of ComponentClassTransformWorker.
TapestryModule.contributeComponentClassTransformWorker(org.apache.tapestry5.ioc.OrderedConfiguration,
org.apache.tapestry5.ioc.ObjectLocator, InjectionProvider, ComponentClassResolver)| Method Summary | ||
|---|---|---|
void |
addCatch(TransformMethodSignature methodSignature,
String exceptionType,
String body)
Adds a catch block to the method. |
|
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(TransformMethodSignature signature,
String methodBody)
Adds a new method to the transformed class. |
|
void |
addTransformedMethod(TransformMethodSignature methodSignature,
String methodBody)
As with addMethod(TransformMethodSignature, String), but field references inside the method
will be transformed, and the method must not already exist. |
|
void |
advise(TransformMethodSignature methodSignature,
ComponentMethodAdvice advice)
Adds method advice for the indicated method. |
|
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 |
extendExistingMethod(TransformMethodSignature methodSignature,
String methodBody)
Like extendMethod(TransformMethodSignature, String), but the extension does not mark the method as new,
and field changes will be processed. |
|
void |
extendMethod(TransformMethodSignature methodSignature,
String methodBody)
Extends an existing method. |
|
List<String> |
findFields(FieldFilter filter)
Finds all unclaimed fields matched by the provided filter. |
|
List<String> |
findFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
Generates a list of the names of declared instance fields that have the indicated annotation. |
|
List<TransformMethodSignature> |
findMethods(MethodFilter filter)
Finds all methods matched by the provided filter. |
|
List<TransformMethodSignature> |
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 claimField(String, Object))
and returns the names of those fields. |
|
String |
getClassName()
Returns the fully qualified class name of the class being transformed. |
|
|
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. |
|
org.slf4j.Logger |
getLogger()
Returns a logger, based on the class name being transformed, to which warnings or errors concerning the class being transformed may be logged. |
|
|
getMethodAnnotation(TransformMethodSignature method,
Class<T> annotationClass)
Finds an annotation on a declared method. |
|
String |
getMethodIdentifier(TransformMethodSignature signature)
Converts a signature to a string used to identify the method; this consists of the TransformMethodSignature.getMediumDescription() appended with source file information and line number
information (when available). |
|
String |
getResourcesFieldName()
Returns the name of a field that provides the 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. |
|
boolean |
isMethodOverride(TransformMethodSignature methodSignature)
Returns true if the method is an override of a method from the parent class. |
|
boolean |
isRootTransformation()
Returns true if this transformation represents a root class (one that extends directly from Object), or false if this transformation is an extension of another transformed class. |
|
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 newMemberName(String), but the suggested name is constructed from the prefix and base name. |
|
void |
prefixMethod(TransformMethodSignature methodSignature,
String methodBody)
Inserts code at the beginning of a method body (i.e. |
|
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). |
|
| Methods inherited from interface org.apache.tapestry5.ioc.AnnotationProvider |
|---|
getAnnotation |
| Method Detail |
|---|
String getClassName()
String newMemberName(String suggested)
suggested - the suggested value for the member
String newMemberName(String prefix,
String baseName)
newMemberName(String), but the suggested name is constructed from the prefix and base name. An
underscore will seperate the prefix from the base name.
prefix - for the generated namebaseName - an name, often of an existing field or method
List<String> findFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
List<TransformMethodSignature> findMethodsWithAnnotation(Class<? extends Annotation> annotationClass)
annotationClass -
findMethods(MethodFilter)List<TransformMethodSignature> findMethods(MethodFilter filter)
filter - Passed each method signature, it may include or exclude each potential
List<String> findFields(FieldFilter filter)
filter - passed each field name and field type
<T extends Annotation> T getFieldAnnotation(String fieldName,
Class<T> annotationClass)
T - constrains parameter and return value to Annotation typesfieldName - the name of the field, which must existannotationClass - the type of annotation to access
IllegalArgumentException - if the fieldName does not correspond to a declared field
<T extends Annotation> T getMethodAnnotation(TransformMethodSignature method,
Class<T> annotationClass)
T - constrains parameter and return value to Annotation typesmethod - the method signature to searchannotationClass - the type of annotation to access
IllegalArgumentException - if the method signature does not correspond to a declared method
void claimField(String fieldName,
Object tag)
fieldName - the name of the field that is being claimedtag - a non-null object that represents why the field is being tagged (this is typically a specific
annotation on the field)
IllegalArgumentException - if the fieldName does not correspond to a declared instance field
IllegalStateException - if the field is already claimed for some other tagvoid makeReadOnly(String fieldName)
fieldName - name of field to so changeList<String> findUnclaimedFields()
claimField(String, Object))
and returns the names of those fields. May return an empty array.
String getFieldType(String fieldName)
fieldName -
IllegalArgumentException - if the fieldName does not correspond to a declared instance fieldboolean isField(String fieldName)
fieldName -
String addField(int modifiers,
String type,
String suggestedName)
modifiers - modifiers for the field (typically, Modifier.PRIVATE)type - the type for the field, as a stringsuggestedName - the desired name for the field, which may be modified (for uniqueness) when returned
String addInjectedField(Class type,
String suggestedName,
Object value)
type - the type of object to injectsuggestedName - the suggested name for the new fieldvalue - to be injected. This value is retained.
void injectField(String fieldName,
Object value)
fieldName - name of field to convertvalue - the value provided by the fieldvoid addImplementedInterface(Class interfaceClass)
interfaceClass - the interface to be implemented by the class
IllegalArgumentException - if the interfaceClass argument does not represent an interface
void extendMethod(TransformMethodSignature methodSignature,
String methodBody)
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 addMethod(TransformMethodSignature, String)
when it is necessary to control when the super-class method is invoked.
The extended method is considered new. New methods are not scanned for removeField(String) removed}, replaceReadAccess(String, String) read replaced}, or write replaced fields. Generally that's what you want!
methodSignature - the signature of the method to extendmethodBody - the body of code
MethodCompileException - if the provided Javassist method body can not be compiledextendExistingMethod(TransformMethodSignature, String)
void extendExistingMethod(TransformMethodSignature methodSignature,
String methodBody)
extendMethod(TransformMethodSignature, String), but the extension does not mark the method as new,
and field changes will be processed.
methodSignature - signature of the method to extendmethodBody - the body of code
MethodCompileException - if the provided method body can not be compiledprefixMethod(TransformMethodSignature, String)
void prefixMethod(TransformMethodSignature methodSignature,
String methodBody)
CtBehavior.insertBefore(String).
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 addMethod(TransformMethodSignature, String)
when it is necessary to control when the super-class method is invoked.
Like extendExistingMethod(TransformMethodSignature, String), this method is generally used to "wrap" an
existing method adding additional functionality such as caching or transaction support.
methodSignature - methodBody -
MethodCompileException - if the provided method body can not be compiledString getResourcesFieldName()
ComponentResources for the transformed
component. This will be a protected field, accessible to the class and subclasses.
void addMethod(TransformMethodSignature signature,
String methodBody)
extendMethod(TransformMethodSignature, String), or you should
remember to invoke the super class implemetation explicitly. Use this method to control when the super-class
implementation is invoked.
void addTransformedMethod(TransformMethodSignature methodSignature,
String methodBody)
addMethod(TransformMethodSignature, String), but field references inside the method
will be transformed, and the method must not already exist.
void extendConstructor(String statement)
statement - the statement to add, which should end with a semicolon
void replaceReadAccess(String fieldName,
String methodName)
addMethod(TransformMethodSignature, String) or extendMethod(TransformMethodSignature, String).
void replaceWriteAccess(String fieldName,
String methodName)
addMethod(TransformMethodSignature, String) or extendMethod(TransformMethodSignature, String).
void removeField(String fieldName)
fieldName - the name of the field to removereplaceReadAccess(String, String),
replaceWriteAccess(String, String)Class toClass(String type)
org.slf4j.Logger getLogger()
int getFieldModifiers(String fieldName)
String getMethodIdentifier(TransformMethodSignature signature)
TransformMethodSignature.getMediumDescription() appended with source file information and line number
information (when available).
signature -
boolean isRootTransformation()
void addCatch(TransformMethodSignature methodSignature,
String exceptionType,
String body)
methodSignature - method to be extended.exceptionType - fully qualified class name of exceptionbody - code to execute
void advise(TransformMethodSignature methodSignature,
ComponentMethodAdvice advice)
boolean isMethodOverride(TransformMethodSignature methodSignature)
methodSignature - signature of method to check
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||