Lazy values and memoized functions conform to Kotlin's function interfaces
This commit is contained in:
committed by
Alexander Udalov
parent
a1e4ca2871
commit
4d28dfada6
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.descriptors.serialization.JavaProtoBuf;
|
||||
@@ -61,7 +62,7 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
|
||||
|
||||
private final MemoizedFunctionToNotNull<KotlinJvmBinaryClass, Map<MemberSignature, List<AnnotationDescriptor>>> memberAnnotations =
|
||||
storageManager.createMemoizedFunction(
|
||||
new MemoizedFunctionToNotNull<KotlinJvmBinaryClass, Map<MemberSignature, List<AnnotationDescriptor>>>() {
|
||||
new Function<KotlinJvmBinaryClass, Map<MemberSignature, List<AnnotationDescriptor>>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<MemberSignature, List<AnnotationDescriptor>> fun(@NotNull KotlinJvmBinaryClass kotlinClass) {
|
||||
|
||||
@@ -179,6 +179,11 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
return value != NotValue.NOT_COMPUTED && value != NotValue.COMPUTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T invoke() {
|
||||
return compute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T compute() {
|
||||
Object _value = value;
|
||||
@@ -258,6 +263,11 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
this.compute = compute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V invoke(K k) {
|
||||
return fun(k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public V fun(@NotNull K input) {
|
||||
|
||||
@@ -17,10 +17,15 @@
|
||||
package org.jetbrains.jet.storage;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MemoizedFunctionToNotNull<P, R> extends Function<P, R> {
|
||||
public interface MemoizedFunctionToNotNull<P, R> extends Function<P, R>, Function1<P, R> {
|
||||
@Override
|
||||
@NotNull
|
||||
R fun(P p);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
R invoke(P p);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,15 @@
|
||||
package org.jetbrains.jet.storage;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface MemoizedFunctionToNullable<P, R> extends Function<P, R> {
|
||||
public interface MemoizedFunctionToNullable<P, R> extends Function<P, R>, Function1<P, R> {
|
||||
@Override
|
||||
@Nullable
|
||||
R fun(P p);
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
R invoke(P p);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,18 @@
|
||||
package org.jetbrains.jet.storage;
|
||||
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import jet.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface NotNullLazyValue<T> extends Computable<T> {
|
||||
public interface NotNullLazyValue<T> extends Computable<T>, Function0<T> {
|
||||
@Override
|
||||
@NotNull
|
||||
T compute();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
T invoke();
|
||||
|
||||
// Needed for proper toString() behaviors
|
||||
boolean isComputed();
|
||||
}
|
||||
|
||||
@@ -17,13 +17,18 @@
|
||||
package org.jetbrains.jet.storage;
|
||||
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import jet.Function0;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface NullableLazyValue<T> extends Computable<T> {
|
||||
public interface NullableLazyValue<T> extends Computable<T>, Function0<T> {
|
||||
@Override
|
||||
@Nullable
|
||||
T compute();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
T invoke();
|
||||
|
||||
// Needed for proper toString() behaviors
|
||||
boolean isComputed();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" scope="PROVIDED" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="runtime" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user