diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt b/compiler/tests/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt index dc20ba6814d..5716111359f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt +++ b/compiler/tests/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt @@ -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).logged: () -> T + override val (() -> 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).logged: (K) -> V + override val ((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(compute: (K) -> V): MemoizedFunctionToNotNull { - return delegate.createMemoizedFunction(compute.logged) - } - - override fun createMemoizedFunctionWithNullableValues(compute: (K) -> V?): MemoizedFunctionToNullable { - return delegate.createMemoizedFunctionWithNullableValues(compute.logged) - } - - override fun createMemoizedFunction(compute: (K) -> V, map: ConcurrentMap): MemoizedFunctionToNotNull { - return delegate.createMemoizedFunction(compute.logged, map) - } - - override fun createMemoizedFunctionWithNullableValues(compute: (K) -> V, map: ConcurrentMap): MemoizedFunctionToNullable { - return delegate.createMemoizedFunctionWithNullableValues(compute.logged, map) - } - - override fun createLazyValue(computable: () -> T): NotNullLazyValue { - return delegate.createLazyValue(computable.logged) - } - - override fun createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue { - return delegate.createRecursionTolerantLazyValue(computable.logged, onRecursiveCall) - } - - override fun createLazyValueWithPostCompute(computable: () -> T, onRecursiveCall: ((Boolean) -> T)?, postCompute: (T) -> Unit): NotNullLazyValue { - return delegate.createLazyValueWithPostCompute(computable.logged, onRecursiveCall, postCompute) - } - - override fun createNullableLazyValue(computable: () -> T?): NullableLazyValue { - return delegate.createNullableLazyValue(computable.logged) - } - - override fun createRecursionTolerantNullableLazyValue(computable: () -> T?, onRecursiveCall: T?): NullableLazyValue { - return delegate.createRecursionTolerantNullableLazyValue(computable.logged, onRecursiveCall) - } - - override fun createNullableLazyValueWithPostCompute(computable: () -> T?, postCompute: (T?) -> Unit): NullableLazyValue { - return delegate.createNullableLazyValueWithPostCompute(computable.logged, postCompute) - } - - override fun compute(computable: () -> T): T { - return delegate.compute(computable.logged) - } } diff --git a/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt b/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt new file mode 100644 index 00000000000..40247e3d78e --- /dev/null +++ b/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt @@ -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).observable: () -> T + protected abstract val ((K) -> V).observable: (K) -> V + + override fun createMemoizedFunction(compute: (K) -> V): MemoizedFunctionToNotNull { + return delegate.createMemoizedFunction(compute.observable) + } + + override fun createMemoizedFunctionWithNullableValues(compute: (K) -> V?): MemoizedFunctionToNullable { + return delegate.createMemoizedFunctionWithNullableValues(compute.observable) + } + + override fun createMemoizedFunction(compute: (K) -> V, map: ConcurrentMap): MemoizedFunctionToNotNull { + return delegate.createMemoizedFunction(compute.observable, map) + } + + override fun createMemoizedFunctionWithNullableValues(compute: (K) -> V, map: ConcurrentMap): MemoizedFunctionToNullable { + return delegate.createMemoizedFunctionWithNullableValues(compute.observable, map) + } + + override fun createLazyValue(computable: () -> T): NotNullLazyValue { + return delegate.createLazyValue(computable.observable) + } + + override fun createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue { + return delegate.createRecursionTolerantLazyValue(computable.observable, onRecursiveCall) + } + + override fun createLazyValueWithPostCompute(computable: () -> T, onRecursiveCall: ((Boolean) -> T)?, postCompute: (T) -> Unit): NotNullLazyValue { + return delegate.createLazyValueWithPostCompute(computable.observable, onRecursiveCall, postCompute) + } + + override fun createNullableLazyValue(computable: () -> T?): NullableLazyValue { + return delegate.createNullableLazyValue(computable.observable) + } + + override fun createRecursionTolerantNullableLazyValue(computable: () -> T?, onRecursiveCall: T?): NullableLazyValue { + return delegate.createRecursionTolerantNullableLazyValue(computable.observable, onRecursiveCall) + } + + override fun createNullableLazyValueWithPostCompute(computable: () -> T?, postCompute: (T?) -> Unit): NullableLazyValue { + return delegate.createNullableLazyValueWithPostCompute(computable.observable, postCompute) + } + + override fun compute(computable: () -> T): T { + return delegate.compute(computable.observable) + } +}