@ParametersAreNonnullByDefault
public class ASMUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.util.regex.Pattern |
FIELD_DECLARATION_PATTERN |
static java.lang.String |
FIELD_DECLARATION_REGEX |
static java.util.regex.Pattern |
METHOD_DECLARATION_PATTERN |
static java.lang.String |
METHOD_DECLARATION_REGEX |
| Constructor and Description |
|---|
ASMUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addParameters(org.objectweb.asm.tree.MethodNode methodNode,
org.objectweb.asm.Type... parameters)
Add parameters to a method.
The actual code is not changed, only the descriptor and annotations. |
static org.objectweb.asm.tree.ClassNode |
cloneClass(org.objectweb.asm.tree.ClassNode classNode)
Clone a class node with all its methods and fields.
|
static org.objectweb.asm.tree.InsnList |
cloneInsnList(org.objectweb.asm.tree.InsnList insnList)
Clone an insn list with all its instructions.
|
static java.util.Map<org.objectweb.asm.tree.LabelNode,org.objectweb.asm.tree.LabelNode> |
cloneLabels(org.objectweb.asm.tree.InsnList original)
Clone all labels from an insn list.
|
static org.objectweb.asm.tree.MethodNode |
cloneMethod(org.objectweb.asm.tree.MethodNode methodNode)
Clone a method node with all its instructions.
|
static java.lang.String |
combiToRegex(java.lang.String combi)
Convert a field or method search pattern to a regex pattern.
Use * for a wildcard search. e.g. |
static boolean |
compareType(org.objectweb.asm.Type type,
org.objectweb.asm.Type targetType)
Compare a single type with a target type
This supports the usage of object instead of the actual type but does not check for other inheritance. Object can not be used as a replacement for primitives. |
static boolean |
compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes)
Compare an array of types with a target array of types.
This supports the usage of object instead of the actual type but does not check for other inheritance. Object can not be used as a replacement for primitives. |
static boolean |
compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes,
boolean prepend,
org.objectweb.asm.Type... additionalNeededTypes)
Compare an array of types with a target array of types.
This supports the usage of object instead of the actual type but does not check for other inheritance. Object can not be used as a replacement for primitives. |
static org.objectweb.asm.tree.ClassNode |
createEmptyClass(java.lang.String name)
Create an empty class with a default constructor.
|
static void |
cutParameters(org.objectweb.asm.tree.MethodNode methodNode,
int count)
Cut the given amount of parameters from the end of a method.
The actual code is not changed, only the descriptor and annotations. |
static java.lang.String |
dot(java.lang.String s)
Replace all slashes with dots in the given class/package name.
|
static org.objectweb.asm.tree.ClassNode |
fromBytes(byte[] bytecode)
Get a class node from the raw bytecode of a class.
|
static org.objectweb.asm.tree.ClassNode |
fromBytes(byte[] bytecode,
int flags)
Get a class node from the raw bytecode of a class.
|
static org.objectweb.asm.tree.InsnList |
getCast(org.objectweb.asm.Type wantedType)
Get the byte code to cast an object to a given type.
Converts primitive wrapper to their primitive types (e.g. |
static org.objectweb.asm.tree.FieldNode |
getField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Get a field node from a class node using the name.
The descriptor is passed as a parameter but is not used for the search. |
static java.util.List<org.objectweb.asm.tree.FieldNode> |
getFieldsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
Get a list of method nodes from a class node using the combined name and descriptor.
Use * for a wildcard search. e.g. |
static org.objectweb.asm.tree.AbstractInsnNode |
getFirstConstructorInstruction(java.lang.String superClass,
org.objectweb.asm.tree.MethodNode methodNode)
Get the first instruction of a constructor skipping the super init call.
|
static int |
getFreeVarIndex(org.objectweb.asm.tree.MethodNode methodNode)
Get the last empty local variable index.
You can simply count the index up from there. |
static int |
getLoadOpcode(org.objectweb.asm.Type type)
Get the needed load opcode for the given type.
|
static org.objectweb.asm.tree.MethodNode |
getMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Get a method node from a class node using the name and descriptor.
|
static java.util.List<org.objectweb.asm.tree.MethodNode> |
getMethodsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
Get a list of method nodes from a class node using the combined name and descriptor.
Use * for a wildcard search. e.g. |
static java.lang.Number |
getNumber(org.objectweb.asm.tree.AbstractInsnNode instruction)
Get a number from an insn node if it represents one.
This also works for constants (e.g. |
static int[] |
getParameterIndices(org.objectweb.asm.tree.MethodNode methodNode)
Get the variable indices for the parameters of a method.
|
static int[] |
getParameterIndices(org.objectweb.asm.Type[] types,
boolean isStatic)
Get the variable indices for an array of types.
|
static org.objectweb.asm.tree.AbstractInsnNode |
getPrimitiveToObject(org.objectweb.asm.Type primitive)
Get the byte code to wrap a primitive to its wrapper type (e.g.
|
static int |
getReturnOpcode(org.objectweb.asm.Type returnType)
Get the needed return opcode for the given type.
|
static int |
getStoreOpcode(org.objectweb.asm.Type type)
Get the needed store opcode for the given type.
|
static boolean |
hasField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Check if a class node has a field with the given name and descriptor.
|
static boolean |
hasMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Check if a class node has a method with the given name and descriptor.
|
static org.objectweb.asm.tree.AbstractInsnNode |
intPush(int i)
Create a new insn node representing the given int.
This uses the most efficient opcode for the given int. |
static boolean |
isAccessLower(int toCheck,
int checkAgainst)
Check if the given access is lower than another.
private < package private < protected < public |
static void |
removeParameters(org.objectweb.asm.tree.MethodNode methodNode,
int... indices)
Remove the given parameter indices from a method.
The actual code is not changed, only the descriptor and annotations. |
static int |
setAccess(int currentAccess,
int newAccess)
Set the wanted access to a given access mask.
Other access flags will be removed. |
static int |
setModifier(int currentAccess,
int modifier,
boolean value)
Set a modifier to a given access mask.
|
static java.lang.String |
slash(java.lang.String s)
Replace all dots with slashes in the given class/package name.
|
static MemberDeclaration |
splitMemberDeclaration(java.lang.String memberDeclaration)
Split a member declaration into owner, name and descriptor.
All parts are required. Examples: - java/lang/String.length()I- java/lang/System.out:Ljava/io/PrintStream;- Ljava/lang/String;length()I- Ljava/lang/System;out:Ljava/io/PrintStream; |
static org.objectweb.asm.tree.InsnList |
swap(org.objectweb.asm.Type top,
org.objectweb.asm.Type bottom)
Get the bytecode to swap two stack elements.
This also works for long and double types. |
static byte[] |
toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider)
Get the bytecode from a class node.
|
static byte[] |
toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider,
int flags)
Get the bytecode from a class node.
|
static byte[] |
toBytes(org.objectweb.asm.tree.ClassNode node,
TransformerManager transformerManager)
Get the bytecode from a class node.
|
static byte[] |
toBytes(org.objectweb.asm.tree.ClassNode node,
TransformerManager transformerManager,
int flags)
Get the bytecode from a class node.
|
static byte[] |
toStacklessBytes(org.objectweb.asm.tree.ClassNode node)
Get the bytecode from a class node without calculating stack map frames.
|
public static final java.lang.String METHOD_DECLARATION_REGEX
public static final java.lang.String FIELD_DECLARATION_REGEX
public static final java.util.regex.Pattern METHOD_DECLARATION_PATTERN
public static final java.util.regex.Pattern FIELD_DECLARATION_PATTERN
public static org.objectweb.asm.tree.ClassNode fromBytes(byte[] bytecode)
bytecode - The bytecode of the classpublic static org.objectweb.asm.tree.ClassNode fromBytes(byte[] bytecode,
int flags)
bytecode - The bytecode of the classflags - The flags to use for the class readerpublic static byte[] toBytes(org.objectweb.asm.tree.ClassNode node,
TransformerManager transformerManager)
node - The class nodetransformerManager - The transformer managerpublic static byte[] toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider)
node - The class nodeclassTree - The class tree used to get the super classesclassProvider - The class provider used for stack frame calculationpublic static byte[] toBytes(org.objectweb.asm.tree.ClassNode node,
TransformerManager transformerManager,
int flags)
node - The class nodetransformerManager - The transformer managerflags - The flags to use for the class writerpublic static byte[] toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider,
int flags)
node - The class nodeclassTree - The class tree used to get the super classesclassProvider - The class provider used for stack frame calculationflags - The flags to use for the class writerpublic static byte[] toStacklessBytes(org.objectweb.asm.tree.ClassNode node)
node - The class node@Nullable
public static org.objectweb.asm.tree.MethodNode getMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the methoddesc - The descriptor of the methodpublic static boolean hasMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the methoddesc - The descriptor of the method@Nullable
public static org.objectweb.asm.tree.FieldNode getField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the fielddesc - The descriptor of the fieldpublic static boolean hasField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the fielddesc - The descriptor of the fieldpublic static java.util.List<org.objectweb.asm.tree.MethodNode> getMethodsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
classNode - The class node to search incombi - The combined name and descriptorjava.lang.IllegalArgumentException - If the combined name and descriptor is emptypublic static java.util.List<org.objectweb.asm.tree.FieldNode> getFieldsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
classNode - The class node to search incombi - The combined name and descriptorpublic static java.lang.String combiToRegex(java.lang.String combi)
combi - The search patternpublic static boolean isAccessLower(int toCheck,
int checkAgainst)
toCheck - The access to checkcheckAgainst - The access to check againstpublic static int setAccess(int currentAccess,
int newAccess)
currentAccess - The current access masknewAccess - The wanted accesspublic static int setModifier(int currentAccess,
int modifier,
boolean value)
currentAccess - The current access maskmodifier - The modifier to setvalue - The value to set the modifier topublic static int getReturnOpcode(org.objectweb.asm.Type returnType)
returnType - The return type of a methodpublic static int getLoadOpcode(org.objectweb.asm.Type type)
type - The type to get the load opcode forpublic static int getStoreOpcode(org.objectweb.asm.Type type)
type - The type to get the store opcode forpublic static int getFreeVarIndex(org.objectweb.asm.tree.MethodNode methodNode)
methodNode - The method to get the last empty local variable index forpublic static org.objectweb.asm.tree.InsnList getCast(org.objectweb.asm.Type wantedType)
wantedType - The wanted type@Nullable public static org.objectweb.asm.tree.AbstractInsnNode getPrimitiveToObject(org.objectweb.asm.Type primitive)
primitive - The primitive type to wrap@Nullable public static MemberDeclaration splitMemberDeclaration(java.lang.String memberDeclaration)
java/lang/String.length()Ijava/lang/System.out:Ljava/io/PrintStream;Ljava/lang/String;length()ILjava/lang/System;out:Ljava/io/PrintStream;memberDeclaration - The member declaration@Nullable
public static org.objectweb.asm.tree.AbstractInsnNode getFirstConstructorInstruction(java.lang.String superClass,
org.objectweb.asm.tree.MethodNode methodNode)
superClass - The name of the super classmethodNode - The constructor method node@Nullable
public static java.lang.Number getNumber(@Nullable
org.objectweb.asm.tree.AbstractInsnNode instruction)
Opcodes.ICONST_0)instruction - The insn nodepublic static boolean compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes)
types - The source array of typestargetTypes - The target array of typespublic static boolean compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes,
boolean prepend,
org.objectweb.asm.Type... additionalNeededTypes)
types - The source array of typestargetTypes - The target array of typesprepend - If the additional types array should be prepended or appendedadditionalNeededTypes - The additional types to append/prepend to the sourcepublic static boolean compareType(org.objectweb.asm.Type type,
org.objectweb.asm.Type targetType)
type - The source typetargetType - The target typepublic static org.objectweb.asm.tree.ClassNode cloneClass(org.objectweb.asm.tree.ClassNode classNode)
classNode - The class node to clonepublic static org.objectweb.asm.tree.MethodNode cloneMethod(org.objectweb.asm.tree.MethodNode methodNode)
methodNode - The method node to clonepublic static org.objectweb.asm.tree.InsnList cloneInsnList(org.objectweb.asm.tree.InsnList insnList)
insnList - The insn list to clonepublic static java.util.Map<org.objectweb.asm.tree.LabelNode,org.objectweb.asm.tree.LabelNode> cloneLabels(org.objectweb.asm.tree.InsnList original)
original - The insn list to clone the labels frompublic static org.objectweb.asm.tree.ClassNode createEmptyClass(java.lang.String name)
name - The name of the classpublic static org.objectweb.asm.tree.AbstractInsnNode intPush(int i)
i - The intpublic static int[] getParameterIndices(org.objectweb.asm.tree.MethodNode methodNode)
methodNode - The method nodepublic static int[] getParameterIndices(org.objectweb.asm.Type[] types,
boolean isStatic)
types - The typesisStatic - If the first index should be 0 or 1public static void cutParameters(org.objectweb.asm.tree.MethodNode methodNode,
int count)
methodNode - The method nodecount - The amount of parameters to cutpublic static void removeParameters(org.objectweb.asm.tree.MethodNode methodNode,
int... indices)
methodNode - The method nodeindices - The indices to removepublic static void addParameters(org.objectweb.asm.tree.MethodNode methodNode,
org.objectweb.asm.Type... parameters)
methodNode - The method nodeparameters - The parameters to addpublic static org.objectweb.asm.tree.InsnList swap(org.objectweb.asm.Type top,
org.objectweb.asm.Type bottom)
top - The type of the top stack elementbottom - The type of the bottom stack elementpublic static java.lang.String dot(java.lang.String s)
s - The class/package namepublic static java.lang.String slash(java.lang.String s)
s - The class/package name