Package net.bytebuddy.build
Class RenamingPlugin
java.lang.Object
net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
net.bytebuddy.build.RenamingPlugin
- All Implemented Interfaces:
Closeable
,AutoCloseable
,AsmVisitorWrapper
,Plugin
,ElementMatcher<TypeDescription>
A plugin that replaces names that are discovered in class files.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A renaming function tho transform a type's binary name.protected static class
An ASMRemapper
to apply renamings.Nested classes/interfaces inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
AsmVisitorWrapper.AbstractBase, AsmVisitorWrapper.Compound, AsmVisitorWrapper.ForDeclaredFields, AsmVisitorWrapper.ForDeclaredMethods, AsmVisitorWrapper.NoOp
Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher
ElementMatcher.Junction<S>
Nested classes/interfaces inherited from interface net.bytebuddy.build.Plugin
Plugin.Engine, Plugin.Factory, Plugin.ForElementMatcher, Plugin.NoOp, Plugin.WithInitialization, Plugin.WithPreprocessor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ElementMatcher
<? super TypeDescription> A matcher that determines what types to consider for renaming.private final RenamingPlugin.Renaming
The renaming to apply.Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
Constructor Summary
ConstructorsConstructorDescriptionRenamingPlugin
(String pattern, String replacement) Creates a renaming plugin for a given regular expression and replacement that applies to all types.RenamingPlugin
(String pattern, String replacement, String prefix) Creates a renaming plugin for a given regular expression and replacement that applies to all types that start with a given prefix.RenamingPlugin
(RenamingPlugin.Renaming renaming) Creates a renaming plugin for the given renaming that applies to all types.RenamingPlugin
(RenamingPlugin.Renaming renaming, ElementMatcher<? super TypeDescription> matcher) Creates a renaming plugin for the given renaming and type matcher. -
Method Summary
Modifier and TypeMethodDescriptionapply
(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) Applies this plugin.void
close()
boolean
matches
(TypeDescription target) Matches a target against this element matcher.org.objectweb.asm.ClassVisitor
wrap
(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) Applies aClassVisitorWrapper
to the creation of aDynamicType
.Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
Field Details
-
renaming
The renaming to apply. -
matcher
A matcher that determines what types to consider for renaming.
-
-
Constructor Details
-
RenamingPlugin
Creates a renaming plugin for a given regular expression and replacement that applies to all types.- Parameters:
pattern
- The pattern to consider.replacement
- The replacement to apply if the supplied pattern is matched.
-
RenamingPlugin
Creates a renaming plugin for a given regular expression and replacement that applies to all types that start with a given prefix.- Parameters:
pattern
- The pattern to consider.replacement
- The replacement to apply if the supplied pattern is matched.prefix
- The prefix for types to consider for renaming.
-
RenamingPlugin
Creates a renaming plugin for the given renaming that applies to all types.- Parameters:
renaming
- The renaming to apply.
-
RenamingPlugin
public RenamingPlugin(RenamingPlugin.Renaming renaming, ElementMatcher<? super TypeDescription> matcher) Creates a renaming plugin for the given renaming and type matcher.- Parameters:
renaming
- The renaming to apply.matcher
- A matcher that determines what types to consider for renaming.
-
-
Method Details
-
apply
public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) Applies this plugin.- Specified by:
apply
in interfacePlugin
- Parameters:
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.- Returns:
- The supplied builder with additional transformations registered.
-
matches
Matches a target against this element matcher.- Specified by:
matches
in interfaceElementMatcher<TypeDescription>
- Parameters:
target
- The instance to be matched ornull
.- Returns:
true
if the given element is matched by this matcher orfalse
otherwise.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
wrap
public org.objectweb.asm.ClassVisitor wrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) Applies aClassVisitorWrapper
to the creation of aDynamicType
.- Specified by:
wrap
in interfaceAsmVisitorWrapper
- Parameters:
instrumentedType
- The instrumented type.classVisitor
- AClassVisitor
to become the new primary class visitor to which the createdDynamicType
is written to.implementationContext
- The implementation context of the current instrumentation.typePool
- The type pool that was provided for the class creation.fields
- The instrumented type's fields.methods
- The instrumented type's methods non-ignored declared and virtually inherited methods.writerFlags
- The ASMClassWriter
flags to consider.readerFlags
- The ASMClassReader
flags to consider.- Returns:
- A new
ClassVisitor
that usually delegates to theClassVisitor
delivered in the argument.
-