Interface Code
-
public interface CodeThis represents a piece of code in the program.It is formed of a set of instructions and can be implemented at bytecode or source-code level.
Typically, a code in the program comes from method bodies (it can be init methods (instance or static) or regular methods (instance or static) with any kind of visibility modifiers (public, protected, private).
So, this class allows the client to retrieve code locators on instructions within this code. This locators shall be used conjointly whith an
Instrumentorimplementation in order to perform aspetual transformations of the program (before/after/around type).The
getLocator()method returns the locator for the whole method and can be used to implement callee-side transformations before/after/around the callee method.The other set of locating methods returns locators that allows the client to implement caller-side transformations (e.g. when the code accesses a field or calls a method).
- See Also:
Instrumentor,CodeLocator,Method.getBody()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CodeLocatorgetCallLocator(Method calleeMethod)Returns a call locator for the given callee method.CodeLocatorgetCatchLocator(Class exceptionType)Returns a exception catching locator in the current body.CodeLocatorgetLocator()Returns the code locator that corresponds to this code.CodeLocatorgetReadLocator(Field readField)Returns a field reading locator in the current body.CodeLocatorgetThrowLocator(Class exceptionType)Returns a exception throwing locator in the current body.CodeLocatorgetWriteLocator(Field writtenField)Returns a field writing locator in the current body.
-
-
-
Method Detail
-
getLocator
CodeLocator getLocator()
Returns the code locator that corresponds to this code.For instance, if a code is a set of instructions called
code, then the locator will designate<code>.This locator is typically used to locate a whole method body.
- See Also:
Method.getBody()
-
getCallLocator
CodeLocator getCallLocator(Method calleeMethod)
Returns a call locator for the given callee method.For instance, a call locator for method
m()designates the parts between<>in the following code.[...] aLocalVariable.<m()>; [...] aMethodParameter.<m()>; [...] aField.<m()>; [...] <m()> // when m is a method of the class the current code belongs to [...]
If the given method is a static method, the locator follows the same principles, as for constructors. For instance if the current method is the
initmethod of classC:[...] aVar = <new C()>; [...]
- Parameters:
calleeMethod- the method that is called from the current code
-
getReadLocator
CodeLocator getReadLocator(Field readField)
Returns a field reading locator in the current body.For instance, a field read locator for field
fdesignates the parts between<>in the following code.[...] <f>.m(); [...] aVarOrFieldOrParam = <f>; [...]
- Parameters:
readField- the field that is read from the current code
-
getWriteLocator
CodeLocator getWriteLocator(Field writtenField)
Returns a field writing locator in the current body.For instance, a field write locator for field
fdesignates the parts between<>in the following code.[...] <f=> aVarOrFieldOrParam; [...]
- Parameters:
writtenField- the field that is written from the current code
-
getThrowLocator
CodeLocator getThrowLocator(Class exceptionType)
Returns a exception throwing locator in the current body.For instance, an exception throw locator for exception of type
Edesignates the parts between<>in the following code.[...] <throw> new E(); [...] throw new AnotherExceptionType(); [...]
- Parameters:
exceptionType- the type of the throwed exception
-
getCatchLocator
CodeLocator getCatchLocator(Class exceptionType)
Returns a exception catching locator in the current body.For instance, an exception catch locator for exception of type
Edesignates the parts between<>in the following code.[...] try { [...] } catch(E e1) { <[...]> } catch(AnotherExceptionType e2) { [...] }; [...]- Parameters:
exceptionType- the type of the throwed exception
-
-