Use StorageManager in AbstractClassDescriptor to create a lazy value

This commit is contained in:
Alexander Udalov
2013-11-20 19:41:05 +04:00
parent ff29684e3d
commit 97f2d568a3
6 changed files with 43 additions and 14 deletions
@@ -81,7 +81,8 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
@NotNull DescriptorFinder descriptorFinder,
@NotNull ClassData classData
) {
super(classData.getNameResolver().getClassId(classData.getClassProto().getFqName()).getRelativeClassName().shortName());
super(storageManager,
classData.getNameResolver().getClassId(classData.getClassProto().getFqName()).getRelativeClassName().shortName());
NameResolver nameResolver = classData.getNameResolver();
this.classProto = classData.getClassProto();
@@ -89,7 +90,7 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
this.descriptorFinder = descriptorFinder;
TypeDeserializer notNullTypeDeserializer = new TypeDeserializer(storageManager, null, nameResolver,
descriptorFinder, "Deserializer for class " + name, NONE);
descriptorFinder, "Deserializer for class " + getName(), NONE);
DescriptorDeserializer outerDeserializer = DescriptorDeserializer.create(storageManager, notNullTypeDeserializer,
this, nameResolver, annotationResolver);
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount());
@@ -94,7 +94,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
@NotNull Name name,
@NotNull JetClassLikeInfo classLikeInfo
) {
super(containingDeclaration, name);
super(resolveSession.getStorageManager(), containingDeclaration, name);
this.resolveSession = resolveSession;
if (classLikeInfo.getCorrespondingClassOrObject() != null) {
@@ -1,5 +1,22 @@
/*
* 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.descriptors.impl;
import jet.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
@@ -9,16 +26,24 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.storage.NotNullLazyValue;
import org.jetbrains.jet.storage.StorageManager;
import java.util.List;
import java.util.Map;
public abstract class AbstractClassDescriptor implements ClassDescriptor {
protected final Name name;
protected volatile JetType defaultType;
private final Name name;
protected final NotNullLazyValue<JetType> defaultType;
public AbstractClassDescriptor(@NotNull Name name) {
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name) {
this.name = name;
this.defaultType = storageManager.createLazyValue(new Function0<JetType>() {
@Override
public JetType invoke() {
return TypeUtils.makeUnsubstitutedType(AbstractClassDescriptor.this, getScopeForMemberLookup());
}
});
}
@NotNull
@@ -66,10 +91,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
@NotNull
@Override
public JetType getDefaultType() {
if (defaultType == null) {
defaultType = TypeUtils.makeUnsubstitutedType(this, getScopeForMemberLookup());
}
return defaultType;
return defaultType.invoke();
}
@Override
@@ -19,13 +19,18 @@ package org.jetbrains.jet.lang.descriptors.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.storage.StorageManager;
public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
private final DeclarationDescriptor containingDeclaration;
protected ClassDescriptorBase(@NotNull DeclarationDescriptor containingDeclaration, @NotNull Name name) {
super(name);
protected ClassDescriptorBase(
@NotNull StorageManager storageManager,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Name name
) {
super(storageManager, name);
this.containingDeclaration = containingDeclaration;
}
@@ -69,7 +69,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
constructors.add(constructorDescriptor);
if (defaultType != null) {
if (defaultType.isComputed()) {
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
}
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.storage.LockBasedStorageManager;
import java.util.ArrayList;
import java.util.Collection;
@@ -65,7 +66,7 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
@NotNull ClassKind kind,
boolean isInner
) {
super(containingDeclaration, name);
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
this.kind = kind;
this.isInner = isInner;
}