Move caching of deserialized classes to new component ClassDeserializer
Drop AbstractDescriptorFinder
This commit is contained in:
-60
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.descriptors.serialization;
|
||||
|
||||
import kotlin.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.descriptors.serialization.context.DeserializationGlobalContext;
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
public abstract class AbstractDescriptorFinder implements DescriptorFinder {
|
||||
private final MemoizedFunctionToNullable<ClassId, ClassDescriptor> findClass;
|
||||
|
||||
public AbstractDescriptorFinder(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
@NotNull AnnotationLoader annotationLoader,
|
||||
@NotNull ConstantLoader constantLoader,
|
||||
@NotNull PackageFragmentProvider packageFragmentProvider
|
||||
) {
|
||||
final DeserializationGlobalContext deserializationGlobalContext =
|
||||
new DeserializationGlobalContext(storageManager, moduleDescriptor, this, annotationLoader, constantLoader,
|
||||
packageFragmentProvider);
|
||||
this.findClass = storageManager.createMemoizedFunctionWithNullableValues(new Function1<ClassId, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(ClassId classId) {
|
||||
ClassData classData = getClassData(classId);
|
||||
return classData == null ? null : new DeserializedClassDescriptor(deserializationGlobalContext, classData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassDescriptor findClass(@NotNull ClassId classId) {
|
||||
return findClass.invoke(classId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract ClassData getClassData(@NotNull ClassId classId);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.descriptors.serialization
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
|
||||
public class ClassDeserializer(val storageManager: StorageManager, val descriptorFinder: DescriptorFinder) {
|
||||
private val classes = storageManager.createMemoizedFunctionWithNullableValues {
|
||||
(classId: ClassId) ->
|
||||
descriptorFinder.findClass(classId)
|
||||
}
|
||||
|
||||
public fun deserializeClass(classId: ClassId): ClassDescriptor? = classes(classId)
|
||||
}
|
||||
+10
-6
@@ -31,6 +31,7 @@ import org.jetbrains.jet.descriptors.serialization.descriptors.ConstantLoader
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.descriptors.serialization.ClassId
|
||||
import org.jetbrains.jet.descriptors.serialization.ClassDeserializer
|
||||
|
||||
public open class DeserializationGlobalContext(
|
||||
public val storageManager: StorageManager,
|
||||
@@ -38,11 +39,12 @@ public open class DeserializationGlobalContext(
|
||||
public val descriptorFinder: DescriptorFinder,
|
||||
public val annotationLoader: AnnotationLoader,
|
||||
public val constantLoader: ConstantLoader,
|
||||
public val packageFragmentProvider: PackageFragmentProvider
|
||||
public val packageFragmentProvider: PackageFragmentProvider,
|
||||
public val classDeserializer: ClassDeserializer = ClassDeserializer(storageManager, descriptorFinder)
|
||||
) {
|
||||
public fun withNameResolver(nameResolver: NameResolver): DeserializationContext {
|
||||
return DeserializationContext(storageManager, moduleDescriptor, descriptorFinder, annotationLoader,
|
||||
constantLoader, packageFragmentProvider, nameResolver)
|
||||
constantLoader, packageFragmentProvider, classDeserializer, nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +56,10 @@ public open class DeserializationContext(
|
||||
annotationLoader: AnnotationLoader,
|
||||
constantLoader: ConstantLoader,
|
||||
packageFragmentProvider: PackageFragmentProvider,
|
||||
classDeserializer: ClassDeserializer,
|
||||
public val nameResolver: NameResolver
|
||||
) : DeserializationGlobalContext(storageManager, moduleDescriptor, descriptorFinder, annotationLoader,
|
||||
constantLoader, packageFragmentProvider) {
|
||||
constantLoader, packageFragmentProvider, classDeserializer) {
|
||||
fun withTypes(containingDeclaration: DeclarationDescriptor): DeserializationContextWithTypes {
|
||||
val typeDeserializer = TypeDeserializer(this, null, "Deserializer for ${containingDeclaration.getName()}",
|
||||
TypeDeserializer.TypeParameterResolver.NONE)
|
||||
@@ -65,7 +68,7 @@ public open class DeserializationContext(
|
||||
|
||||
fun withTypes(containingDeclaration: DeclarationDescriptor, typeDeserializer: TypeDeserializer): DeserializationContextWithTypes {
|
||||
return DeserializationContextWithTypes(storageManager, moduleDescriptor, descriptorFinder, annotationLoader,
|
||||
constantLoader, packageFragmentProvider,
|
||||
constantLoader, packageFragmentProvider, classDeserializer,
|
||||
nameResolver, containingDeclaration, typeDeserializer)
|
||||
}
|
||||
|
||||
@@ -79,11 +82,12 @@ class DeserializationContextWithTypes(
|
||||
annotationLoader: AnnotationLoader,
|
||||
constantLoader: ConstantLoader,
|
||||
packageFragmentProvider: PackageFragmentProvider,
|
||||
classDeserializer: ClassDeserializer,
|
||||
nameResolver: NameResolver,
|
||||
val containingDeclaration: DeclarationDescriptor,
|
||||
val typeDeserializer: TypeDeserializer
|
||||
) : DeserializationContext(storageManager, moduleDescriptor, descriptorFinder, annotationLoader,
|
||||
constantLoader, packageFragmentProvider, nameResolver) {
|
||||
constantLoader, packageFragmentProvider, classDeserializer, nameResolver) {
|
||||
val deserializer: MemberDeserializer = MemberDeserializer(this)
|
||||
|
||||
public fun childContext(
|
||||
@@ -106,5 +110,5 @@ class DeserializationContextWithTypes(
|
||||
}
|
||||
|
||||
fun DeserializationGlobalContext.deserializeClass(classId: ClassId): ClassDescriptor? {
|
||||
return descriptorFinder.findClass(classId)
|
||||
return classDeserializer.deserializeClass(classId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user