Class ClassInstrumentor
- java.lang.Object
-
- org.robolectric.internal.bytecode.ClassInstrumentor
-
- Direct Known Subclasses:
InvokeDynamicClassInstrumentor,OldClassInstrumentor
public abstract class ClassInstrumentor extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceClassInstrumentor.Decorator
-
Constructor Summary
Constructors Modifier Constructor Description protectedClassInstrumentor(ClassInstrumentor.Decorator decorator)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddDirectCallConstructor(MutableClass mutableClass)MutableClassanalyzeClass(byte[] origClassBytes, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)protected java.lang.String[]exceptionArray(org.objectweb.asm.tree.MethodNode method)protected abstract voidgenerateClassHandlerCall(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode originalMethod, java.lang.String originalMethodName, RobolectricGeneratorAdapter generator)byte[]instrument(byte[] origBytes, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)voidinstrument(MutableClass mutableClass)protected voidinstrumentNativeMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)Creates native stub which returns the default return value.protected voidinstrumentNormalMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)Instruments a normal method Rename the method frommethodNameto$$robo$$methodName.protected abstract voidinterceptInvokeVirtualMethod(MutableClass mutableClass, java.util.ListIterator<org.objectweb.asm.tree.AbstractInsnNode> instructions, org.objectweb.asm.tree.MethodInsnNode targetMethod)Decides to call through the appropriate method to intercept the method with an INVOKEVIRTUAL Opcode, depending if the invokedynamic bytecode instruction is available (Java 7+).protected voidmakeMethodPrivate(org.objectweb.asm.tree.MethodNode method)Replaces protected and public class modifiers with private.protected voidmakeMethodPublic(org.objectweb.asm.tree.MethodNode method)Replaces protected and private method modifiers with public.protected abstract voidwriteCallToInitializing(MutableClass mutableClass, RobolectricGeneratorAdapter generator)
-
-
-
Constructor Detail
-
ClassInstrumentor
protected ClassInstrumentor(ClassInstrumentor.Decorator decorator)
-
-
Method Detail
-
analyzeClass
public MutableClass analyzeClass(byte[] origClassBytes, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)
-
instrument
public byte[] instrument(byte[] origBytes, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)
-
instrument
public void instrument(MutableClass mutableClass)
-
addDirectCallConstructor
protected abstract void addDirectCallConstructor(MutableClass mutableClass)
-
writeCallToInitializing
protected abstract void writeCallToInitializing(MutableClass mutableClass, RobolectricGeneratorAdapter generator)
-
instrumentNormalMethod
protected void instrumentNormalMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)
Instruments a normal method- Rename the method from
methodNameto$$robo$$methodName. - Make it private so we can invoke it directly without subclass overrides taking precedence.
- Remove
finalmodifiers, if present. - Create a delegator method named
methodNamewhich delegates to theClassHandler.
- Rename the method from
-
instrumentNativeMethod
protected void instrumentNativeMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)
Creates native stub which returns the default return value.- Parameters:
mutableClass- Class to be instrumentedmethod- Method to be instrumented, must be native
-
exceptionArray
protected java.lang.String[] exceptionArray(org.objectweb.asm.tree.MethodNode method)
-
interceptInvokeVirtualMethod
protected abstract void interceptInvokeVirtualMethod(MutableClass mutableClass, java.util.ListIterator<org.objectweb.asm.tree.AbstractInsnNode> instructions, org.objectweb.asm.tree.MethodInsnNode targetMethod)
Decides to call through the appropriate method to intercept the method with an INVOKEVIRTUAL Opcode, depending if the invokedynamic bytecode instruction is available (Java 7+).
-
makeMethodPublic
protected void makeMethodPublic(org.objectweb.asm.tree.MethodNode method)
Replaces protected and private method modifiers with public.
-
makeMethodPrivate
protected void makeMethodPrivate(org.objectweb.asm.tree.MethodNode method)
Replaces protected and public class modifiers with private.
-
generateClassHandlerCall
protected abstract void generateClassHandlerCall(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode originalMethod, java.lang.String originalMethodName, RobolectricGeneratorAdapter generator)
-
-