Make LazyValue extend Computable
This commit is contained in:
@@ -88,7 +88,7 @@ public class ScopeProvider {
|
|||||||
rootPackageDescriptor.getMemberScope(),
|
rootPackageDescriptor.getMemberScope(),
|
||||||
packageDescriptor.getMemberScope(),
|
packageDescriptor.getMemberScope(),
|
||||||
importsScope,
|
importsScope,
|
||||||
defaultImportsScope.get());
|
defaultImportsScope.compute());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetScope createScopeWithDefaultImports() {
|
private JetScope createScopeWithDefaultImports() {
|
||||||
|
|||||||
+1
-1
@@ -106,7 +106,7 @@ public class FilteringClassLikeInfo implements JetClassLikeInfo {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<JetDeclaration> getDeclarations() {
|
public List<JetDeclaration> getDeclarations() {
|
||||||
return filteredDeclarations.get();
|
return filteredDeclarations.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+4
-4
@@ -85,24 +85,24 @@ public abstract class AbstractPsiBasedDeclarationProvider implements Declaration
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<JetDeclaration> getAllDeclarations() {
|
public List<JetDeclaration> getAllDeclarations() {
|
||||||
return index.get().allDeclarations;
|
return index.compute().allDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
|
public List<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
|
||||||
return Lists.newArrayList(index.get().functions.get(name));
|
return Lists.newArrayList(index.compute().functions.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<JetProperty> getPropertyDeclarations(@NotNull Name name) {
|
public List<JetProperty> getPropertyDeclarations(@NotNull Name name) {
|
||||||
return Lists.newArrayList(index.get().properties.get(name));
|
return Lists.newArrayList(index.compute().properties.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name) {
|
public Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name) {
|
||||||
return index.get().classesAndObjects.get(name);
|
return index.compute().classesAndObjects.get(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -99,7 +99,7 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ boolean isPackageDeclaredExplicitly(@NotNull FqName packageFqName) {
|
/*package*/ boolean isPackageDeclaredExplicitly(@NotNull FqName packageFqName) {
|
||||||
return index.get().declaredPackages.contains(packageFqName);
|
return index.compute().declaredPackages.contains(packageFqName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ boolean isPackageDeclared(@NotNull FqName packageFqName) {
|
/*package*/ boolean isPackageDeclared(@NotNull FqName packageFqName) {
|
||||||
@@ -107,7 +107,7 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ Collection<FqName> getAllDeclaredSubPackagesOf(@NotNull final FqName parent) {
|
/*package*/ Collection<FqName> getAllDeclaredSubPackagesOf(@NotNull final FqName parent) {
|
||||||
return Collections2.filter(index.get().declaredPackages, new Predicate<FqName>() {
|
return Collections2.filter(index.compute().declaredPackages, new Predicate<FqName>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(FqName fqName) {
|
public boolean apply(FqName fqName) {
|
||||||
return !fqName.isRoot() && fqName.parent().equals(parent);
|
return !fqName.isRoot() && fqName.parent().equals(parent);
|
||||||
@@ -129,13 +129,13 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FileBasedPackageMemberDeclarationProvider(storageManager, packageFqName, this, index.get().filesByPackage.get(packageFqName));
|
return new FileBasedPackageMemberDeclarationProvider(storageManager, packageFqName, this, index.compute().filesByPackage.get(packageFqName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ClassMemberDeclarationProvider getClassMemberDeclarationProvider(@NotNull JetClassLikeInfo classLikeInfo) {
|
public ClassMemberDeclarationProvider getClassMemberDeclarationProvider(@NotNull JetClassLikeInfo classLikeInfo) {
|
||||||
if (!index.get().filesByPackage.containsKey(classLikeInfo.getContainingPackageFqName())) {
|
if (!index.compute().filesByPackage.containsKey(classLikeInfo.getContainingPackageFqName())) {
|
||||||
throw new IllegalStateException("This factory doesn't know about this class: " + classLikeInfo);
|
throw new IllegalStateException("This factory doesn't know about this class: " + classLikeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ public class FileBasedPackageMemberDeclarationProvider extends AbstractPsiBasedD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<FqName> getAllDeclaredPackages() {
|
public Collection<FqName> getAllDeclaredPackages() {
|
||||||
return allDeclaredPackages.get();
|
return allDeclaredPackages.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -208,7 +208,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassDescriptor> getObjectDescriptors() {
|
public Collection<ClassDescriptor> getObjectDescriptors() {
|
||||||
return allDescriptors.get().objects;
|
return allDescriptors.compute().objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -237,7 +237,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
return allDescriptors.get().all;
|
return allDescriptors.compute().all;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+8
-8
@@ -172,7 +172,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetScope getScopeForClassHeaderResolution() {
|
public JetScope getScopeForClassHeaderResolution() {
|
||||||
return scopeForClassHeaderResolution.get();
|
return scopeForClassHeaderResolution.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -193,7 +193,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetScope getScopeForMemberDeclarationResolution() {
|
public JetScope getScopeForMemberDeclarationResolution() {
|
||||||
return scopeForMemberDeclarationResolution.get();
|
return scopeForMemberDeclarationResolution.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -211,7 +211,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetScope getScopeForPropertyInitializerResolution() {
|
public JetScope getScopeForPropertyInitializerResolution() {
|
||||||
return scopeForPropertyInitializerResolution.get();
|
return scopeForPropertyInitializerResolution.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -277,7 +277,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassDescriptor getClassObjectDescriptor() {
|
public ClassDescriptor getClassObjectDescriptor() {
|
||||||
return classObjectDescriptor.get();
|
return classObjectDescriptor.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -337,12 +337,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||||
return thisAsReceiverParameter.get();
|
return thisAsReceiverParameter.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AnnotationDescriptor> getAnnotations() {
|
public List<AnnotationDescriptor> getAnnotations() {
|
||||||
return annotations.get();
|
return annotations.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -442,13 +442,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TypeParameterDescriptor> getParameters() {
|
public List<TypeParameterDescriptor> getParameters() {
|
||||||
return parameters.get();
|
return parameters.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetType> getSupertypes() {
|
public Collection<JetType> getSupertypes() {
|
||||||
return supertypes.get();
|
return supertypes.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findAndDisconnectLoopsInTypeHierarchy(Collection<JetType> supertypes) {
|
private void findAndDisconnectLoopsInTypeHierarchy(Collection<JetType> supertypes) {
|
||||||
|
|||||||
+1
-1
@@ -343,7 +343,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ConstructorDescriptor getPrimaryConstructor() {
|
public ConstructorDescriptor getPrimaryConstructor() {
|
||||||
return primaryConstructor.get();
|
return primaryConstructor.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+4
-4
@@ -112,7 +112,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<JetType> getUpperBounds() {
|
public Set<JetType> getUpperBounds() {
|
||||||
return upperBounds.get();
|
return upperBounds.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -166,7 +166,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetType getUpperBoundsAsType() {
|
public JetType getUpperBoundsAsType() {
|
||||||
return upperBoundsAsType.get();
|
return upperBoundsAsType.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -195,7 +195,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TypeConstructor getTypeConstructor() {
|
public TypeConstructor getTypeConstructor() {
|
||||||
return typeConstructor.get();
|
return typeConstructor.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -238,7 +238,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetType getDefaultType() {
|
public JetType getDefaultType() {
|
||||||
return defaultType.get();
|
return defaultType.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||||
|
|
||||||
public interface LazyValue<T> {
|
import com.intellij.openapi.util.Computable;
|
||||||
T get();
|
|
||||||
|
public interface LazyValue<T> extends Computable<T> {
|
||||||
|
@Override
|
||||||
|
T compute();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -78,7 +78,7 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
@Override
|
@Override
|
||||||
public V fun(@NotNull final K input) {
|
public V fun(@NotNull final K input) {
|
||||||
LazyValue<V> lazyValue = cache.get(input);
|
LazyValue<V> lazyValue = cache.get(input);
|
||||||
if (lazyValue != null) return lazyValue.get();
|
if (lazyValue != null) return lazyValue.compute();
|
||||||
|
|
||||||
lazyValue = createNullableLazyValue(new Computable<V>() {
|
lazyValue = createNullableLazyValue(new Computable<V>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -88,9 +88,9 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
LazyValue<V> oldValue = cache.putIfAbsent(input, lazyValue);
|
LazyValue<V> oldValue = cache.putIfAbsent(input, lazyValue);
|
||||||
if (oldValue != null) return oldValue.get();
|
if (oldValue != null) return oldValue.compute();
|
||||||
|
|
||||||
return lazyValue.get();
|
return lazyValue.compute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public T get() {
|
public T compute() {
|
||||||
T _value = value;
|
T _value = value;
|
||||||
if (_value != null) {
|
if (_value != null) {
|
||||||
return _value;
|
return _value;
|
||||||
@@ -195,7 +195,7 @@ public class LockBasedStorageManager implements StorageManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public T get() {
|
public T compute() {
|
||||||
// NOTE: no local variables used here, because they would not reduce the number of volatile reads/writes
|
// NOTE: no local variables used here, because they would not reduce the number of volatile reads/writes
|
||||||
|
|
||||||
// We want to guarantee that whenever computed = true, value is not null
|
// We want to guarantee that whenever computed = true, value is not null
|
||||||
|
|||||||
Reference in New Issue
Block a user