Top Description Fields Constructors Methods
org.objectweb.asm.commons

public Class StaticInitMerger

extends ClassVisitor
Class Inheritance
Imports
org.objectweb.asm.ClassVisitor, .MethodVisitor, .Opcodes

A ClassVisitor that merges <clinit> methods into a single one. All the existing <clinit> methods are renamed, and a new one is created, which calls all the renamed methods.
Author
Eric Bruneton

Field Summary

Modifier and TypeField and Description
private MethodVisitor
mergedClinitVisitor

The MethodVisitor for the merged <clinit> method.

private int
numClinitMethods

The number of <clinit> methods visited so far.

private String
owner

The internal name of the visited class.

private final String
renamedClinitMethodPrefix

The prefix to use to rename the existing <clinit> methods.

Inherited from org.objectweb.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
public
StaticInitMerger(final String
the prefix to use to rename the existing <clinit> methods.
prefix
,
final ClassVisitor
the class visitor to which this visitor must delegate method calls. May be null.
classVisitor
)

Constructs a new StaticInitMerger.

protected
StaticInitMerger(final int
the ASM API version implemented by this visitor. Must be one of the ASMx values in Opcodes.
api
,
final String
the prefix to use to rename the existing <clinit> methods.
prefix
,
final ClassVisitor
the class visitor to which this visitor must delegate method calls. May be null.
classVisitor
)

Constructs a new StaticInitMerger.

Method Summary

Modifier and TypeMethod and Description
public void
visit(final int
the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.
version
,
final int
the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.
access
,
final String
the internal name of the class (see Type#getInternalName()).
name
,
final String
the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
signature
,
final String
the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.
superName
,
final String[]
the internal names of the class's interfaces (see Type#getInternalName()). May be null.
interfaces
)

Overrides org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.
public void
visitEnd()

Overrides org.objectweb.asm.ClassVisitor.visitEnd.

Visits the end of the class.
public MethodVisitor
visitMethod(final int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
access
,
final String
the method's name.
name
,
final String
the method's descriptor (see Type).
descriptor
,
final String
the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
signature
,
final String[]
the internal names of the method's exception classes (see Type#getInternalName()). May be null.
exceptions
)

Overrides org.objectweb.asm.ClassVisitor.visitMethod.

Visits a method of the class.
Inherited from org.objectweb.asm.ClassVisitor:
getDelegatevisitAnnotationvisitAttributevisitFieldvisitInnerClassvisitModulevisitNestHostvisitNestMembervisitOuterClassvisitPermittedSubclassvisitRecordComponentvisitSourcevisitTypeAnnotation

Field Detail

mergedClinitVisitorback to summary
private MethodVisitor mergedClinitVisitor

The MethodVisitor for the merged <clinit> method.

numClinitMethodsback to summary
private int numClinitMethods

The number of <clinit> methods visited so far.

ownerback to summary
private String owner

The internal name of the visited class.

renamedClinitMethodPrefixback to summary
private final String renamedClinitMethodPrefix

The prefix to use to rename the existing <clinit> methods.

Constructor Detail

StaticInitMergerback to summary
public StaticInitMerger(final String prefix, final ClassVisitor classVisitor)

Constructs a new StaticInitMerger. Subclasses must not use this constructor. Instead, they must use the StaticInitMerger(int, String, ClassVisitor) version.

Parameters
prefix:String

the prefix to use to rename the existing <clinit> methods.

classVisitor:ClassVisitor

the class visitor to which this visitor must delegate method calls. May be null.

StaticInitMergerback to summary
protected StaticInitMerger(final int api, final String prefix, final ClassVisitor classVisitor)

Constructs a new StaticInitMerger.

Parameters
api:int

the ASM API version implemented by this visitor. Must be one of the ASMx values in Opcodes.

prefix:String

the prefix to use to rename the existing <clinit> methods.

classVisitor:ClassVisitor

the class visitor to which this visitor must delegate method calls. May be null.

Method Detail

visitback to summary
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces)

Overrides org.objectweb.asm.ClassVisitor.visit.

Doc from org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.

Parameters
version:int

the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.

access:int

the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.

name:String

the internal name of the class (see Type#getInternalName()).

signature:String

the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.

superName:String

the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.

interfaces:String[]

the internal names of the class's interfaces (see Type#getInternalName()). May be null.

Annotations
@Override
visitEndback to summary
public void visitEnd()

Overrides org.objectweb.asm.ClassVisitor.visitEnd.

Doc from org.objectweb.asm.ClassVisitor.visitEnd.

Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

Annotations
@Override
visitMethodback to summary
public MethodVisitor visitMethod(final int access, final String name, final String descriptor, final String signature, final String[] exceptions)

Overrides org.objectweb.asm.ClassVisitor.visitMethod.

Doc from org.objectweb.asm.ClassVisitor.visitMethod.

Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Parameters
access:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

name:String

the method's name.

descriptor:String

the method's descriptor (see Type).

signature:String

the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.

exceptions:String[]

the internal names of the method's exception classes (see Type#getInternalName()). May be null.

Returns:MethodVisitor

an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

Annotations
@Override