From 4aadf6e8026510d5a18662fcfb19bc329621cc2e Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 19 Nov 2013 14:49:39 +0400 Subject: [PATCH] Storage manager framework uses Kotlin iterfaces --- .../jet/storage/LockBasedStorageManager.java | 4 +-- .../storage/MemoizedFunctionToNotNull.java | 26 ----------------- .../storage/MemoizedFunctionToNullable.java | 26 ----------------- .../jet/storage/NullableLazyValue.java | 29 ------------------- .../jetbrains/jet/storage/StorageManager.java | 3 ++ .../{NotNullLazyValue.java => storage.kt} | 21 +++++++------- core/util.runtime/util.runtime.iml | 1 + 7 files changed, 17 insertions(+), 93 deletions(-) delete mode 100644 core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNotNull.java delete mode 100644 core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNullable.java delete mode 100644 core/util.runtime/src/org/jetbrains/jet/storage/NullableLazyValue.java rename core/util.runtime/src/org/jetbrains/jet/storage/{NotNullLazyValue.java => storage.kt} (58%) diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/LockBasedStorageManager.java b/core/util.runtime/src/org/jetbrains/jet/storage/LockBasedStorageManager.java index 0fa35abb0ea..fd63db91d0f 100644 --- a/core/util.runtime/src/org/jetbrains/jet/storage/LockBasedStorageManager.java +++ b/core/util.runtime/src/org/jetbrains/jet/storage/LockBasedStorageManager.java @@ -265,7 +265,7 @@ public class LockBasedStorageManager implements StorageManager { @Override @Nullable - public V invoke(@NotNull K input) { + public V invoke(K input) { Object value = cache.get(input); if (value != null) return WrappedValues.unescapeExceptionOrNull(value); @@ -306,7 +306,7 @@ public class LockBasedStorageManager implements StorageManager { @NotNull @Override - public V invoke(@NotNull K input) { + public V invoke(K input) { V result = super.invoke(input); assert result != null : "compute() returned null"; return result; diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNotNull.java b/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNotNull.java deleted file mode 100644 index 55e853f5640..00000000000 --- a/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNotNull.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.storage; - -import jet.Function1; -import org.jetbrains.annotations.NotNull; - -public interface MemoizedFunctionToNotNull extends Function1 { - @Override - @NotNull - R invoke(P p); -} diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNullable.java b/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNullable.java deleted file mode 100644 index 5521c143933..00000000000 --- a/core/util.runtime/src/org/jetbrains/jet/storage/MemoizedFunctionToNullable.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.storage; - -import jet.Function1; -import org.jetbrains.annotations.Nullable; - -public interface MemoizedFunctionToNullable extends Function1 { - @Override - @Nullable - R invoke(P p); -} diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/NullableLazyValue.java b/core/util.runtime/src/org/jetbrains/jet/storage/NullableLazyValue.java deleted file mode 100644 index 63d3984c51a..00000000000 --- a/core/util.runtime/src/org/jetbrains/jet/storage/NullableLazyValue.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.storage; - -import jet.Function0; -import org.jetbrains.annotations.Nullable; - -public interface NullableLazyValue extends Function0 { - @Override - @Nullable - T invoke(); - - // Needed for proper toString() behaviors - boolean isComputed(); -} diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/StorageManager.java b/core/util.runtime/src/org/jetbrains/jet/storage/StorageManager.java index 4c37eb9e663..b0bcedd123d 100644 --- a/core/util.runtime/src/org/jetbrains/jet/storage/StorageManager.java +++ b/core/util.runtime/src/org/jetbrains/jet/storage/StorageManager.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.storage; import jet.Function0; import jet.Function1; import jet.Unit; +import jet.runtime.typeinfo.KotlinSignature; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,6 +34,8 @@ public interface StorageManager { */ @NotNull MemoizedFunctionToNotNull createMemoizedFunction(@NotNull Function1 compute); + @KotlinSignature( + "fun createMemoizedFunctionWithNullableValues(compute: (K) -> V?): MemoizedFunctionToNullable") @NotNull MemoizedFunctionToNullable createMemoizedFunctionWithNullableValues(@NotNull Function1 compute); diff --git a/core/util.runtime/src/org/jetbrains/jet/storage/NotNullLazyValue.java b/core/util.runtime/src/org/jetbrains/jet/storage/storage.kt similarity index 58% rename from core/util.runtime/src/org/jetbrains/jet/storage/NotNullLazyValue.java rename to core/util.runtime/src/org/jetbrains/jet/storage/storage.kt index ff0c0ef95d2..e6e0e2ff875 100644 --- a/core/util.runtime/src/org/jetbrains/jet/storage/NotNullLazyValue.java +++ b/core/util.runtime/src/org/jetbrains/jet/storage/storage.kt @@ -14,16 +14,17 @@ * limitations under the License. */ -package org.jetbrains.jet.storage; +package org.jetbrains.jet.storage -import jet.Function0; -import org.jetbrains.annotations.NotNull; +public trait MemoizedFunctionToNotNull : Function1 +public trait MemoizedFunctionToNullable : Function1 -public interface NotNullLazyValue extends Function0 { - @Override - @NotNull - T invoke(); - - // Needed for proper toString() behaviors - boolean isComputed(); +public trait NotNullLazyValue : Function0 { + fun isComputed(): Boolean } + +public trait NullableLazyValue : Function0 { + fun isComputed(): Boolean +} + +fun NotNullLazyValue.get(_this: Any?, p: PropertyMetadata): T = invoke() diff --git a/core/util.runtime/util.runtime.iml b/core/util.runtime/util.runtime.iml index 4815fceb3bf..cd88404a500 100644 --- a/core/util.runtime/util.runtime.iml +++ b/core/util.runtime/util.runtime.iml @@ -9,6 +9,7 @@ +