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

<lambda>null1 package shark
2 
3 /**
4  * Extracts metadata from a hprof to be reported in [HeapAnalysisSuccess.metadata].
5  *
6  * This is a functional interface with which you can create a [MetadataExtractor] from a lambda.
7  */
8 fun interface MetadataExtractor {
9   fun extractMetadata(graph: HeapGraph): Map<String, String>
10 
11   companion object {
12 
13     /**
14      * A no-op [MetadataExtractor]
15      */
16     val NO_OP = MetadataExtractor { emptyMap() }
17 
18     /**
19      * Utility function to create a [MetadataExtractor] from the passed in [block] lambda instead of
20      * using the anonymous `object : MetadataExtractor` syntax.
21      *
22      * Usage:
23      *
24      * ```kotlin
25      * val inspector = MetadataExtractor { graph ->
26      *
27      * }
28      * ```
29      */
30     inline operator fun invoke(crossinline block: (HeapGraph) -> Map<String, String>): MetadataExtractor =
31       MetadataExtractor { graph -> block(graph) }
32   }
33 }
34