Class NativeCallHandler
java.lang.Object
org.robolectric.internal.bytecode.NativeCallHandler
Handler for native calls instrumented by ClassInstrumentor.
Native Calls can either be instrumented as no-op calls (returning a default value or 0 or null) or throw an exception. This helper class helps maintain a list of exemptions to indicates which native calls should be no-op and never throw.
-
Constructor Summary
ConstructorDescriptionNativeCallHandler
(File exemptionsFile, boolean writeExemptions, boolean throwOnNatives) Initializes the native calls handler. -
Method Summary
Modifier and TypeMethodDescriptiongetExceptionMessage
(String descriptor, String className, String methodName) Returns the detailed message to be used by the ClassInstrumentor in the generated bytecode.void
logNativeCall
(String descriptor) Adds the method description to the native call exemption list ifwriteExemptions
is set.boolean
shouldThrow
(String descriptor) Returns whether the ClassInstrumentor should generate an exception or a no-op bytecode.void
-
Constructor Details
-
NativeCallHandler
public NativeCallHandler(@Nonnull File exemptionsFile, boolean writeExemptions, boolean throwOnNatives) throws IOException Initializes the native calls handler.- Parameters:
exemptionsFile
- The exemptions file to read from and/or to generate.writeExemptions
- When true, native calls are added to the exemption list.throwOnNatives
- Whether native calls should throw by default unless their signature is listed in the exemption list. When false, all native calls become no-op.- Throws:
IOException
- if there's an issue reading an existing exemption list.
-
-
Method Details
-
writeExemptionsList
- Throws:
IOException
-
logNativeCall
Adds the method description to the native call exemption list ifwriteExemptions
is set. -
shouldThrow
Returns whether the ClassInstrumentor should generate an exception or a no-op bytecode. -
getExceptionMessage
public String getExceptionMessage(@Nonnull String descriptor, @Nonnull String className, @Nonnull String methodName) Returns the detailed message to be used by the ClassInstrumentor in the generated bytecode.- Parameters:
descriptor
- The ASM descriptor as it should be written in the exemption file.className
- The fully qualified class name, used for the user description.methodName
- The method name, used for the user description.
-