Use StorageManager in AbstractClassDescriptor to create a lazy value
This commit is contained in:
+3
-2
@@ -81,7 +81,8 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
|||||||
@NotNull DescriptorFinder descriptorFinder,
|
@NotNull DescriptorFinder descriptorFinder,
|
||||||
@NotNull ClassData classData
|
@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();
|
NameResolver nameResolver = classData.getNameResolver();
|
||||||
this.classProto = classData.getClassProto();
|
this.classProto = classData.getClassProto();
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
|||||||
this.descriptorFinder = descriptorFinder;
|
this.descriptorFinder = descriptorFinder;
|
||||||
|
|
||||||
TypeDeserializer notNullTypeDeserializer = new TypeDeserializer(storageManager, null, nameResolver,
|
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,
|
DescriptorDeserializer outerDeserializer = DescriptorDeserializer.create(storageManager, notNullTypeDeserializer,
|
||||||
this, nameResolver, annotationResolver);
|
this, nameResolver, annotationResolver);
|
||||||
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount());
|
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount());
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
@NotNull Name name,
|
@NotNull Name name,
|
||||||
@NotNull JetClassLikeInfo classLikeInfo
|
@NotNull JetClassLikeInfo classLikeInfo
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, name);
|
super(resolveSession.getStorageManager(), containingDeclaration, name);
|
||||||
this.resolveSession = resolveSession;
|
this.resolveSession = resolveSession;
|
||||||
|
|
||||||
if (classLikeInfo.getCorrespondingClassOrObject() != null) {
|
if (classLikeInfo.getCorrespondingClassOrObject() != null) {
|
||||||
|
|||||||
+29
-7
@@ -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;
|
package org.jetbrains.jet.lang.descriptors.impl;
|
||||||
|
|
||||||
|
import jet.Function0;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||||
protected final Name name;
|
private final Name name;
|
||||||
protected volatile JetType defaultType;
|
protected final NotNullLazyValue<JetType> defaultType;
|
||||||
|
|
||||||
public AbstractClassDescriptor(@NotNull Name name) {
|
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.defaultType = storageManager.createLazyValue(new Function0<JetType>() {
|
||||||
|
@Override
|
||||||
|
public JetType invoke() {
|
||||||
|
return TypeUtils.makeUnsubstitutedType(AbstractClassDescriptor.this, getScopeForMemberLookup());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -66,10 +91,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetType getDefaultType() {
|
public JetType getDefaultType() {
|
||||||
if (defaultType == null) {
|
return defaultType.invoke();
|
||||||
defaultType = TypeUtils.makeUnsubstitutedType(this, getScopeForMemberLookup());
|
|
||||||
}
|
|
||||||
return defaultType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+7
-2
@@ -19,13 +19,18 @@ package org.jetbrains.jet.lang.descriptors.impl;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
|
|
||||||
public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
|
public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
|
||||||
|
|
||||||
private final DeclarationDescriptor containingDeclaration;
|
private final DeclarationDescriptor containingDeclaration;
|
||||||
|
|
||||||
protected ClassDescriptorBase(@NotNull DeclarationDescriptor containingDeclaration, @NotNull Name name) {
|
protected ClassDescriptorBase(
|
||||||
super(name);
|
@NotNull StorageManager storageManager,
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull Name name
|
||||||
|
) {
|
||||||
|
super(storageManager, name);
|
||||||
this.containingDeclaration = containingDeclaration;
|
this.containingDeclaration = containingDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
|||||||
|
|
||||||
constructors.add(constructorDescriptor);
|
constructors.add(constructorDescriptor);
|
||||||
|
|
||||||
if (defaultType != null) {
|
if (defaultType.isComputed()) {
|
||||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.types.TypeConstructor;
|
|||||||
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
|
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||||
|
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -65,7 +66,7 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
|||||||
@NotNull ClassKind kind,
|
@NotNull ClassKind kind,
|
||||||
boolean isInner
|
boolean isInner
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, name);
|
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.isInner = isInner;
|
this.isInner = isInner;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user