Package net.bytebuddy.build
Class RenamingPlugin
- java.lang.Object
-
- net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
-
- net.bytebuddy.build.RenamingPlugin
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,AsmVisitorWrapper
,Plugin
,ElementMatcher<TypeDescription>
@Enhance public class RenamingPlugin extends AsmVisitorWrapper.AbstractBase implements Plugin
A plugin that replaces names that are discovered in class files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RenamingPlugin.Renaming
A renaming function tho transform a type's binary name.protected static class
RenamingPlugin.RenamingRemapper
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
Fields Modifier and Type Field Description private ElementMatcher<? super TypeDescription>
matcher
A matcher that determines what types to consider for renaming.private RenamingPlugin.Renaming
renaming
The renaming to apply.-
Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
-
Constructor Summary
Constructors Constructor Description RenamingPlugin(java.lang.String pattern, java.lang.String replacement)
Creates a renaming plugin for a given regular expression and replacement that applies to all types.RenamingPlugin(java.lang.String pattern, java.lang.String replacement, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DynamicType.Builder<?>
apply(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 Detail
-
renaming
private final RenamingPlugin.Renaming renaming
The renaming to apply.
-
matcher
private final ElementMatcher<? super TypeDescription> matcher
A matcher that determines what types to consider for renaming.
-
-
Constructor Detail
-
RenamingPlugin
public RenamingPlugin(java.lang.String pattern, java.lang.String replacement)
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
public RenamingPlugin(java.lang.String pattern, java.lang.String replacement, java.lang.String prefix)
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
public RenamingPlugin(RenamingPlugin.Renaming renaming)
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 Detail
-
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
public boolean matches(TypeDescription target)
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
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.
-
-