|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.tapestry5.internal.services.InternalClassTransformationImpl
public final class InternalClassTransformationImpl
Implementation of the InternalClassTransformation interface.
| Field Summary | |
|---|---|
static MethodSignature |
FIELD_ACCESS_READ_SIGNATURE
|
static MethodSignature |
FIELD_ACCESS_WRITE_SIGNATURE
|
static MethodSignature |
INVOKE_SIGNATURE
|
| Constructor Summary | |
|---|---|
InternalClassTransformationImpl(ClassFactory classFactory,
javassist.CtClass ctClass,
ComponentClassCache componentClassCache,
MutableComponentModel componentModel,
CtClassSource classSource,
boolean developmentMode)
This is a constructor for a base class. |
|
| Method Summary | ||
|---|---|---|
void |
addCatch(TransformMethodSignature methodSignature,
String exceptionType,
String body)
Adds a catch block to the method. |
|
void |
addComponentEventHandler(String eventType,
int minContextValues,
String methodDescription,
ComponentEventHandler handler)
Adds advice to the Component.dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) 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. |
|
|
addIndirectInjectedField(Class<T> type,
String suggestedName,
ComponentValueProvider<T> provider)
Like ClassTransformation.addInjectedField(Class, String, Object), but instead of specifying the value,
a provider for the value is specified. |
|
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. |
|
TransformMethod |
addNewMethod(TransformMethodSignature signature,
String methodBody)
Adds a new method to the transformed class, possibly replacing an existing method or overriding a base-class method. |
|
TransformMethod |
addNewTransformedMethod(TransformMethodSignature signature,
String methodBody)
|
|
void |
addTransformedMethod(TransformMethodSignature signature,
String methodBody)
As with ClassTransformation.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 |
copyMethod(TransformMethodSignature sourceMethod,
int modifiers,
String newMethodName)
Creates a new method by copying the body of an existing method. |
|
InternalClassTransformation |
createChildTransformation(javassist.CtClass childClass,
MutableComponentModel childModel)
|
|
TransformField |
createField(int modifiers,
String type,
String suggestedName)
Defines a new declared field for the class. |
|
Instantiator |
createInstantiator()
Called (after InternalClassTransformation.finish()) to construct an instantiator for the component. |
|
void |
extendConstructor(String statement)
Adds a statement to the constructor. |
|
void |
extendExistingMethod(TransformMethodSignature methodSignature,
String methodBody)
Like ClassTransformation.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 ClassTransformation.claimField(String, Object))
and have not been added , and returns the names of those fields. |
|
String |
finish()
Invoked after all ComponentClassTransformWorkers have had their chance to work over the class. |
|
|
getAnnotation(Class<T> annotationClass)
Searches for the specified annotation, returning the matching annotation instance. |
|
List<Annotation> |
getClassAnnotations()
|
|
String |
getClassName()
Returns the fully qualified class name of the class being transformed. |
|
List<Object> |
getConstructorArgs()
Returns a copy of the list of constructor arguments for this class. |
|
TransformField |
getField(String fieldName)
Locates a declared field by its field name. |
|
|
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. |
|
IdAllocator |
getIdAllocator()
Returns a copy of the transformation's IdAllocator. |
|
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 signature,
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). |
|
TransformMethod |
getOrCreateMethod(TransformMethodSignature signature)
Locates and returns the method if declared in this class; If not, the method is added to the class. |
|
InternalClassTransformation |
getParentTransformation()
Returns the parent transformation, or null for a root class. |
|
String |
getResourcesFieldName()
Returns the name of a field that provides the ComponentResources for the transformed
component. |
|
void |
injectField(String fieldName,
Object value)
Converts an existing field into a read only field whose value is the provided value. |
|
boolean |
isDeclaredMethod(TransformMethodSignature signature)
Determines if the class being transformed includes a declared (not inherited) method with the provided signature. |
|
boolean |
isField(String fieldName)
Returns true if the indicated name is a private instance field. |
|
boolean |
isMethod(TransformMethodSignature signature)
Returns true if the provided signature is a method implemented by the transformed class. |
|
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 sub-class of another transformed class. |
|
void |
makeReadOnly(String fieldName)
Changes the field to be read only. |
|
List<TransformField> |
matchFields(Predicate<TransformField> predicate)
Finds all unclaimed fields matched by the provided predicate. |
|
List<TransformField> |
matchFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
Returns a sorted list of declared instance fields with the indicated annotation. |
|
List<TransformMethod> |
matchMethods(Predicate<TransformMethod> predicate)
Finds all methods matched by the provided predicate. |
|
List<TransformMethod> |
matchMethodsWithAnnotation(Class<? extends Annotation> annotationType)
Finds all methods matched by the provided predicate. |
|
List<TransformField> |
matchUnclaimedFields()
Matches all fields that are not claimed. |
|
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 |
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. |
|
String |
searchForPreviousInjection(InjectionKey key)
Searchs for an existing injection of an object, returning the name of the protected field into which the value was injected. |
|
Class |
toClass(String type)
Converts a type name into a corresponding class (possibly, a transformed class). |
|
String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final MethodSignature INVOKE_SIGNATURE
public static final MethodSignature FIELD_ACCESS_READ_SIGNATURE
public static final MethodSignature FIELD_ACCESS_WRITE_SIGNATURE
| Constructor Detail |
|---|
public InternalClassTransformationImpl(ClassFactory classFactory,
javassist.CtClass ctClass,
ComponentClassCache componentClassCache,
MutableComponentModel componentModel,
CtClassSource classSource,
boolean developmentMode)
| Method Detail |
|---|
public InternalClassTransformation createChildTransformation(javassist.CtClass childClass,
MutableComponentModel childModel)
createChildTransformation in interface InternalClassTransformationpublic String getResourcesFieldName()
ClassTransformationComponentResources for the transformed
component. This will be a protected field, accessible to the class and subclasses.
getResourcesFieldName in interface ClassTransformation
public <T extends Annotation> T getFieldAnnotation(String fieldName,
Class<T> annotationClass)
ClassTransformation
getFieldAnnotation in interface ClassTransformationT - constrains parameter and return value to Annotation typesfieldName - the name of the field, which must existannotationClass - the type of annotation to access
public <T extends Annotation> T getMethodAnnotation(TransformMethodSignature signature,
Class<T> annotationClass)
ClassTransformation
getMethodAnnotation in interface ClassTransformationT - constrains parameter and return value to Annotation typessignature - the method signature to searchannotationClass - the type of annotation to access
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
AnnotationProvider
getAnnotation in interface AnnotationProviderannotationClass - used to select the annotation to return«
public TransformField getField(String fieldName)
ClassTransformation
getField in interface ClassTransformationpublic String newMemberName(String suggested)
ClassTransformation
newMemberName in interface ClassTransformationsuggested - the suggested value for the member
public String newMemberName(String prefix,
String baseName)
ClassTransformationClassTransformation.newMemberName(String), but the suggested name is constructed from the prefix
and base name. An
underscore will separate the prefix from the base name.
newMemberName in interface ClassTransformationprefix - for the generated namebaseName - a name, often of an existing field or method
public void addImplementedInterface(Class interfaceClass)
ClassTransformation
addImplementedInterface in interface ClassTransformationinterfaceClass - the interface to be implemented by the class
public void claimField(String fieldName,
Object tag)
ClassTransformation
claimField in interface ClassTransformationfieldName - 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)
public void addMethod(TransformMethodSignature signature,
String methodBody)
ClassTransformationClassTransformation.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.
addMethod in interface ClassTransformation
public TransformMethod addNewMethod(TransformMethodSignature signature,
String methodBody)
InternalClassTransformation
addNewMethod in interface InternalClassTransformation
public TransformMethod addNewTransformedMethod(TransformMethodSignature signature,
String methodBody)
public void addTransformedMethod(TransformMethodSignature signature,
String methodBody)
ClassTransformationClassTransformation.addMethod(TransformMethodSignature, String), but field references inside the
method will be transformed, and the method must not already exist.
addTransformedMethod in interface ClassTransformation
public void extendMethod(TransformMethodSignature methodSignature,
String methodBody)
ClassTransformationCtBehavior.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
body is added that first invokes the super implementation. Use
ClassTransformation.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
ClassTransformation.removeField(String) removed}, ClassTransformation.replaceReadAccess(String, String) read replaced}, or
write replaced fields. Generally that's what you want!
extendMethod in interface ClassTransformationmethodSignature - the signature of the method to extendmethodBody - the body of code
public void extendExistingMethod(TransformMethodSignature methodSignature,
String methodBody)
ClassTransformationClassTransformation.extendMethod(TransformMethodSignature, String), but the extension does not mark
the method as new,
and field changes will be processed. Note: at some point, this is not longer true; extend and
extendMethod work identically.
extendExistingMethod in interface ClassTransformationmethodSignature - signature of the method to extendmethodBody - the body of codeClassTransformation.prefixMethod(TransformMethodSignature, String)
public void copyMethod(TransformMethodSignature sourceMethod,
int modifiers,
String newMethodName)
InternalClassTransformation
copyMethod in interface InternalClassTransformationsourceMethod - method to be copiedmodifiers - modifiers for the new methodnewMethodName - name of new method to create
public void addCatch(TransformMethodSignature methodSignature,
String exceptionType,
String body)
ClassTransformation
addCatch in interface ClassTransformationmethodSignature - method to be extended.exceptionType - fully qualified class name of exceptionbody - code to execute
public void prefixMethod(TransformMethodSignature methodSignature,
String methodBody)
ClassTransformationCtBehavior.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 ClassTransformation.addMethod(TransformMethodSignature, String)
when it is necessary to control when the super-class method is invoked.
Like ClassTransformation.extendExistingMethod(TransformMethodSignature, String), this method is generally used to "wrap" an
existing method adding additional functionality such as caching or transaction support.
prefixMethod in interface ClassTransformationpublic TransformMethod getOrCreateMethod(TransformMethodSignature signature)
ClassTransformation
getOrCreateMethod in interface ClassTransformationsignature - identifies the method to locate, override or createpublic List<String> findFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
ClassTransformation
findFieldsWithAnnotation in interface ClassTransformationpublic List<String> findFields(FieldFilter filter)
ClassTransformation
findFields in interface ClassTransformationfilter - passed each field name and field type
public List<TransformField> matchFields(Predicate<TransformField> predicate)
ClassTransformation
matchFields in interface ClassTransformationpredicate - used for matching
public List<TransformField> matchFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
ClassTransformation
matchFieldsWithAnnotation in interface ClassTransformationpublic List<TransformMethodSignature> findMethodsWithAnnotation(Class<? extends Annotation> annotationClass)
ClassTransformation
findMethodsWithAnnotation in interface ClassTransformationClassTransformation.findMethods(MethodFilter)public List<TransformMethodSignature> findMethods(MethodFilter filter)
ClassTransformation
findMethods in interface ClassTransformationfilter - Passed each method signature, it may include or exclude each potential
public List<TransformMethod> matchMethods(Predicate<TransformMethod> predicate)
ClassTransformation
matchMethods in interface ClassTransformationpredicate - Used to filter the list
public List<TransformMethod> matchMethodsWithAnnotation(Class<? extends Annotation> annotationType)
ClassTransformation
matchMethodsWithAnnotation in interface ClassTransformationannotationType - Used to filter the list
public List<String> findUnclaimedFields()
ClassTransformationClassTransformation.claimField(String, Object))
and have not been added , and returns the names of those fields. May return an empty array.
findUnclaimedFields in interface ClassTransformationpublic List<TransformField> matchUnclaimedFields()
ClassTransformation
matchUnclaimedFields in interface ClassTransformationpublic String getFieldType(String fieldName)
ClassTransformation
getFieldType in interface ClassTransformationpublic boolean isField(String fieldName)
ClassTransformation
isField in interface ClassTransformationpublic int getFieldModifiers(String fieldName)
ClassTransformation
getFieldModifiers in interface ClassTransformation
public String addField(int modifiers,
String type,
String suggestedName)
ClassTransformation
addField in interface ClassTransformationmodifiers - 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
public TransformField createField(int modifiers,
String type,
String suggestedName)
ClassTransformation
createField in interface ClassTransformationmodifiers - 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
public String addInjectedField(Class type,
String suggestedName,
Object value)
ClassTransformation
addInjectedField in interface ClassTransformationtype - the type of object to injectsuggestedName - the suggested name for the new fieldvalue - to be injected. This value is retained.
public <T> TransformField addIndirectInjectedField(Class<T> type,
String suggestedName,
ComponentValueProvider<T> provider)
ClassTransformationClassTransformation.addInjectedField(Class, String, Object), but instead of specifying the value,
a provider for the value is specified. In the generated class' constructor, the provider
will be passed the ComponentResources and will return the final value; thus
each component instance will receive a matching unique instance via the provider.
addIndirectInjectedField in interface ClassTransformationtype - type of value to injectsuggestedName - suggested name for the new fieldprovider - injected into the component to provide the value
public String searchForPreviousInjection(InjectionKey key)
InternalClassTransformation
searchForPreviousInjection in interface InternalClassTransformation
public void advise(TransformMethodSignature methodSignature,
ComponentMethodAdvice advice)
ClassTransformation
advise in interface ClassTransformationpublic boolean isMethodOverride(TransformMethodSignature methodSignature)
ClassTransformation
isMethodOverride in interface ClassTransformationmethodSignature - signature of method to check
public InternalClassTransformation getParentTransformation()
InternalClassTransformation
getParentTransformation in interface InternalClassTransformationpublic boolean isMethod(TransformMethodSignature signature)
InternalClassTransformation
isMethod in interface InternalClassTransformation
public void injectField(String fieldName,
Object value)
ClassTransformation
injectField in interface ClassTransformationfieldName - name of field to convertvalue - the value provided by the fieldpublic String finish()
InternalClassTransformationComponentClassTransformWorkers have had their chance to work over the class. This
performs any final operations for the class transformation, which includes coming up with the final constructor
method for the class.
finish in interface InternalClassTransformationpublic Instantiator createInstantiator()
InternalClassTransformationInternalClassTransformation.finish()) to construct an instantiator for the component.
createInstantiator in interface InternalClassTransformationpublic IdAllocator getIdAllocator()
InternalClassTransformation
getIdAllocator in interface InternalClassTransformationpublic List<Object> getConstructorArgs()
InternalClassTransformation
getConstructorArgs in interface InternalClassTransformationpublic List<Annotation> getClassAnnotations()
public String toString()
toString in class Objectpublic void makeReadOnly(String fieldName)
ClassTransformation
makeReadOnly in interface ClassTransformationfieldName - name of field to so changeReadOnlyFieldValueConduitpublic void removeField(String fieldName)
ClassTransformation
removeField in interface ClassTransformationfieldName - the name of the field to removeClassTransformation.replaceReadAccess(String, String),
ClassTransformation.replaceWriteAccess(String, String)
public void replaceReadAccess(String fieldName,
String methodName)
ClassTransformationClassTransformation.addMethod(TransformMethodSignature, String) or
ClassTransformation.extendMethod(TransformMethodSignature, String).
replaceReadAccess in interface ClassTransformation
public void replaceWriteAccess(String fieldName,
String methodName)
ClassTransformationClassTransformation.addMethod(TransformMethodSignature, String) or
ClassTransformation.extendMethod(TransformMethodSignature, String).
replaceWriteAccess in interface ClassTransformationpublic Class toClass(String type)
ClassTransformation
toClass in interface ClassTransformationpublic String getClassName()
ClassTransformation
getClassName in interface ClassTransformationpublic org.slf4j.Logger getLogger()
ClassTransformation
getLogger in interface ClassTransformationpublic void extendConstructor(String statement)
ClassTransformation
extendConstructor in interface ClassTransformationstatement - the statement to add, which should end with a semicolonComponentValueProviderpublic String getMethodIdentifier(TransformMethodSignature signature)
ClassTransformationTransformMethodSignature.getMediumDescription() appended with source file information
and line number
information (when available).
getMethodIdentifier in interface ClassTransformationpublic boolean isRootTransformation()
ClassTransformation
isRootTransformation in interface ClassTransformationpublic boolean isDeclaredMethod(TransformMethodSignature signature)
ClassTransformation
isDeclaredMethod in interface ClassTransformationsignature - identifies method to search for
public void addComponentEventHandler(String eventType,
int minContextValues,
String methodDescription,
ComponentEventHandler handler)
ClassTransformationComponent.dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) method.
If the handler is invoked,
the return value of the method will be overriden to true. Updates
the model to
indicate that there is a handler for the named event. Existing handlers, or super-class handlers,
are invoked first.
addComponentEventHandler in interface ClassTransformationeventType - name of event to be handledminContextValues - minimum number of event context values required to invoke the methodmethodDescription - Text description of what the handler does (used with Event.setMethodDescription(String))handler - the handler to invoke
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||