org.objectweb.jac.core.rtti
Class MethodItem

java.lang.Object
  |
  +--org.objectweb.jac.core.rtti.MetaItem
        |
        +--org.objectweb.jac.core.rtti.MetaItemDelegate
              |
              +--org.objectweb.jac.core.rtti.MemberItem
                    |
                    +--org.objectweb.jac.core.rtti.AbstractMethodItem
                          |
                          +--org.objectweb.jac.core.rtti.MethodItem
Direct Known Subclasses:
MixinMethodItem

public class MethodItem
extends AbstractMethodItem

This class defines a meta item that corresponds to the java.lang.reflect.Method meta element.

In addition to the java.lang.reflect classical features, this RTTI method element is able to tell if a method is a setter, a getter, or more generally speaking, a state modifier for a given field of the object it belongs to. And, if this field is a collection (an array, a list or a map), then this meta element is able to tell if the method it represents adds or removes elements to or from this collection.

It also provides to introspection features for references on Jac objects.

For the moment, default meta informations are setted by the ClassRepository class using some naming conventions. In a close future, these informations will be deduced from the class bytecodes analysis at load-time.

Author:
Renaud Pawlak, Laurent Martelli
See Also:
Method, AbstractMethodItem.getWrittenFields(), AbstractMethodItem.getAccessedFields(), getAddedCollections(), getRemovedCollections(), AbstractMethodItem.isModifier(), hasAccessedReferences()

Field Summary
static MethodItem[] emptyArray
           
 
Fields inherited from class org.objectweb.jac.core.rtti.MemberItem
role, roleClassType, roleName, roleType
 
Fields inherited from class org.objectweb.jac.core.rtti.MetaItemDelegate
delegate, parent
 
Fields inherited from class org.objectweb.jac.core.rtti.MetaItem
attrACs
 
Constructor Summary
MethodItem(Method delegate, ClassItem parent)
          Default contructor to create a new method item object.
 
Method Summary
 void addAccessedField(FieldItem accessedField)
          Adds a new accessed field for this method.
 void addAddedCollection(CollectionItem addedCollection)
          Adds a new added collection for this method.
 void addRemovedCollection(CollectionItem removedCollection)
          Adds a new removed collection for this method.
 Method getActualMethod()
          Gets the method represented by this method item.
 CollectionItem[] getAddedCollections()
          Get the value of the collections that are added by this method.
 int getCollectionIndexArgument()
          Returns the number of the argument which is the index of a modified collection if any, -1 otherwise.
 int getCollectionItemArgument()
          Returns the number of the argument which is the item that will be added to a collection if any, -1 otherwise.
 String getName()
          This method gets the name of the meta item by delegating to the actual java.lang.reflect meta item.
 Method getOrgMethod()
           
 Class[] getParameterTypes()
          Gets the parameter types of this abstract method item.
 CollectionItem getRemovedCollection()
           
 CollectionItem[] getRemovedCollections()
          Gets the value of the collections that are removed by this method.
 FieldItem getReturnedField()
          Returns the field item corresponding to the field value returned by this method, if any.
 FieldItem getSetField()
          Returns the field set by this method, if any.
 Class getType()
          This method gets the type of the meta item by delegating to the actual java.lang.reflect meta item.
 boolean hasAccessedReferences()
          Tells if this method accesses any references of the class it belongs to.
 boolean hasAddedCollections()
          Returns true if the method has at least one added collection
 boolean hasRemovedCollections()
          Returns true if the method has at least one removed collection
 Object invoke(Object object, Object[] parameters)
          Invokes this method on the given object and with the given parameters values.
 Object invokeStatic(Object[] parameters)
          Invokes this static method with the given parameters values.
 Object invokeWithInit(Object object, Object[] parameters)
          Invokes a method with uninitialized parameters.
 boolean isAccessor()
           
 boolean isAdder()
          Tells wether the method is an adder of a collection
 boolean isCollectionAccessor()
           
 boolean isCollectionGetter()
           
 boolean isCollectionSetter()
           
 boolean isFieldGetter()
           
 boolean isFieldSetter()
           
 boolean isGetter()
          Tells wether the method returns the value of a field
 boolean isJacMethod()
          Tells wether the method was introduced by JAC
 boolean isReferenceAccessor()
           
 boolean isReferenceGetter()
           
 boolean isReferenceSetter()
           
 boolean isRemover()
          Tells wether the method is a remover of a collection
 boolean isSetter()
          Tells wether the method is the setter of a field
 boolean isWriter()
           
 void removeAddedCollection(CollectionItem collection)
          Removes an existing added collection for this method.
 void removeRemovedCollection(CollectionItem collection)
          Removes an existing removed collection for this method.
 void setAddedCollections(CollectionItem[] addedCollections)
          Sets the value of the collections that are added by this method.
 void setCollectionIndexArgument(int collectionIndexArgument)
          Sets collectionIndexArgument
 void setCollectionItemArgument(int collectionItemArgument)
          Sets collectionItemArgument
 void setRemovedCollections(CollectionItem[] removedCollections)
          Sets the value of the collections that are removed by this method.
 void setReturnedField(FieldItem returnedField)
          Sets the field returned by the method.
 void setSetField(FieldItem setField)
          Sets the field set by the method.
static Method[] toMethods(MethodItem[] methodItems)
          Transforms a method items array into a methods array containing the java.lang.reflect methods wrapped by the method items.
 
Methods inherited from class org.objectweb.jac.core.rtti.AbstractMethodItem
addModifiedCollection, addWrittenField, getAccessedCollections, getAccessedFields, getAccessedReferences, getAddedCollection, getAttribute, getCompactFullName, getConcreteMethod, getFullName, getFullName, getLongName, getModifiedCollections, getOwningClass, getParameter, getParameterCount, getParameterTypeItem, getRealFullName, getTypedName, getWrittenFields, hasModifiedCollections, hasWrittenFields, isModifier, isStatic, removeAccessedField, removeWrittenField, setAccessedFields, setParameter, setWrittenFields, toString
 
Methods inherited from class org.objectweb.jac.core.rtti.MemberItem
addDependentMethod, equals, getClassItem, getDependentMethods, getMemberFromFullName, getModifiers, getTypeItem, isRole, setRole
 
Methods inherited from class org.objectweb.jac.core.rtti.MetaItemDelegate
getDelegate, getParent, setParent
 
Methods inherited from class org.objectweb.jac.core.rtti.MetaItem
getAttribute, getAttribute, getAttributeAlways, getBoolean, getItemClass, registerAccessController, setAttribute, setItemClass, unsetAttribute, unsetAttributesFor
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

emptyArray

public static final MethodItem[] emptyArray
Constructor Detail

MethodItem

public MethodItem(Method delegate,
                  ClassItem parent)
           throws InvalidDelegateException
Default contructor to create a new method item object.

Parameters:
delegate - the java.lang.reflect.Method actual meta item
Method Detail

toMethods

public static Method[] toMethods(MethodItem[] methodItems)
Transforms a method items array into a methods array containing the java.lang.reflect methods wrapped by the method items.

Parameters:
methodItems - the method items
Returns:
the actual methods in java.lang.reflect

getOrgMethod

public final Method getOrgMethod()

hasAccessedReferences

public final boolean hasAccessedReferences()
Tells if this method accesses any references of the class it belongs to.

Returns:
true if one or more references are accessed

getReturnedField

public final FieldItem getReturnedField()
Returns the field item corresponding to the field value returned by this method, if any.

See Also:
setReturnedField(FieldItem)

setReturnedField

public void setReturnedField(FieldItem returnedField)
Sets the field returned by the method.

See Also:
getReturnedField()

getSetField

public final FieldItem getSetField()
Returns the field set by this method, if any. In other words, the field for which the method is the setter. A method is thesetter of a field if it assigns this field directly with one of its argument.

Specified by:
getSetField in class AbstractMethodItem
See Also:
setReturnedField(FieldItem)

setSetField

public void setSetField(FieldItem setField)
Sets the field set by the method. This method should not be called more than once for a gievn field.

See Also:
getSetField()

getAddedCollections

public final CollectionItem[] getAddedCollections()
Get the value of the collections that are added by this method.

Specified by:
getAddedCollections in class AbstractMethodItem
Returns:
value of addedCollections.

hasAddedCollections

public final boolean hasAddedCollections()
Returns true if the method has at least one added collection


setAddedCollections

public final void setAddedCollections(CollectionItem[] addedCollections)
Sets the value of the collections that are added by this method.

Parameters:
addedCollections - value to assign to addedCollections
See Also:
addAddedCollection(CollectionItem)

addAddedCollection

public final void addAddedCollection(CollectionItem addedCollection)
Adds a new added collection for this method.

Parameters:
addedCollection - the collection to add
See Also:
removeAddedCollection(CollectionItem)

removeAddedCollection

public final void removeAddedCollection(CollectionItem collection)
Removes an existing added collection for this method.

Parameters:
collection - the collection to add
See Also:
addAddedCollection(CollectionItem)

getActualMethod

public final Method getActualMethod()
Gets the method represented by this method item.

Returns:
the actual method

getName

public final String getName()
Description copied from class: MetaItem
This method gets the name of the meta item by delegating to the actual java.lang.reflect meta item.

Specified by:
getName in class MetaItem
Returns:
the item name

getType

public final Class getType()
Description copied from class: MetaItemDelegate
This method gets the type of the meta item by delegating to the actual java.lang.reflect meta item.

Specified by:
getType in class MemberItem
Returns:
the item type

getParameterTypes

public Class[] getParameterTypes()
Description copied from class: AbstractMethodItem
Gets the parameter types of this abstract method item.

Specified by:
getParameterTypes in class AbstractMethodItem
Returns:
the actual method parameter types

getCollectionIndexArgument

public int getCollectionIndexArgument()
Returns the number of the argument which is the index of a modified collection if any, -1 otherwise.


setCollectionIndexArgument

public void setCollectionIndexArgument(int collectionIndexArgument)
Sets collectionIndexArgument

See Also:
getCollectionIndexArgument()

getCollectionItemArgument

public int getCollectionItemArgument()
Returns the number of the argument which is the item that will be added to a collection if any, -1 otherwise.


setCollectionItemArgument

public void setCollectionItemArgument(int collectionItemArgument)
Sets collectionItemArgument

See Also:
getCollectionItemArgument()

addAccessedField

public void addAccessedField(FieldItem accessedField)
Description copied from class: AbstractMethodItem
Adds a new accessed field for this method.

Overrides:
addAccessedField in class AbstractMethodItem
Parameters:
accessedField - the field to add
See Also:
AbstractMethodItem.setAccessedFields(FieldItem[]), AbstractMethodItem.removeAccessedField(FieldItem)

invoke

public Object invoke(Object object,
                     Object[] parameters)
Invokes this method on the given object and with the given parameters values.

Overrides:
invoke in class AbstractMethodItem
Parameters:
object - a class this method belongs to intance
parameters - the values of the parameters to invoke this method with

invokeStatic

public final Object invokeStatic(Object[] parameters)
Invokes this static method with the given parameters values.

Parameters:
parameters - the values of the parameters to invoke this method with

invokeWithInit

public final Object invokeWithInit(Object object,
                                   Object[] parameters)
                            throws IllegalAccessException,
                                   InvocationTargetException
Invokes a method with uninitialized parameters.

The parameters array is initialized before the invocation with default values.

Parameters:
object - the target object
parameters - the maybe initialized values of the parameters to invoke this method with (primitive parameters can be null)
IllegalAccessException
InvocationTargetException

isGetter

public final boolean isGetter()
Tells wether the method returns the value of a field

Specified by:
isGetter in class AbstractMethodItem

isCollectionGetter

public final boolean isCollectionGetter()
Specified by:
isCollectionGetter in class AbstractMethodItem

isSetter

public final boolean isSetter()
Tells wether the method is the setter of a field

Specified by:
isSetter in class AbstractMethodItem

isAdder

public final boolean isAdder()
Tells wether the method is an adder of a collection

Specified by:
isAdder in class AbstractMethodItem

getRemovedCollections

public final CollectionItem[] getRemovedCollections()
Gets the value of the collections that are removed by this method.

Specified by:
getRemovedCollections in class AbstractMethodItem
Returns:
value of removedCollections.

getRemovedCollection

public final CollectionItem getRemovedCollection()

hasRemovedCollections

public final boolean hasRemovedCollections()
Returns true if the method has at least one removed collection


setRemovedCollections

public final void setRemovedCollections(CollectionItem[] removedCollections)
Sets the value of the collections that are removed by this method.

Parameters:
removedCollections - value to assign to removedCollections
See Also:
addRemovedCollection(CollectionItem)

addRemovedCollection

public final void addRemovedCollection(CollectionItem removedCollection)
Adds a new removed collection for this method.

Parameters:
removedCollection - the collection to add
See Also:
setRemovedCollections(CollectionItem[]), removeRemovedCollection(CollectionItem)

removeRemovedCollection

public final void removeRemovedCollection(CollectionItem collection)
Removes an existing removed collection for this method.

Parameters:
collection - the collection to remove
See Also:
addRemovedCollection(CollectionItem)

isRemover

public final boolean isRemover()
Tells wether the method is a remover of a collection

Specified by:
isRemover in class AbstractMethodItem

isAccessor

public final boolean isAccessor()
Specified by:
isAccessor in class AbstractMethodItem

isWriter

public final boolean isWriter()
Specified by:
isWriter in class AbstractMethodItem

isCollectionAccessor

public final boolean isCollectionAccessor()
Specified by:
isCollectionAccessor in class AbstractMethodItem

isReferenceAccessor

public final boolean isReferenceAccessor()
Specified by:
isReferenceAccessor in class AbstractMethodItem

isCollectionSetter

public final boolean isCollectionSetter()
Specified by:
isCollectionSetter in class AbstractMethodItem

isFieldSetter

public final boolean isFieldSetter()
Specified by:
isFieldSetter in class AbstractMethodItem

isReferenceSetter

public final boolean isReferenceSetter()
Specified by:
isReferenceSetter in class AbstractMethodItem

isFieldGetter

public final boolean isFieldGetter()
Specified by:
isFieldGetter in class AbstractMethodItem

isReferenceGetter

public final boolean isReferenceGetter()
Specified by:
isReferenceGetter in class AbstractMethodItem

isJacMethod

public final boolean isJacMethod()
Tells wether the method was introduced by JAC