Enum Constant and Description |
---|
CLASS
The value of this part depends on the
Inheritance.Mode :
For Inheritance.Mode.NONE or Inheritance.Mode.WITH_SUPERCLASS_NAME ,
it is the name of the class where this annotation is placed. |
INSTANCE
The string representation of the instance on which the instrumented method is called.
|
INSTANCE_CLASS
The class name of the instance on which the instrumented method is called.
|
METHOD
The name of the annotated method.
|
PARAMETER
The string representation of a method parameter.
|
TEXT
Fixed text.
|
Modifier and Type | Method and Description |
---|---|
static Part.Type |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static Part.Type[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final Part.Type TEXT
Part.text()
parameter is used to set the text.
TEXT is the default for Part.value()
, so you can write
@Part(text = "Some text")
If you concatenate a TEXT part with other parts, you might have to add surrounding space to the text.
public static final Part.Type CLASS
Inheritance.Mode
:
Inheritance.Mode.NONE
or Inheritance.Mode.WITH_SUPERCLASS_NAME
,
it is the name of the class where this annotation is placed.
For a ClassTransaction
, this is the annotated class, for a
MethodTransaction
, this is the class surrounding the annotated method.
Inheritance.Mode.WITH_SUBCLASS_NAMES
,
it is the name of the class where the instrumented method is defined. If a method is overridden in a subclass,
the name of the subclass is used.
For this type, the Part.packageMode()
parameter is used to control
the format of the class name. By default, only the simple class name is added. In that case, you can
omit the "value" parameter name:
@Part(Type.CLASS)If you need the package name to be added, set packageMode to
PackageMode.ABBREVIATED
or
PackageMode.FULL
:
@Part(value = Type.CLASS, packageMode = PackageMode.FULL)
public static final Part.Type METHOD
The method name is added without the signature and without the class name.
Since there are no further applicable parameters for this type, it can always be specified without the "value" parameter name:
@Part(Type.METHOD)
public static final Part.Type PARAMETER
MethodTransaction
and will produce an
empty string otherwise.
For this type, the Part.parameterIndex()
parameter is used to select the desired parameter.
By default, the first parameter is used (index 0), so you can write
@Part(Type.PARAMETER)
in that case. If another parameter should be used, the "value" parameter name has to be specified for the type:
@Part(value = Type.PARAMETER, parameterIndex = 2)
The parameter index is zero-based, so this will select the third parameter.
The toString() method will be called on the selected parameter. If the value is primitive, the primitive string representation is added. If the value is null, the string "null" will be added. You can optionally apply a getter chain to the selected parameter and add the result of the getter chain instead of the parameter. For example:
@Part(value = Type.PARAMETER, parameterIndex = 1, getterChain = "getUser().getName()")
See the documentation for Part.getterChain()
for more information.
public static final Part.Type INSTANCE
MethodTransaction
and
ClassTransaction
, but not for static methods.
In that case, the value of the part will be empty.
The toString() method will be called on the instance. You can optionally apply a getter chain to the instance and add the result of the getter chain instead of the parameter. For example:
@Part(value = Type.INSTANCE, getterChain = "getUser().getName()")
See the documentation for Part.getterChain()
for more information.
public static final Part.Type INSTANCE_CLASS
MethodTransaction
and
ClassTransaction
. For static methods it yields the same value as
CLASS
.
The difference with respect to the CLASS
type with Inheritance.Mode.WITH_SUBCLASS_NAMES
is that for a subclass, the class name of the actual class is added and not the class name where the instrumented method has
been defined. For example, if the instrumented method follows the template method pattern, you can capture the actual class name
to distinguish between different sub step implementations.
The CLASS
type imposes less overhead, so it is preferable if you don't need to know the actual class name.
Just like the CLASS
type, the INSTANCE_CLASS type supports the parameter
Part.packageMode()
to control if and how package names should be added.
public static Part.Type[] values()
for (Part.Type c : Part.Type.values()) System.out.println(c);
public static Part.Type valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant
with the specified namejava.lang.NullPointerException
- if the argument is null