Refactoring: extract ObservableStorageManager from LoggingStorageManager
This commit is contained in:
committed by
Nikolay Krasko
parent
58dbb1ad53
commit
a62e6f7737
@@ -16,19 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.checkers
|
||||
|
||||
import org.jetbrains.kotlin.checkers.LoggingStorageManager.CallData
|
||||
import org.jetbrains.kotlin.storage.ObservableStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.lang.reflect.*
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.GenericDeclaration
|
||||
|
||||
public class LoggingStorageManager(
|
||||
private val delegate: StorageManager,
|
||||
private val callHandler: (lambda: Any, call: LoggingStorageManager.CallData?) -> Unit
|
||||
) : StorageManager {
|
||||
private val callHandler: (lambda: Any, call: LoggingStorageManager.CallData?) -> Unit) : ObservableStorageManager(delegate) {
|
||||
|
||||
public class CallData(
|
||||
val fieldOwner: Any?,
|
||||
@@ -39,21 +34,21 @@ public class LoggingStorageManager(
|
||||
)
|
||||
|
||||
// Creating objects here because we need a reference to it
|
||||
private val <T> (() -> T).logged: () -> T
|
||||
override val <T> (() -> T).observable: () -> T
|
||||
get() = object : () -> T {
|
||||
override fun invoke(): T {
|
||||
val result = this@logged()
|
||||
callHandler(this@logged, computeCallerData(this@logged, this, listOf(), result))
|
||||
val result = this@observable()
|
||||
callHandler(this@observable, computeCallerData(this@observable, this, listOf(), result))
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// Creating objects here because we need a reference to it
|
||||
private val <K, V> ((K) -> V).logged: (K) -> V
|
||||
override val <K, V> ((K) -> V).observable: (K) -> V
|
||||
get() = object : (K) -> V {
|
||||
override fun invoke(p1: K): V {
|
||||
val result = this@logged(p1)
|
||||
callHandler(this@logged, computeCallerData(this@logged, this, listOf(p1), result))
|
||||
val result = this@observable(p1)
|
||||
callHandler(this@observable, computeCallerData(this@observable, this, listOf(p1), result))
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -130,48 +125,4 @@ public class LoggingStorageManager(
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override fun createMemoizedFunction<K, V: Any>(compute: (K) -> V): MemoizedFunctionToNotNull<K, V> {
|
||||
return delegate.createMemoizedFunction(compute.logged)
|
||||
}
|
||||
|
||||
override fun createMemoizedFunctionWithNullableValues<K, V: Any>(compute: (K) -> V?): MemoizedFunctionToNullable<K, V> {
|
||||
return delegate.createMemoizedFunctionWithNullableValues(compute.logged)
|
||||
}
|
||||
|
||||
override fun createMemoizedFunction<K, V: Any>(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNotNull<K, V> {
|
||||
return delegate.createMemoizedFunction(compute.logged, map)
|
||||
}
|
||||
|
||||
override fun createMemoizedFunctionWithNullableValues<K, V: Any>(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNullable<K, V> {
|
||||
return delegate.createMemoizedFunctionWithNullableValues(compute.logged, map)
|
||||
}
|
||||
|
||||
override fun createLazyValue<T: Any>(computable: () -> T): NotNullLazyValue<T> {
|
||||
return delegate.createLazyValue(computable.logged)
|
||||
}
|
||||
|
||||
override fun createRecursionTolerantLazyValue<T: Any>(computable: () -> T, onRecursiveCall: T): NotNullLazyValue<T> {
|
||||
return delegate.createRecursionTolerantLazyValue(computable.logged, onRecursiveCall)
|
||||
}
|
||||
|
||||
override fun createLazyValueWithPostCompute<T: Any>(computable: () -> T, onRecursiveCall: ((Boolean) -> T)?, postCompute: (T) -> Unit): NotNullLazyValue<T> {
|
||||
return delegate.createLazyValueWithPostCompute(computable.logged, onRecursiveCall, postCompute)
|
||||
}
|
||||
|
||||
override fun createNullableLazyValue<T: Any>(computable: () -> T?): NullableLazyValue<T> {
|
||||
return delegate.createNullableLazyValue(computable.logged)
|
||||
}
|
||||
|
||||
override fun createRecursionTolerantNullableLazyValue<T: Any>(computable: () -> T?, onRecursiveCall: T?): NullableLazyValue<T> {
|
||||
return delegate.createRecursionTolerantNullableLazyValue(computable.logged, onRecursiveCall)
|
||||
}
|
||||
|
||||
override fun createNullableLazyValueWithPostCompute<T: Any>(computable: () -> T?, postCompute: (T?) -> Unit): NullableLazyValue<T> {
|
||||
return delegate.createNullableLazyValueWithPostCompute(computable.logged, postCompute)
|
||||
}
|
||||
|
||||
override fun compute<T>(computable: () -> T): T {
|
||||
return delegate.compute(computable.logged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.storage
|
||||
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
|
||||
public abstract class ObservableStorageManager(private val delegate: StorageManager) : StorageManager {
|
||||
protected abstract val <T> (() -> T).observable: () -> T
|
||||
protected abstract val <K, V> ((K) -> V).observable: (K) -> V
|
||||
|
||||
override fun <K, V: Any> createMemoizedFunction(compute: (K) -> V): MemoizedFunctionToNotNull<K, V> {
|
||||
return delegate.createMemoizedFunction(compute.observable)
|
||||
}
|
||||
|
||||
override fun <K, V: Any> createMemoizedFunctionWithNullableValues(compute: (K) -> V?): MemoizedFunctionToNullable<K, V> {
|
||||
return delegate.createMemoizedFunctionWithNullableValues(compute.observable)
|
||||
}
|
||||
|
||||
override fun <K, V: Any> createMemoizedFunction(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNotNull<K, V> {
|
||||
return delegate.createMemoizedFunction(compute.observable, map)
|
||||
}
|
||||
|
||||
override fun <K, V: Any> createMemoizedFunctionWithNullableValues(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNullable<K, V> {
|
||||
return delegate.createMemoizedFunctionWithNullableValues(compute.observable, map)
|
||||
}
|
||||
|
||||
override fun <T: Any> createLazyValue(computable: () -> T): NotNullLazyValue<T> {
|
||||
return delegate.createLazyValue(computable.observable)
|
||||
}
|
||||
|
||||
override fun <T: Any> createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue<T> {
|
||||
return delegate.createRecursionTolerantLazyValue(computable.observable, onRecursiveCall)
|
||||
}
|
||||
|
||||
override fun <T: Any> createLazyValueWithPostCompute(computable: () -> T, onRecursiveCall: ((Boolean) -> T)?, postCompute: (T) -> Unit): NotNullLazyValue<T> {
|
||||
return delegate.createLazyValueWithPostCompute(computable.observable, onRecursiveCall, postCompute)
|
||||
}
|
||||
|
||||
override fun <T: Any> createNullableLazyValue(computable: () -> T?): NullableLazyValue<T> {
|
||||
return delegate.createNullableLazyValue(computable.observable)
|
||||
}
|
||||
|
||||
override fun <T: Any> createRecursionTolerantNullableLazyValue(computable: () -> T?, onRecursiveCall: T?): NullableLazyValue<T> {
|
||||
return delegate.createRecursionTolerantNullableLazyValue(computable.observable, onRecursiveCall)
|
||||
}
|
||||
|
||||
override fun <T: Any> createNullableLazyValueWithPostCompute(computable: () -> T?, postCompute: (T?) -> Unit): NullableLazyValue<T> {
|
||||
return delegate.createNullableLazyValueWithPostCompute(computable.observable, postCompute)
|
||||
}
|
||||
|
||||
override fun <T> compute(computable: () -> T): T {
|
||||
return delegate.compute(computable.observable)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user