Storage manager framework uses Kotlin iterfaces

This commit is contained in:
Andrey Breslav
2013-11-19 14:49:39 +04:00
parent 0c2e1fb806
commit 4aadf6e802
7 changed files with 17 additions and 93 deletions
@@ -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;
@@ -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<P, R> extends Function1<P, R> {
@Override
@NotNull
R invoke(P p);
}
@@ -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<P, R> extends Function1<P, R> {
@Override
@Nullable
R invoke(P p);
}
@@ -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<T> extends Function0<T> {
@Override
@Nullable
T invoke();
// Needed for proper toString() behaviors
boolean isComputed();
}
@@ -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
<K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function1<K, V> compute);
@KotlinSignature(
"fun <K, V> createMemoizedFunctionWithNullableValues(compute: (K) -> V?): MemoizedFunctionToNullable<K, V>")
@NotNull
<K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute);
@@ -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<P, R: Any> : Function1<P, R>
public trait MemoizedFunctionToNullable<P, R: Any> : Function1<P, R?>
public interface NotNullLazyValue<T> extends Function0<T> {
@Override
@NotNull
T invoke();
// Needed for proper toString() behaviors
boolean isComputed();
public trait NotNullLazyValue<T: Any> : Function0<T> {
fun isComputed(): Boolean
}
public trait NullableLazyValue<T: Any> : Function0<T?> {
fun isComputed(): Boolean
}
fun <T> NotNullLazyValue<T>.get(_this: Any?, p: PropertyMetadata): T = invoke()
+1
View File
@@ -9,6 +9,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="PROVIDED" name="intellij-core" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime" level="project" />
<orderEntry type="library" name="annotations" level="project" />
</component>
</module>