Explicit interfaces for memoized functions
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
||||||
@@ -41,7 +42,7 @@ import static org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager.Referen
|
|||||||
public class ScopeProvider {
|
public class ScopeProvider {
|
||||||
private final ResolveSession resolveSession;
|
private final ResolveSession resolveSession;
|
||||||
|
|
||||||
private final Function<JetFile, JetScope> fileScopes;
|
private final MemoizedFunctionToNotNull<JetFile, JetScope> fileScopes;
|
||||||
|
|
||||||
private final NotNullLazyValue<JetScope> defaultImportsScope;
|
private final NotNullLazyValue<JetScope> defaultImportsScope;
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -28,9 +28,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNullable;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -48,7 +49,7 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
private final StorageManager storageManager;
|
private final StorageManager storageManager;
|
||||||
private final NotNullLazyValue<Index> index;
|
private final NotNullLazyValue<Index> index;
|
||||||
|
|
||||||
private final Function<FqName, PackageMemberDeclarationProvider> packageDeclarationProviders;
|
private final MemoizedFunctionToNullable<FqName, PackageMemberDeclarationProvider> packageDeclarationProviders;
|
||||||
|
|
||||||
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull Collection<JetFile> files) {
|
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull Collection<JetFile> files) {
|
||||||
this(storageManager, files, Predicates.<FqName>alwaysFalse());
|
this(storageManager, files, Predicates.<FqName>alwaysFalse());
|
||||||
|
|||||||
+7
-6
@@ -25,11 +25,12 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassInfoUtil;
|
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassInfoUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProvider;
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProvider;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNotNull;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
@@ -47,11 +48,11 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
protected final DP declarationProvider;
|
protected final DP declarationProvider;
|
||||||
protected final D thisDescriptor;
|
protected final D thisDescriptor;
|
||||||
|
|
||||||
private final Function<Name, List<ClassDescriptor>> classDescriptors;
|
private final MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> classDescriptors;
|
||||||
private final Function<Name, List<ClassDescriptor>> objectDescriptors;
|
private final MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> objectDescriptors;
|
||||||
|
|
||||||
private final Function<Name, Set<FunctionDescriptor>> functionDescriptors;
|
private final MemoizedFunctionToNotNull<Name, Set<FunctionDescriptor>> functionDescriptors;
|
||||||
private final Function<Name, Set<VariableDescriptor>> propertyDescriptors;
|
private final MemoizedFunctionToNotNull<Name, Set<VariableDescriptor>> propertyDescriptors;
|
||||||
|
|
||||||
private static class AllDescriptors {
|
private static class AllDescriptors {
|
||||||
private final Collection<DeclarationDescriptor> all = Sets.newLinkedHashSet();
|
private final Collection<DeclarationDescriptor> all = Sets.newLinkedHashSet();
|
||||||
|
|||||||
+3
-2
@@ -24,8 +24,9 @@ import org.jetbrains.jet.lang.psi.JetDeclaration;
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
@@ -35,7 +36,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class LazyPackageMemberScope extends AbstractLazyMemberScope<NamespaceDescriptor, PackageMemberDeclarationProvider> {
|
public class LazyPackageMemberScope extends AbstractLazyMemberScope<NamespaceDescriptor, PackageMemberDeclarationProvider> {
|
||||||
|
|
||||||
private final Function<Name, NamespaceDescriptor> packageDescriptors;
|
private final MemoizedFunctionToNullable<Name, NamespaceDescriptor> packageDescriptors;
|
||||||
|
|
||||||
public LazyPackageMemberScope(@NotNull ResolveSession resolveSession,
|
public LazyPackageMemberScope(@NotNull ResolveSession resolveSession,
|
||||||
@NotNull PackageMemberDeclarationProvider declarationProvider,
|
@NotNull PackageMemberDeclarationProvider declarationProvider,
|
||||||
|
|||||||
+6
-4
@@ -43,10 +43,11 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public <K, V> Function<K, V> createMemoizedFunction(@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind) {
|
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind) {
|
||||||
return new Function<K, V>() {
|
return new MemoizedFunctionToNotNull<K, V>() {
|
||||||
private final ConcurrentMap<K, V> cache = createConcurrentMap(valuesReferenceKind);
|
private final ConcurrentMap<K, V> cache = createConcurrentMap(valuesReferenceKind);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public V fun(@NotNull final K input) {
|
public V fun(@NotNull final K input) {
|
||||||
V value = cache.get(input);
|
V value = cache.get(input);
|
||||||
@@ -69,13 +70,14 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public <K, V> Function<K, V> createMemoizedFunctionWithNullableValues(
|
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||||
@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind
|
@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind
|
||||||
) {
|
) {
|
||||||
return new Function<K, V>() {
|
return new MemoizedFunctionToNullable<K, V>() {
|
||||||
private final ConcurrentMap<K, NullableLazyValue<V>> cache = createConcurrentMap(valuesReferenceKind);
|
private final ConcurrentMap<K, NullableLazyValue<V>> cache = createConcurrentMap(valuesReferenceKind);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public V fun(@NotNull final K input) {
|
public V fun(@NotNull final K input) {
|
||||||
NullableLazyValue<V> lazyValue = cache.get(input);
|
NullableLazyValue<V> lazyValue = cache.get(input);
|
||||||
if (lazyValue != null) return lazyValue.compute();
|
if (lazyValue != null) return lazyValue.compute();
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.resolve.lazy.storage;
|
||||||
|
|
||||||
|
import com.intellij.util.Function;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface MemoizedFunctionToNotNull<P, R> extends Function<P, R> {
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
R fun(P p);
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.resolve.lazy.storage;
|
||||||
|
|
||||||
|
import com.intellij.util.Function;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface MemoizedFunctionToNullable<P, R> extends Function<P, R> {
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
R fun(P p);
|
||||||
|
}
|
||||||
+2
-2
@@ -32,9 +32,9 @@ public interface StorageManager {
|
|||||||
* the value gets collected and then re-computed
|
* the value gets collected and then re-computed
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
<K, V> Function<K, V> createMemoizedFunction(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
<K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
||||||
@NotNull
|
@NotNull
|
||||||
<K, V> Function<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
<K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
<T> NotNullLazyValue<T> createLazyValue(@NotNull Computable<T> computable);
|
<T> NotNullLazyValue<T> createLazyValue(@NotNull Computable<T> computable);
|
||||||
|
|||||||
Reference in New Issue
Block a user