@HashCodeAndEqualsPlugin.Enhance public class CachedReturnPlugin extends Plugin.ForElementMatcher implements Plugin.Factory
final
fields. In this context, it is possible that
the method is executed multiple times by different threads but at the same time, this approach avoids a volatile
field
declaration. For methods with a primitive return type, the type's default value is used to indicate that a method was not yet invoked.
For methods that return a reference type, null
is used as an indicator. If a method returns such a value, this mechanism will
not work. This plugin does not need to be closed.Modifier and Type | Class and Description |
---|---|
protected static interface |
CachedReturnPlugin.CacheField
Indicates the field that stores the cached value.
|
protected static class |
CachedReturnPlugin.CacheFieldOffsetMapping
An offset mapping for the cached field.
|
static interface |
CachedReturnPlugin.Enhance
Indicates methods that should be cached, i.e.
|
Plugin.Factory.Simple, Plugin.Factory.UsingReflection
Plugin.Compound, Plugin.Engine, Plugin.Factory, Plugin.ForElementMatcher, Plugin.NoOp
ElementMatcher.Junction<S>
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ADVICE_INFIX
The infix symbol for advice classes.
|
private java.util.Map<TypeDescription,TypeDescription> |
adviceByType
A map of advice types mapped by their argument type.
|
private ClassFileLocator |
classFileLocator
The class file locator to use.
|
private static java.lang.String |
NAME_INFIX
An infix between a field and the random suffix if no field name is chosen.
|
private RandomString |
randomString
A random string to use for avoid field name collisions.
|
Constructor and Description |
---|
CachedReturnPlugin()
Creates a plugin for caching method return values.
|
Modifier and Type | Method and Description |
---|---|
DynamicType.Builder<?> |
apply(DynamicType.Builder<?> builder,
TypeDescription typeDescription,
ClassFileLocator classFileLocator)
Applies this plugin.
|
void |
close() |
Plugin |
make()
Returns a plugin that can be used for a transformation and which is subsequently closed.
|
matches
private static final java.lang.String NAME_INFIX
private static final java.lang.String ADVICE_INFIX
@HashCodeAndEqualsPlugin.ValueHandling(value=IGNORE) private final RandomString randomString
private final ClassFileLocator classFileLocator
@HashCodeAndEqualsPlugin.ValueHandling(value=IGNORE) private final java.util.Map<TypeDescription,TypeDescription> adviceByType
public CachedReturnPlugin()
public Plugin make()
make
in interface Plugin.Factory
public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)
apply
in interface Plugin
builder
- The builder to use as a basis for the applied transformation.typeDescription
- The type being transformed.classFileLocator
- A class file locator that can locate other types in the scope of the project.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable