Fix double laziness of annotations introduced in 149a90d
This commit is contained in:
+1
-1
@@ -103,7 +103,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.globalSearchScope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(lockBasedStorageManager, getModule());
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(lockBasedStorageManager, getModule(), descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(getModule(), descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader(descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.deserializationComponentsForJava = new DeserializationComponentsForJava(lockBasedStorageManager, getModule(), javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.scriptBodyResolver = new ScriptBodyResolver();
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(storageManager, module);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(storageManager, module, descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(module, descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader(descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.deserializationComponentsForJava = new DeserializationComponentsForJava(storageManager, module, javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, getModuleDescriptor());
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(storageManager, getModuleDescriptor());
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(storageManager, getModuleDescriptor(), descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader(getModuleDescriptor(), descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader(descriptorLoadersStorage, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.deserializationComponentsForJava = new DeserializationComponentsForJava(storageManager, getModuleDescriptor(), javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
this.additionalCheckerProvider = org.jetbrains.jet.lang.resolve.kotlin.JavaDeclarationCheckerProvider.INSTANCE$;
|
||||
|
||||
+24
-40
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import kotlin.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.descriptors.serialization.JavaProtoBuf;
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationLoader;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
|
||||
@@ -37,7 +35,6 @@ import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.AnnotationArra
|
||||
import org.jetbrains.jet.lang.resolve.name.ClassId;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -45,11 +42,9 @@ import static org.jetbrains.jet.lang.resolve.kotlin.DescriptorLoadersStorage.Mem
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.javaClassIdToKotlinClassId;
|
||||
|
||||
public class AnnotationDescriptorLoader extends BaseDescriptorLoader implements AnnotationLoader {
|
||||
private final StorageManager storageManager;
|
||||
private final ModuleDescriptor module;
|
||||
|
||||
public AnnotationDescriptorLoader(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull ModuleDescriptor module,
|
||||
@NotNull DescriptorLoadersStorage storage,
|
||||
@NotNull KotlinClassFinder kotlinClassFinder,
|
||||
@@ -57,40 +52,34 @@ public class AnnotationDescriptorLoader extends BaseDescriptorLoader implements
|
||||
) {
|
||||
super(kotlinClassFinder, errorReporter, storage);
|
||||
this.module = module;
|
||||
this.storageManager = storageManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) {
|
||||
final KotlinJvmBinaryClass kotlinClass = findKotlinClassByDescriptor(descriptor);
|
||||
public List<AnnotationDescriptor> loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) {
|
||||
KotlinJvmBinaryClass kotlinClass = findKotlinClassByDescriptor(descriptor);
|
||||
if (kotlinClass == null) {
|
||||
// This means that the resource we're constructing the descriptor from is no longer present: KotlinClassFinder had found the
|
||||
// class earlier, but it can't now
|
||||
errorReporter.reportLoadingError("Kotlin class for loading class annotations is not found: " + descriptor, null);
|
||||
return Annotations.EMPTY;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return new DeserializedAnnotations(storageManager, new Function0<List<AnnotationDescriptor>>() {
|
||||
final List<AnnotationDescriptor> result = new ArrayList<AnnotationDescriptor>(1);
|
||||
|
||||
kotlinClass.loadClassAnnotations(new KotlinJvmBinaryClass.AnnotationVisitor() {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<AnnotationDescriptor> invoke() {
|
||||
final List<AnnotationDescriptor> result = new ArrayList<AnnotationDescriptor>(1);
|
||||
public KotlinJvmBinaryClass.AnnotationArgumentVisitor visitAnnotation(@NotNull ClassId classId) {
|
||||
return resolveAnnotation(classId, result, module);
|
||||
}
|
||||
|
||||
kotlinClass.loadClassAnnotations(new KotlinJvmBinaryClass.AnnotationVisitor() {
|
||||
@Nullable
|
||||
@Override
|
||||
public KotlinJvmBinaryClass.AnnotationArgumentVisitor visitAnnotation(@NotNull ClassId classId) {
|
||||
return resolveAnnotation(classId, result, module);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -189,44 +178,39 @@ public class AnnotationDescriptorLoader extends BaseDescriptorLoader implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations loadCallableAnnotations(
|
||||
public List<AnnotationDescriptor> loadCallableAnnotations(
|
||||
@NotNull ClassOrPackageFragmentDescriptor container,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull NameResolver nameResolver,
|
||||
@NotNull AnnotatedCallableKind kind
|
||||
) {
|
||||
MemberSignature signature = getCallableSignature(proto, nameResolver, kind);
|
||||
if (signature == null) return Annotations.EMPTY;
|
||||
if (signature == null) return Collections.emptyList();
|
||||
|
||||
return findClassAndLoadMemberAnnotations(container, proto, nameResolver, kind, signature);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Annotations findClassAndLoadMemberAnnotations(
|
||||
private List<AnnotationDescriptor> findClassAndLoadMemberAnnotations(
|
||||
@NotNull ClassOrPackageFragmentDescriptor container,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull NameResolver nameResolver,
|
||||
@NotNull AnnotatedCallableKind kind,
|
||||
@NotNull final MemberSignature signature
|
||||
@NotNull MemberSignature signature
|
||||
) {
|
||||
final KotlinJvmBinaryClass kotlinClass = findClassWithAnnotationsAndInitializers(container, proto, nameResolver, kind);
|
||||
KotlinJvmBinaryClass kotlinClass = findClassWithAnnotationsAndInitializers(container, proto, nameResolver, kind);
|
||||
if (kotlinClass == null) {
|
||||
errorReporter.reportLoadingError("Kotlin class for loading member annotations is not found: " + container, null);
|
||||
return Annotations.EMPTY;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return new DeserializedAnnotations(storageManager, new Function0<List<AnnotationDescriptor>>() {
|
||||
@Override
|
||||
public List<AnnotationDescriptor> invoke() {
|
||||
List<AnnotationDescriptor> descriptors = storage.getStorageForClass(kotlinClass).getMemberAnnotations().get(signature);
|
||||
return descriptors == null ? Collections.<AnnotationDescriptor>emptyList() : descriptors;
|
||||
}
|
||||
});
|
||||
List<AnnotationDescriptor> descriptors = storage.getStorageForClass(kotlinClass).getMemberAnnotations().get(signature);
|
||||
return descriptors == null ? Collections.<AnnotationDescriptor>emptyList() : descriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations loadValueParameterAnnotations(
|
||||
public List<AnnotationDescriptor> loadValueParameterAnnotations(
|
||||
@NotNull ClassOrPackageFragmentDescriptor container,
|
||||
@NotNull ProtoBuf.Callable callable,
|
||||
@NotNull NameResolver nameResolver,
|
||||
@@ -242,6 +226,6 @@ public class AnnotationDescriptorLoader extends BaseDescriptorLoader implements
|
||||
}
|
||||
}
|
||||
|
||||
return Annotations.EMPTY;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -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 =
|
||||
|
||||
+10
-8
@@ -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,
|
||||
|
||||
+4
-4
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin
|
||||
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.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.utils.toReadOnlyList
|
||||
|
||||
class DeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
+8
-9
@@ -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
|
||||
|
||||
|
||||
+1
-3
@@ -94,9 +94,7 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
|
||||
private val loadersStorage = DescriptorLoadersStorage(storageManager, moduleDescriptor)
|
||||
|
||||
private val annotationLoader = AnnotationDescriptorLoader(
|
||||
storageManager, moduleDescriptor, loadersStorage, localClassFinder, LOGGING_REPORTER
|
||||
)
|
||||
private val annotationLoader = AnnotationDescriptorLoader(moduleDescriptor, loadersStorage, localClassFinder, LOGGING_REPORTER)
|
||||
|
||||
private val constantLoader = ConstantDescriptorLoader(loadersStorage, localClassFinder, LOGGING_REPORTER)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user