Make LazyValue extend Computable
This commit is contained in:
@@ -88,7 +88,7 @@ public class ScopeProvider {
|
||||
rootPackageDescriptor.getMemberScope(),
|
||||
packageDescriptor.getMemberScope(),
|
||||
importsScope,
|
||||
defaultImportsScope.get());
|
||||
defaultImportsScope.compute());
|
||||
}
|
||||
|
||||
private JetScope createScopeWithDefaultImports() {
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class FilteringClassLikeInfo implements JetClassLikeInfo {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
return filteredDeclarations.get();
|
||||
return filteredDeclarations.compute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -85,24 +85,24 @@ public abstract class AbstractPsiBasedDeclarationProvider implements Declaration
|
||||
|
||||
@Override
|
||||
public List<JetDeclaration> getAllDeclarations() {
|
||||
return index.get().allDeclarations;
|
||||
return index.compute().allDeclarations;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
|
||||
return Lists.newArrayList(index.get().functions.get(name));
|
||||
return Lists.newArrayList(index.compute().functions.get(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetProperty> getPropertyDeclarations(@NotNull Name name) {
|
||||
return Lists.newArrayList(index.get().properties.get(name));
|
||||
return Lists.newArrayList(index.compute().properties.get(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
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) {
|
||||
return index.get().declaredPackages.contains(packageFqName);
|
||||
return index.compute().declaredPackages.contains(packageFqName);
|
||||
}
|
||||
|
||||
/*package*/ boolean isPackageDeclared(@NotNull FqName packageFqName) {
|
||||
@@ -107,7 +107,7 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
||||
}
|
||||
|
||||
/*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
|
||||
public boolean apply(FqName fqName) {
|
||||
return !fqName.isRoot() && fqName.parent().equals(parent);
|
||||
@@ -129,13 +129,13 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
||||
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
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class FileBasedPackageMemberDeclarationProvider extends AbstractPsiBasedD
|
||||
|
||||
@Override
|
||||
public Collection<FqName> getAllDeclaredPackages() {
|
||||
return allDeclaredPackages.get();
|
||||
return allDeclaredPackages.compute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -208,7 +208,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> getObjectDescriptors() {
|
||||
return allDescriptors.get().objects;
|
||||
return allDescriptors.compute().objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +237,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return allDescriptors.get().all;
|
||||
return allDescriptors.compute().all;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+8
-8
@@ -172,7 +172,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForClassHeaderResolution() {
|
||||
return scopeForClassHeaderResolution.get();
|
||||
return scopeForClassHeaderResolution.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -193,7 +193,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberDeclarationResolution() {
|
||||
return scopeForMemberDeclarationResolution.get();
|
||||
return scopeForMemberDeclarationResolution.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -211,7 +211,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForPropertyInitializerResolution() {
|
||||
return scopeForPropertyInitializerResolution.get();
|
||||
return scopeForPropertyInitializerResolution.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -277,7 +277,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClassObjectDescriptor() {
|
||||
return classObjectDescriptor.get();
|
||||
return classObjectDescriptor.compute();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -337,12 +337,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||
return thisAsReceiverParameter.get();
|
||||
return thisAsReceiverParameter.compute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return annotations.get();
|
||||
return annotations.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -442,13 +442,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return parameters.get();
|
||||
return parameters.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes.get();
|
||||
return supertypes.compute();
|
||||
}
|
||||
|
||||
private void findAndDisconnectLoopsInTypeHierarchy(Collection<JetType> supertypes) {
|
||||
|
||||
+1
-1
@@ -343,7 +343,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
|
||||
@Nullable
|
||||
public ConstructorDescriptor getPrimaryConstructor() {
|
||||
return primaryConstructor.get();
|
||||
return primaryConstructor.compute();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+4
-4
@@ -112,7 +112,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getUpperBounds() {
|
||||
return upperBounds.get();
|
||||
return upperBounds.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -166,7 +166,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getUpperBoundsAsType() {
|
||||
return upperBoundsAsType.get();
|
||||
return upperBoundsAsType.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -195,7 +195,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor.get();
|
||||
return typeConstructor.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -238,7 +238,7 @@ public class LazyTypeParameterDescriptor implements TypeParameterDescriptor, Laz
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
return defaultType.get();
|
||||
return defaultType.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
public interface LazyValue<T> {
|
||||
T get();
|
||||
import com.intellij.openapi.util.Computable;
|
||||
|
||||
public interface LazyValue<T> extends Computable<T> {
|
||||
@Override
|
||||
T compute();
|
||||
}
|
||||
|
||||
+5
-5
@@ -78,7 +78,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
@Override
|
||||
public V fun(@NotNull final K input) {
|
||||
LazyValue<V> lazyValue = cache.get(input);
|
||||
if (lazyValue != null) return lazyValue.get();
|
||||
if (lazyValue != null) return lazyValue.compute();
|
||||
|
||||
lazyValue = createNullableLazyValue(new Computable<V>() {
|
||||
@Override
|
||||
@@ -88,9 +88,9 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
});
|
||||
|
||||
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
|
||||
@Override
|
||||
public T get() {
|
||||
public T compute() {
|
||||
T _value = value;
|
||||
if (_value != null) {
|
||||
return _value;
|
||||
@@ -195,7 +195,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T get() {
|
||||
public T compute() {
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user