Skip to content

Commit

Permalink
Revert removal of invoke operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Zhang committed Oct 1, 2020
1 parent 9497586 commit 4521d7d
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ fun interface OnHeapAnalyzedListener {
* @see OnHeapAnalyzedListener
*/
fun onHeapAnalyzed(heapAnalysis: HeapAnalysis)

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (HeapAnalysis) -> Unit): OnHeapAnalyzedListener =
object : OnHeapAnalyzedListener {
override fun onHeapAnalyzed(heapAnalysis: HeapAnalysis) {
block(heapAnalysis)
}
}
}
}
9 changes: 9 additions & 0 deletions leakcanary-object-watcher/src/main/java/leakcanary/Clock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ fun interface Clock {
* On Android VMs, this should return android.os.SystemClock.uptimeMillis().
*/
fun uptimeMillis(): Long

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: () -> Long): Clock =
object : Clock {
override fun uptimeMillis(): Long = block()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ fun interface OnObjectRetainedListener {
* A watched object became retained.
*/
fun onObjectRetained()

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: () -> Unit): OnObjectRetainedListener =
object : OnObjectRetainedListener {
override fun onObjectRetained() {
block()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class ObjectWatcherTest {
override fun uptimeMillis(): Long {
return time
}
}, checkRetainedExecutor).apply {
addOnObjectRetainedListener{}
}
}, checkRetainedExecutor).apply { addOnObjectRetainedListener(OnObjectRetainedListener {}) }
var time: Long = 0

var ref: Any? = Any()
Expand Down
16 changes: 15 additions & 1 deletion shark-hprof/src/main/java/shark/OnHprofRecordListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package shark
/**
* Listener passed in to [HprofReader.readHprofRecords], gets notified for each [HprofRecord]
* found in the heap dump which types is in the set of the recordTypes parameter passed to
* [HprofReader.readHprofRecords].
* [StreamingHprofReader.readRecords].
*
* This is a functional interface with which you can create a [OnHprofRecordListener] from a lambda.
*/
Expand All @@ -15,4 +15,18 @@ fun interface OnHprofRecordListener {
position: Long,
record: HprofRecord
)

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (Long, HprofRecord) -> Unit): OnHprofRecordListener =
object : OnHprofRecordListener {
override fun onHprofRecord(
position: Long,
record: HprofRecord
) {
block(position, record)
}
}
}
}
8 changes: 8 additions & 0 deletions shark/src/main/java/shark/LeakingObjectFinder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ fun interface LeakingObjectFinder {
*/
fun findLeakingObjectIds(graph: HeapGraph): Set<Long>

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (HeapGraph) -> Set<Long>): LeakingObjectFinder =
object : LeakingObjectFinder {
override fun findLeakingObjectIds(graph: HeapGraph): Set<Long> = block(graph)
}
}
}
7 changes: 6 additions & 1 deletion shark/src/main/java/shark/MetadataExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ fun interface MetadataExtractor {
* A no-op [MetadataExtractor]
*/
val NO_OP = MetadataExtractor { emptyMap() }
}

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (HeapGraph) -> Map<String, String>): MetadataExtractor =
object : MetadataExtractor {
override fun extractMetadata(graph: HeapGraph): Map<String, String> = block(graph)
}
}
}
12 changes: 12 additions & 0 deletions shark/src/main/java/shark/ObjectInspector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ fun interface ObjectInspector {
*/
fun inspect(reporter: ObjectReporter)

companion object {

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (ObjectReporter) -> Unit): ObjectInspector =
object : ObjectInspector {
override fun inspect(
reporter: ObjectReporter
) {
block(reporter)
}
}
}
}
8 changes: 8 additions & 0 deletions shark/src/main/java/shark/OnAnalysisProgressListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ fun interface OnAnalysisProgressListener {
* A no-op [OnAnalysisProgressListener]
*/
val NO_OP = OnAnalysisProgressListener {}

@Deprecated("Leverage Kotlin SAM lambda expression")
inline operator fun invoke(crossinline block: (Step) -> Unit): OnAnalysisProgressListener =
object : OnAnalysisProgressListener {
override fun onAnalysisProgress(step: Step) {
block(step)
}
}
}
}

0 comments on commit 4521d7d

Please sign in to comment.