Class ClassInstrumentor
- java.lang.Object
-
- org.robolectric.internal.bytecode.ClassInstrumentor
-
- Direct Known Subclasses:
InvokeDynamicClassInstrumentor
public class ClassInstrumentor extends Object
Instruments (i.e. modifies the bytecode) of classes to place the scaffolding necessary to use Robolectric's shadows.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ClassInstrumentor.Decorator
-
Constructor Summary
Constructors Modifier Constructor Description ClassInstrumentor()
protected
ClassInstrumentor(ClassInstrumentor.Decorator decorator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addDirectCallConstructor(MutableClass mutableClass)
protected static String
directMethodName(MutableClass mutableClass, String originalName)
protected String[]
exceptionArray(org.objectweb.asm.tree.MethodNode method)
protected void
generateClassHandlerCall(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode originalMethod, String originalMethodName, RobolectricGeneratorAdapter generator)
byte[]
instrument(ClassDetails classDetails, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)
void
instrument(MutableClass mutableClass)
protected void
instrumentNativeMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)
Creates native stub which returns the default return value.protected void
instrumentNormalMethod(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode method)
Instruments a normal method Rename the method frommethodName
to$$robo$$methodName
.protected void
interceptInvokeVirtualMethod(MutableClass mutableClass, 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 void
makeMethodPrivate(org.objectweb.asm.tree.MethodNode method)
Replaces protected and public class modifiers with private.protected void
makeMethodPublic(org.objectweb.asm.tree.MethodNode method)
Replaces protected and private method modifiers with public.protected void
writeCallToInitializing(MutableClass mutableClass, RobolectricGeneratorAdapter generator)
-
-
-
Constructor Detail
-
ClassInstrumentor
public ClassInstrumentor()
-
ClassInstrumentor
protected ClassInstrumentor(ClassInstrumentor.Decorator decorator)
-
-
Method Detail
-
instrument
public byte[] instrument(ClassDetails classDetails, InstrumentationConfiguration config, ClassNodeProvider classNodeProvider)
-
instrument
public void instrument(MutableClass mutableClass)
-
addDirectCallConstructor
protected void addDirectCallConstructor(MutableClass mutableClass)
-
writeCallToInitializing
protected 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
methodName
to$$robo$$methodName
. - Make it private so we can invoke it directly without subclass overrides taking precedence.
- Remove
final
modifiers, if present. - Create a delegator method named
methodName
which 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
-
directMethodName
protected static String directMethodName(MutableClass mutableClass, String originalName)
-
exceptionArray
protected String[] exceptionArray(org.objectweb.asm.tree.MethodNode method)
-
interceptInvokeVirtualMethod
protected void interceptInvokeVirtualMethod(MutableClass mutableClass, 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 void generateClassHandlerCall(MutableClass mutableClass, org.objectweb.asm.tree.MethodNode originalMethod, String originalMethodName, RobolectricGeneratorAdapter generator)
-
-