Make AnnotationLoader and ConstantLoader accept descriptor-independent data

Rewrite BaseDescriptorLoader to operate on data derived from proto
Intdoduce ProtoContainer to replace containing descriptor as input data
This commit is contained in:
Pavel V. Talanov
2014-11-26 18:36:34 +03:00
parent c73ac97ecf
commit e4d3a65124
8 changed files with 108 additions and 93 deletions
@@ -113,7 +113,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
if (Flags.HAS_CONSTANT.get(flags)) {
property.setCompileTimeInitializer(
c.storageManager.createNullableLazyValue {
val container = c.containingDeclaration.asClassOrPackage()
val container = c.containingDeclaration.asProtoContainer()
c.components.constantLoader.loadPropertyConstant(container, proto, c.nameResolver, AnnotatedCallableKind.PROPERTY)
}
)
@@ -166,13 +166,13 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
return DeserializedAnnotations(c.storageManager) {
c.components.annotationLoader.loadCallableAnnotations(
c.containingDeclaration.asClassOrPackage(), proto, c.nameResolver, kind
c.containingDeclaration.asProtoContainer(), proto, c.nameResolver, kind
)
}
}
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
val containerOfCallable = c.containingDeclaration.getContainingDeclaration().asClassOrPackage()
val containerOfCallable = c.containingDeclaration.getContainingDeclaration().asProtoContainer()
return callable.getValueParameterList().withIndices().map { val (i, proto) = it
ValueParameterDescriptorImpl(
@@ -188,7 +188,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
private fun getParameterAnnotations(
classOrPackage: ClassOrPackageFragmentDescriptor,
container: ProtoContainer,
callable: Callable,
kind: AnnotatedCallableKind,
valueParameter: Callable.ValueParameter
@@ -197,11 +197,13 @@ public class MemberDeserializer(private val c: DeserializationContext) {
return Annotations.EMPTY
}
return DeserializedAnnotations(c.storageManager) {
c.components.annotationLoader.loadValueParameterAnnotations(classOrPackage, callable, c.nameResolver, kind, valueParameter)
c.components.annotationLoader.loadValueParameterAnnotations(container, callable, c.nameResolver, kind, valueParameter)
}
}
private fun DeclarationDescriptor.asClassOrPackage(): ClassOrPackageFragmentDescriptor =
this as? ClassOrPackageFragmentDescriptor
?: error("Only members in classes or package fragments should be serialized: $this")
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer = when(this) {
is PackageFragmentDescriptor -> ProtoContainer(null, fqName)
is DeserializedClassDescriptor -> ProtoContainer(classProto, null)
else -> error("Only members in classes or package fragments should be serialized: $this")
}
}
@@ -19,8 +19,6 @@ package org.jetbrains.jet.descriptors.serialization.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.descriptors.serialization.NameResolver;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassOrPackageFragmentDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import java.util.List;
@@ -30,7 +28,6 @@ public interface AnnotationLoader {
@NotNull
@Override
public List<AnnotationDescriptor> loadClassAnnotations(
@NotNull ClassDescriptor descriptor,
@NotNull ProtoBuf.Class classProto,
@NotNull NameResolver nameResolver
) {
@@ -40,7 +37,7 @@ public interface AnnotationLoader {
@NotNull
@Override
public List<AnnotationDescriptor> loadCallableAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
@@ -51,7 +48,7 @@ public interface AnnotationLoader {
@NotNull
@Override
public List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind,
@@ -68,14 +65,13 @@ public interface AnnotationLoader {
@NotNull
List<AnnotationDescriptor> loadClassAnnotations(
@NotNull ClassDescriptor descriptor,
@NotNull ProtoBuf.Class classProto,
@NotNull NameResolver nameResolver
);
@NotNull
List<AnnotationDescriptor> loadCallableAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
@@ -83,7 +79,7 @@ public interface AnnotationLoader {
@NotNull
List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind,
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.descriptors.serialization.NameResolver;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.lang.descriptors.ClassOrPackageFragmentDescriptor;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
public interface ConstantLoader {
@@ -28,7 +27,7 @@ public interface ConstantLoader {
@Nullable
@Override
public CompileTimeConstant<?> loadPropertyConstant(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
@@ -39,7 +38,7 @@ public interface ConstantLoader {
@Nullable
CompileTimeConstant<?> loadPropertyConstant(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoContainer container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
@@ -40,7 +40,7 @@ import org.jetbrains.jet.descriptors.serialization.NameResolver
public class DeserializedClassDescriptor(
outerContext: DeserializationContext,
private val classProto: ProtoBuf.Class,
val classProto: ProtoBuf.Class,
nameResolver: NameResolver
) : ClassDescriptor, AbstractClassDescriptor(
outerContext.storageManager,
@@ -70,7 +70,7 @@ public class DeserializedClassDescriptor(
Annotations.EMPTY
}
else DeserializedAnnotations(c.storageManager) {
c.components.annotationLoader.loadClassAnnotations(this, classProto, c.nameResolver)
c.components.annotationLoader.loadClassAnnotations(classProto, c.nameResolver)
}
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
@@ -0,0 +1,26 @@
/*
* 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.descriptors
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
public data class ProtoContainer(val classProto: ProtoBuf.Class?, val packageFqName: FqName?) {
{
assert(classProto != null || packageFqName != null)
}
}