xref: /aosp_15_r20/external/leakcanary2/shark/src/main/java/shark/ObjectInspector.kt (revision d9e8da70d8c9df9a41d7848ae506fb3115cae6e6)

<lambda>null1 package shark
2 
3 /**
4  * Provides LeakCanary with insights about objects (classes, instances and arrays) found in the
5  * heap. [inspect] will be called for each object that LeakCanary wants to know more about.
6  * The implementation can then use the provided [ObjectReporter] to provide insights for that
7  * object.
8  *
9  * This is a functional interface with which you can create a [ObjectInspector] from a lambda.
10  */
11 fun interface ObjectInspector {
12 
13   /**
14    * @see [ObjectInspector]
15    */
16   fun inspect(reporter: ObjectReporter)
17 
18   companion object {
19     /**
20      * Utility function to create a [ObjectInspector] from the passed in [block] lambda instead of
21      * using the anonymous `object : OnHeapAnalyzedListener` syntax.
22      *
23      * Usage:
24      *
25      * ```kotlin
26      * val inspector = ObjectInspector { reporter ->
27      *
28      * }
29      * ```
30      */
31     inline operator fun invoke(crossinline block: (ObjectReporter) -> Unit): ObjectInspector =
32       ObjectInspector { reporter -> block(reporter) }
33   }
34 }
35