Fix double laziness of annotations introduced in 149a90d

This commit is contained in:
Alexander Udalov
2014-11-23 17:06:10 +03:00
parent 75851d44cc
commit 60662e5831
9 changed files with 60 additions and 73 deletions
@@ -164,12 +164,14 @@ public class MemberDeserializer(private val context: DeserializationContext) {
}
private fun getAnnotations(proto: Callable, flags: Int, kind: AnnotatedCallableKind): Annotations {
return if (Flags.HAS_ANNOTATIONS.get(flags))
if (!Flags.HAS_ANNOTATIONS.get(flags)) {
return Annotations.EMPTY
}
return DeserializedAnnotations(components.storageManager) {
components.annotationLoader.loadCallableAnnotations(
context.containingDeclaration.asClassOrPackage(), proto, context.nameResolver, kind
)
else
Annotations.EMPTY
}
}
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
@@ -194,10 +196,12 @@ public class MemberDeserializer(private val context: DeserializationContext) {
kind: AnnotatedCallableKind,
valueParameter: Callable.ValueParameter
): Annotations {
return if (Flags.HAS_ANNOTATIONS.get(valueParameter.getFlags()))
if (!Flags.HAS_ANNOTATIONS.get(valueParameter.getFlags())) {
return Annotations.EMPTY
}
return DeserializedAnnotations(components.storageManager) {
components.annotationLoader.loadValueParameterAnnotations(classOrPackage, callable, context.nameResolver, kind, valueParameter)
else
Annotations.EMPTY
}
}
private fun DeclarationDescriptor.asClassOrPackage(): ClassOrPackageFragmentDescriptor =
@@ -21,19 +21,21 @@ 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.Annotations;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import java.util.List;
public interface AnnotationLoader {
AnnotationLoader UNSUPPORTED = new AnnotationLoader() {
@NotNull
@Override
public Annotations loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) {
public List<AnnotationDescriptor> loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) {
return notSupported();
}
@NotNull
@Override
public Annotations loadCallableAnnotations(
public List<AnnotationDescriptor> loadCallableAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@@ -44,7 +46,7 @@ public interface AnnotationLoader {
@NotNull
@Override
public Annotations loadValueParameterAnnotations(
public List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@@ -55,16 +57,16 @@ public interface AnnotationLoader {
}
@NotNull
private Annotations notSupported() {
private List<AnnotationDescriptor> notSupported() {
throw new UnsupportedOperationException("Annotations are not supported");
}
};
@NotNull
Annotations loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto);
List<AnnotationDescriptor> loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto);
@NotNull
Annotations loadCallableAnnotations(
List<AnnotationDescriptor> loadCallableAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@@ -72,7 +74,7 @@ public interface AnnotationLoader {
);
@NotNull
Annotations loadValueParameterAnnotations(
List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrPackageFragmentDescriptor container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@@ -0,0 +1,42 @@
/*
* 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.utils.toReadOnlyList
import org.jetbrains.jet.storage.StorageManager
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.resolve.DescriptorUtils
class DeserializedAnnotations(
storageManager: StorageManager,
compute: () -> List<AnnotationDescriptor>
) : Annotations {
private val annotations = storageManager.createLazyValue { compute().toReadOnlyList() }
override fun isEmpty(): Boolean = annotations().isEmpty()
override fun findAnnotation(fqName: FqName): AnnotationDescriptor? = annotations().firstOrNull {
annotation ->
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
descriptor is ClassDescriptor && fqName.equalsTo(DescriptorUtils.getFqName(descriptor))
}
override fun iterator(): Iterator<AnnotationDescriptor> = annotations().iterator()
}
@@ -63,10 +63,16 @@ public class DeserializedClassDescriptor(
private val enumEntries = EnumEntryClassDescriptors()
private val containingDeclaration = outerContext.containingDeclaration
private val annotations = components.storageManager.createLazyValue { computeAnnotations() }
private val primaryConstructor = components.storageManager.createNullableLazyValue { computePrimaryConstructor() }
private val classObjectDescriptor = components.storageManager.createNullableLazyValue { computeClassObjectDescriptor() }
private val annotations = if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
Annotations.EMPTY
}
else DeserializedAnnotations(components.storageManager) {
components.annotationLoader.loadClassAnnotations(this, classProto)
}
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
override fun getTypeConstructor() = typeConstructor
@@ -79,14 +85,7 @@ public class DeserializedClassDescriptor(
override fun isInner() = isInner
private fun computeAnnotations(): Annotations {
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
return Annotations.EMPTY
}
return components.annotationLoader.loadClassAnnotations(this, classProto)
}
override fun getAnnotations(): Annotations = annotations()
override fun getAnnotations() = annotations
override fun getScopeForMemberLookup() = memberScope