Converted to Kotlin
This commit is contained in:
+244
-362
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,516 +14,398 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.descriptors.serialization.descriptors;
|
package org.jetbrains.jet.descriptors.serialization.descriptors
|
||||||
|
|
||||||
import kotlin.Function0;
|
import org.jetbrains.jet.descriptors.serialization.ClassData
|
||||||
import kotlin.Function1;
|
import org.jetbrains.jet.descriptors.serialization.Flags
|
||||||
import kotlin.KotlinPackage;
|
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.jet.descriptors.serialization.context.*
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.jet.lang.descriptors.*
|
||||||
import org.jetbrains.jet.descriptors.serialization.ClassData;
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.jet.descriptors.serialization.Flags;
|
import org.jetbrains.jet.lang.descriptors.impl.AbstractClassDescriptor
|
||||||
import org.jetbrains.jet.descriptors.serialization.NameResolver;
|
import org.jetbrains.jet.lang.descriptors.impl.EnumEntrySyntheticClassDescriptor
|
||||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
import org.jetbrains.jet.lang.resolve.DescriptorFactory
|
||||||
import org.jetbrains.jet.descriptors.serialization.context.ContextPackage;
|
import org.jetbrains.jet.lang.resolve.OverridingUtil
|
||||||
import org.jetbrains.jet.descriptors.serialization.context.DeserializationContext;
|
import org.jetbrains.jet.lang.resolve.name.ClassId
|
||||||
import org.jetbrains.jet.descriptors.serialization.context.DeserializationContextWithTypes;
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
import org.jetbrains.jet.descriptors.serialization.context.DeserializationGlobalContext;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.resolve.scopes.StaticScopeForKotlinClass
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.AbstractClassDescriptor;
|
import org.jetbrains.jet.lang.types.ErrorUtils
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.EnumEntrySyntheticClassDescriptor;
|
import org.jetbrains.jet.lang.types.TypeConstructor
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
import org.jetbrains.jet.storage.MemoizedFunctionToNullable
|
||||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
import org.jetbrains.jet.storage.NotNullLazyValue
|
||||||
import org.jetbrains.jet.lang.resolve.name.ClassId;
|
import org.jetbrains.jet.storage.NullableLazyValue
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.StaticScopeForKotlinClass;
|
|
||||||
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor;
|
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
|
||||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
|
||||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
|
||||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
|
||||||
import org.jetbrains.jet.storage.NullableLazyValue;
|
|
||||||
import org.jetbrains.jet.storage.StorageManager;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*
|
||||||
|
|
||||||
import static org.jetbrains.jet.descriptors.serialization.SerializationPackage.*;
|
import org.jetbrains.jet.descriptors.serialization
|
||||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
import org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.classKind
|
||||||
|
|
||||||
public class DeserializedClassDescriptor extends AbstractClassDescriptor implements ClassDescriptor {
|
|
||||||
|
|
||||||
private final ClassId classId;
|
public fun DeserializedClassDescriptor(globalContext: DeserializationGlobalContext, classData: ClassData): DeserializedClassDescriptor {
|
||||||
private final ProtoBuf.Class classProto;
|
return DeserializedClassDescriptor(globalContext.withNameResolver(classData.getNameResolver()), classData.getClassProto())
|
||||||
private final DeserializedMemberScope memberScope;
|
}
|
||||||
|
|
||||||
private final NullableLazyValue<ConstructorDescriptor> primaryConstructor;
|
public class DeserializedClassDescriptor(outerContext: DeserializationContext, private val classProto: ProtoBuf.Class) : AbstractClassDescriptor(outerContext.storageManager, outerContext.nameResolver.getClassId(classProto.getFqName()).getRelativeClassName().shortName()), ClassDescriptor {
|
||||||
|
|
||||||
private final NotNullLazyValue<Annotations> annotations;
|
private val classId: ClassId
|
||||||
|
private val memberScope: DeserializedMemberScope
|
||||||
|
|
||||||
private final NullableLazyValue<ClassDescriptor> classObjectDescriptor;
|
private val primaryConstructor: NullableLazyValue<ConstructorDescriptor>
|
||||||
private final NestedClassDescriptors nestedClasses;
|
|
||||||
private final JetScope staticScope = new StaticScopeForKotlinClass(this);
|
|
||||||
|
|
||||||
private final NotNullLazyValue<DeclarationDescriptor> containingDeclaration;
|
private val annotations: NotNullLazyValue<Annotations>
|
||||||
private final DeserializedClassTypeConstructor typeConstructor;
|
|
||||||
private final Modality modality;
|
|
||||||
private final Visibility visibility;
|
|
||||||
private final ClassKind kind;
|
|
||||||
private final boolean isInner;
|
|
||||||
private final DeserializationContextWithTypes context;
|
|
||||||
|
|
||||||
public DeserializedClassDescriptor(@NotNull DeserializationGlobalContext globalContext, @NotNull ClassData classData) {
|
private val classObjectDescriptor: NullableLazyValue<ClassDescriptor>
|
||||||
this(globalContext.withNameResolver(classData.getNameResolver()), classData.getClassProto());
|
private val nestedClasses: NestedClassDescriptors
|
||||||
|
private val staticScope = StaticScopeForKotlinClass(this)
|
||||||
|
|
||||||
|
private val containingDeclaration: NotNullLazyValue<DeclarationDescriptor>
|
||||||
|
private val typeConstructor: DeserializedClassTypeConstructor
|
||||||
|
private val modality: Modality
|
||||||
|
private val visibility: Visibility
|
||||||
|
private val kind: ClassKind
|
||||||
|
private val isInner: Boolean
|
||||||
|
private val context: DeserializationContextWithTypes
|
||||||
|
|
||||||
|
{
|
||||||
|
this.classId = outerContext.nameResolver.getClassId(classProto.getFqName())
|
||||||
|
|
||||||
|
val typeParameters = ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount())
|
||||||
|
this.context = outerContext.withTypes(this).childContext(this, classProto.getTypeParameterList(), typeParameters)
|
||||||
|
|
||||||
|
this.containingDeclaration = outerContext.storageManager.createLazyValue<DeclarationDescriptor>(object : Function0<DeclarationDescriptor> {
|
||||||
|
override fun invoke(): DeclarationDescriptor {
|
||||||
|
return computeContainingDeclaration()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.typeConstructor = DeserializedClassTypeConstructor(typeParameters)
|
||||||
|
this.memberScope = DeserializedClassMemberScope()
|
||||||
|
|
||||||
|
val flags = classProto.getFlags()
|
||||||
|
this.modality = serialization.modality(Flags.MODALITY.get(flags))
|
||||||
|
this.visibility = serialization.visibility(Flags.VISIBILITY.get(flags))
|
||||||
|
this.kind = classKind(Flags.CLASS_KIND.get(flags))
|
||||||
|
this.isInner = Flags.INNER.get(flags)
|
||||||
|
|
||||||
|
this.annotations = context.storageManager.createLazyValue<Annotations> { computeAnnotations() }
|
||||||
|
|
||||||
|
this.primaryConstructor = context.storageManager.createNullableLazyValue<ConstructorDescriptor> { computePrimaryConstructor() }
|
||||||
|
|
||||||
|
this.classObjectDescriptor = context.storageManager.createNullableLazyValue<ClassDescriptor> { computeClassObjectDescriptor() }
|
||||||
|
|
||||||
|
this.nestedClasses = NestedClassDescriptors()
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeserializedClassDescriptor(@NotNull DeserializationContext outerContext, @NotNull ProtoBuf.Class classProto) {
|
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||||
super(outerContext.getStorageManager(),
|
return containingDeclaration.invoke()
|
||||||
outerContext.getNameResolver().getClassId(classProto.getFqName()).getRelativeClassName().shortName());
|
|
||||||
this.classProto = classProto;
|
|
||||||
this.classId = outerContext.getNameResolver().getClassId(classProto.getFqName());
|
|
||||||
|
|
||||||
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount());
|
|
||||||
this.context = outerContext.withTypes(this).childContext(this, classProto.getTypeParameterList(), typeParameters);
|
|
||||||
|
|
||||||
this.containingDeclaration = outerContext.getStorageManager().createLazyValue(new Function0<DeclarationDescriptor>() {
|
|
||||||
@Override
|
|
||||||
public DeclarationDescriptor invoke() {
|
|
||||||
return computeContainingDeclaration();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.typeConstructor = new DeserializedClassTypeConstructor(typeParameters);
|
|
||||||
this.memberScope = new DeserializedClassMemberScope();
|
|
||||||
|
|
||||||
int flags = classProto.getFlags();
|
|
||||||
this.modality = modality(Flags.MODALITY.get(flags));
|
|
||||||
this.visibility = visibility(Flags.VISIBILITY.get(flags));
|
|
||||||
this.kind = classKind(Flags.CLASS_KIND.get(flags));
|
|
||||||
this.isInner = Flags.INNER.get(flags);
|
|
||||||
|
|
||||||
this.annotations = context.getStorageManager().createLazyValue(new Function0<Annotations>() {
|
|
||||||
@Override
|
|
||||||
public Annotations invoke() {
|
|
||||||
return computeAnnotations();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.primaryConstructor = context.getStorageManager().createNullableLazyValue(new Function0<ConstructorDescriptor>() {
|
|
||||||
@Override
|
|
||||||
public ConstructorDescriptor invoke() {
|
|
||||||
return computePrimaryConstructor();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.classObjectDescriptor = context.getStorageManager().createNullableLazyValue(new Function0<ClassDescriptor>() {
|
|
||||||
@Override
|
|
||||||
public ClassDescriptor invoke() {
|
|
||||||
return computeClassObjectDescriptor();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.nestedClasses = new NestedClassDescriptors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun computeContainingDeclaration(): DeclarationDescriptor {
|
||||||
@Override
|
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
|
||||||
return containingDeclaration.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private DeclarationDescriptor computeContainingDeclaration() {
|
|
||||||
if (classId.isTopLevelClass()) {
|
if (classId.isTopLevelClass()) {
|
||||||
List<PackageFragmentDescriptor> fragments =
|
val fragments = context.packageFragmentProvider.getPackageFragments(classId.getPackageFqName())
|
||||||
context.getPackageFragmentProvider().getPackageFragments(classId.getPackageFqName());
|
assert(fragments.size() == 1) { "there should be exactly one package: " + fragments + ", class id is " + classId }
|
||||||
assert fragments.size() == 1 : "there should be exactly one package: " + fragments + ", class id is " + classId;
|
return fragments.iterator().next()
|
||||||
return fragments.iterator().next();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClassDescriptor result = ContextPackage.deserializeClass(context, classId.getOuterClassId());
|
return context.deserializeClass(classId.getOuterClassId()) ?: ErrorUtils.getErrorModule()
|
||||||
return result != null ? result : ErrorUtils.getErrorModule();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getTypeConstructor(): TypeConstructor {
|
||||||
@Override
|
return typeConstructor
|
||||||
public TypeConstructor getTypeConstructor() {
|
|
||||||
return typeConstructor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
override fun getKind(): ClassKind {
|
||||||
@Override
|
return kind
|
||||||
public ClassKind getKind() {
|
|
||||||
return kind;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getModality(): Modality {
|
||||||
@Override
|
return modality
|
||||||
public Modality getModality() {
|
|
||||||
return modality;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getVisibility(): Visibility {
|
||||||
@Override
|
return visibility
|
||||||
public Visibility getVisibility() {
|
|
||||||
return visibility;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun isInner(): Boolean {
|
||||||
public boolean isInner() {
|
return isInner
|
||||||
return isInner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Annotations computeAnnotations() {
|
private fun computeAnnotations(): Annotations {
|
||||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
|
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
|
||||||
return Annotations.EMPTY;
|
return Annotations.EMPTY
|
||||||
}
|
}
|
||||||
return context.getAnnotationLoader().loadClassAnnotations(this, classProto);
|
return context.annotationLoader.loadClassAnnotations(this, classProto)
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getAnnotations(): Annotations {
|
||||||
@Override
|
return annotations.invoke()
|
||||||
public Annotations getAnnotations() {
|
|
||||||
return annotations.invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getScopeForMemberLookup(): JetScope {
|
||||||
@Override
|
return memberScope
|
||||||
protected JetScope getScopeForMemberLookup() {
|
|
||||||
return memberScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getStaticScope(): JetScope {
|
||||||
@Override
|
return staticScope
|
||||||
public JetScope getStaticScope() {
|
|
||||||
return staticScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun computePrimaryConstructor(): ConstructorDescriptor? {
|
||||||
private ConstructorDescriptor computePrimaryConstructor() {
|
if (!classProto.hasPrimaryConstructor()) return null
|
||||||
if (!classProto.hasPrimaryConstructor()) return null;
|
|
||||||
|
|
||||||
ProtoBuf.Class.PrimaryConstructor constructorProto = classProto.getPrimaryConstructor();
|
val constructorProto = classProto.getPrimaryConstructor()
|
||||||
if (!constructorProto.hasData()) {
|
if (!constructorProto.hasData()) {
|
||||||
ConstructorDescriptorImpl descriptor = DescriptorFactory.createPrimaryConstructorForObject(this, SourceElement.NO_SOURCE);
|
val descriptor = DescriptorFactory.createPrimaryConstructorForObject(this, SourceElement.NO_SOURCE)
|
||||||
descriptor.setReturnType(getDefaultType());
|
descriptor.setReturnType(getDefaultType())
|
||||||
return descriptor;
|
return descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ConstructorDescriptor) context.getDeserializer().loadCallable(constructorProto.getData());
|
return context.deserializer.loadCallable(constructorProto.getData()) as ConstructorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? {
|
||||||
@Override
|
return primaryConstructor.invoke()
|
||||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
|
||||||
return primaryConstructor.invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getConstructors(): Collection<ConstructorDescriptor> {
|
||||||
@Override
|
val constructor = getUnsubstitutedPrimaryConstructor()
|
||||||
public Collection<ConstructorDescriptor> getConstructors() {
|
|
||||||
ConstructorDescriptor constructor = getUnsubstitutedPrimaryConstructor();
|
|
||||||
if (constructor == null) {
|
if (constructor == null) {
|
||||||
return Collections.emptyList();
|
return listOf()
|
||||||
}
|
}
|
||||||
// TODO: other constructors
|
// TODO: other constructors
|
||||||
return Collections.singletonList(constructor);
|
return listOf(constructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun computeClassObjectDescriptor(): ClassDescriptor? {
|
||||||
private ClassDescriptor computeClassObjectDescriptor() {
|
|
||||||
if (!classProto.hasClassObject()) {
|
if (!classProto.hasClassObject()) {
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getKind() == ClassKind.OBJECT) {
|
if (getKind() == ClassKind.OBJECT) {
|
||||||
ProtoBuf.Class.ClassObject classObjectProto = classProto.getClassObject();
|
val classObjectProto = classProto.getClassObject()
|
||||||
if (!classObjectProto.hasData()) {
|
if (!classObjectProto.hasData()) {
|
||||||
throw new IllegalStateException("Object should have a serialized class object: " + classId);
|
throw IllegalStateException("Object should have a serialized class object: " + classId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DeserializedClassDescriptor(context, classObjectProto.getData());
|
return DeserializedClassDescriptor(context, classObjectProto.getData())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContextPackage.deserializeClass(context, classId.createNestedClassId(getClassObjectName(getName())));
|
return context.deserializeClass(classId.createNestedClassId(getClassObjectName(getName())))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun getClassObjectDescriptor(): ClassDescriptor? {
|
||||||
@Override
|
return classObjectDescriptor.invoke()
|
||||||
public ClassDescriptor getClassObjectDescriptor() {
|
|
||||||
return classObjectDescriptor.invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<JetType> computeSuperTypes() {
|
private fun computeSuperTypes(): Collection<JetType> {
|
||||||
List<JetType> supertypes = new ArrayList<JetType>(classProto.getSupertypeCount());
|
val supertypes = ArrayList<JetType>(classProto.getSupertypeCount())
|
||||||
for (ProtoBuf.Type supertype : classProto.getSupertypeList()) {
|
for (supertype in classProto.getSupertypeList()) {
|
||||||
supertypes.add(context.getTypeDeserializer().type(supertype));
|
supertypes.add(context.typeDeserializer.`type`(supertype))
|
||||||
}
|
}
|
||||||
return supertypes;
|
return supertypes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun toString(): String {
|
||||||
public String toString() {
|
|
||||||
// not using descriptor render to preserve laziness
|
// not using descriptor render to preserve laziness
|
||||||
return "deserialized class " + getName().toString();
|
return "deserialized class " + getName().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getSource(): SourceElement {
|
||||||
@Override
|
return SourceElement.NO_SOURCE
|
||||||
public SourceElement getSource() {
|
|
||||||
return SourceElement.NO_SOURCE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DeserializedClassTypeConstructor extends AbstractClassTypeConstructor {
|
private inner class DeserializedClassTypeConstructor(private val parameters: List<TypeParameterDescriptor>) : AbstractClassTypeConstructor() {
|
||||||
private final Collection<JetType> supertypes = computeSuperTypes();
|
private val supertypes = computeSuperTypes()
|
||||||
private final List<TypeParameterDescriptor> parameters;
|
|
||||||
|
|
||||||
public DeserializedClassTypeConstructor(@NotNull List<TypeParameterDescriptor> typeParameters) {
|
override fun getParameters(): List<TypeParameterDescriptor> {
|
||||||
parameters = typeParameters;
|
return parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getSupertypes(): Collection<JetType> {
|
||||||
@Override
|
|
||||||
public List<TypeParameterDescriptor> getParameters() {
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JetType> getSupertypes() {
|
|
||||||
// We cannot have error supertypes because subclasses inherit error functions from them
|
// We cannot have error supertypes because subclasses inherit error functions from them
|
||||||
// Filtering right away means copying the list every time, so we check for the rare condition first, and only then filter
|
// Filtering right away means copying the list every time, so we check for the rare condition first, and only then filter
|
||||||
for (JetType supertype : supertypes) {
|
for (supertype in supertypes) {
|
||||||
if (supertype.isError()) {
|
if (supertype.isError()) {
|
||||||
return KotlinPackage.filter(supertypes, new Function1<JetType, Boolean>() {
|
return supertypes.filter { !it.isError() }
|
||||||
@Override
|
|
||||||
public Boolean invoke(JetType type) {
|
|
||||||
return !type.isError();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return supertypes;
|
return supertypes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun isFinal(): Boolean {
|
||||||
public boolean isFinal() {
|
return !getModality().isOverridable()
|
||||||
return !getModality().isOverridable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun isDenotable(): Boolean {
|
||||||
public boolean isDenotable() {
|
return true
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun getDeclarationDescriptor(): ClassifierDescriptor? {
|
||||||
@Override
|
return this@DeserializedClassDescriptor
|
||||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
|
||||||
return DeserializedClassDescriptor.this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getAnnotations(): Annotations {
|
||||||
@Override
|
return Annotations.EMPTY // TODO
|
||||||
public Annotations getAnnotations() {
|
|
||||||
return Annotations.EMPTY; // TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun toString(): String {
|
||||||
public String toString() {
|
return getName().toString()
|
||||||
return getName().toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DeserializedClassMemberScope extends DeserializedMemberScope {
|
private inner class DeserializedClassMemberScope : DeserializedMemberScope(context, this@DeserializedClassDescriptor.classProto.getMemberList()) {
|
||||||
private final DeserializedClassDescriptor classDescriptor;
|
private val classDescriptor: DeserializedClassDescriptor
|
||||||
|
|
||||||
public DeserializedClassMemberScope() {
|
{
|
||||||
super(context, DeserializedClassDescriptor.this.classProto.getMemberList());
|
this.classDescriptor = this@DeserializedClassDescriptor
|
||||||
this.classDescriptor = DeserializedClassDescriptor.this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
|
||||||
protected void computeNonDeclaredFunctions(
|
val fromSupertypes = ArrayList<FunctionDescriptor>()
|
||||||
@NotNull Name name, @NotNull Collection<FunctionDescriptor> functions
|
for (supertype in classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
) {
|
fromSupertypes.addAll(supertype.getMemberScope().getFunctions(name))
|
||||||
Collection<FunctionDescriptor> fromSupertypes = new ArrayList<FunctionDescriptor>();
|
|
||||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
|
||||||
fromSupertypes.addAll(supertype.getMemberScope().getFunctions(name));
|
|
||||||
}
|
}
|
||||||
generateFakeOverrides(name, fromSupertypes, functions);
|
generateFakeOverrides(name, fromSupertypes, functions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun computeNonDeclaredProperties(name: Name, property: MutableCollection<PropertyDescriptor>) {
|
||||||
protected void computeNonDeclaredProperties(
|
val fromSupertypes = ArrayList<PropertyDescriptor>()
|
||||||
@NotNull Name name, @NotNull Collection<PropertyDescriptor> property
|
for (supertype in classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
) {
|
[suppress("UNCHECKED_CAST")]
|
||||||
Collection<PropertyDescriptor> fromSupertypes = new ArrayList<PropertyDescriptor>();
|
fromSupertypes.addAll(supertype.getMemberScope().getProperties(name) as Collection<PropertyDescriptor>)
|
||||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
|
||||||
//noinspection unchecked
|
|
||||||
fromSupertypes.addAll((Collection) supertype.getMemberScope().getProperties(name));
|
|
||||||
}
|
}
|
||||||
generateFakeOverrides(name, fromSupertypes, property);
|
generateFakeOverrides(name, fromSupertypes, property)
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableMemberDescriptor> void generateFakeOverrides(
|
private fun <D : CallableMemberDescriptor> generateFakeOverrides(name: Name, fromSupertypes: Collection<D>, result: MutableCollection<D>) {
|
||||||
@NotNull Name name,
|
val fromCurrent = ArrayList<CallableMemberDescriptor>(result)
|
||||||
@NotNull Collection<D> fromSupertypes,
|
OverridingUtil.generateOverridesInFunctionGroup(name, fromSupertypes, fromCurrent, classDescriptor, object : OverridingUtil.DescriptorSink {
|
||||||
@NotNull final Collection<D> result
|
override fun addToScope(fakeOverride: CallableMemberDescriptor) {
|
||||||
) {
|
// TODO: report "cannot infer visibility"
|
||||||
List<CallableMemberDescriptor> fromCurrent = new ArrayList<CallableMemberDescriptor>(result);
|
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null)
|
||||||
OverridingUtil.generateOverridesInFunctionGroup(
|
[suppress("UNCHECKED_CAST")]
|
||||||
name,
|
result.add(fakeOverride as D)
|
||||||
fromSupertypes,
|
}
|
||||||
fromCurrent,
|
|
||||||
classDescriptor,
|
|
||||||
new OverridingUtil.DescriptorSink() {
|
|
||||||
@Override
|
|
||||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
|
||||||
// TODO: report "cannot infer visibility"
|
|
||||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
|
||||||
//noinspection unchecked
|
|
||||||
result.add((D) fakeOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) {
|
||||||
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
|
// TODO report conflicts
|
||||||
// TODO report conflicts
|
}
|
||||||
}
|
})
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>) {
|
||||||
protected void addNonDeclaredDescriptors(@NotNull Collection<DeclarationDescriptor> result) {
|
for (supertype in classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
for (descriptor in supertype.getMemberScope().getAllDescriptors()) {
|
||||||
for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) {
|
if (descriptor is FunctionDescriptor) {
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
result.addAll(getFunctions(descriptor.getName()))
|
||||||
result.addAll(getFunctions(descriptor.getName()));
|
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof PropertyDescriptor) {
|
else if (descriptor is PropertyDescriptor) {
|
||||||
result.addAll(getProperties(descriptor.getName()));
|
result.addAll(getProperties(descriptor.getName()))
|
||||||
}
|
}
|
||||||
// Nothing else is inherited
|
// Nothing else is inherited
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun getImplicitReceiver(): ReceiverParameterDescriptor? {
|
||||||
@Override
|
return classDescriptor.getThisAsReceiverParameter()
|
||||||
protected ReceiverParameterDescriptor getImplicitReceiver() {
|
|
||||||
return classDescriptor.getThisAsReceiverParameter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun getClassDescriptor(name: Name): ClassifierDescriptor? {
|
||||||
@Override
|
return classDescriptor.nestedClasses.findClass.invoke(name)
|
||||||
protected ClassifierDescriptor getClassDescriptor(@NotNull Name name) {
|
|
||||||
return classDescriptor.nestedClasses.findClass.invoke(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun addAllClassDescriptors(result: MutableCollection<DeclarationDescriptor>) {
|
||||||
protected void addAllClassDescriptors(@NotNull Collection<DeclarationDescriptor> result) {
|
result.addAll(classDescriptor.nestedClasses.getAllDescriptors())
|
||||||
result.addAll(classDescriptor.nestedClasses.getAllDescriptors());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NestedClassDescriptors {
|
private inner class NestedClassDescriptors {
|
||||||
private final Set<Name> nestedClassNames;
|
private val nestedClassNames: Set<Name>
|
||||||
private final MemoizedFunctionToNullable<Name, ClassDescriptor> findClass;
|
val findClass: MemoizedFunctionToNullable<Name, ClassDescriptor>
|
||||||
private final Set<Name> enumEntryNames;
|
private val enumEntryNames: Set<Name>
|
||||||
|
|
||||||
public NestedClassDescriptors() {
|
{
|
||||||
this.nestedClassNames = nestedClassNames();
|
this.nestedClassNames = nestedClassNames()
|
||||||
this.enumEntryNames = enumEntryNames();
|
this.enumEntryNames = enumEntryNames()
|
||||||
|
|
||||||
final StorageManager storageManager = context.getStorageManager();
|
val storageManager = context.storageManager
|
||||||
final NotNullLazyValue<Collection<Name>> enumMemberNames = storageManager.createLazyValue(new Function0<Collection<Name>>() {
|
val enumMemberNames = storageManager.createLazyValue<Collection<Name>>(object : Function0<Collection<Name>> {
|
||||||
@Override
|
override fun invoke(): Collection<Name> {
|
||||||
public Collection<Name> invoke() {
|
return computeEnumMemberNames()
|
||||||
return computeEnumMemberNames();
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
this.findClass = storageManager.createMemoizedFunctionWithNullableValues(new Function1<Name, ClassDescriptor>() {
|
this.findClass = storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
|
||||||
@Override
|
if (enumEntryNames.contains(name)) {
|
||||||
public ClassDescriptor invoke(Name name) {
|
EnumEntrySyntheticClassDescriptor.create(storageManager, this@DeserializedClassDescriptor, name, enumMemberNames, SourceElement.NO_SOURCE)
|
||||||
if (enumEntryNames.contains(name)) {
|
}
|
||||||
return EnumEntrySyntheticClassDescriptor
|
else if (nestedClassNames.contains(name)) {
|
||||||
.create(storageManager, DeserializedClassDescriptor.this, name, enumMemberNames, SourceElement.NO_SOURCE);
|
context.deserializeClass(classId.createNestedClassId(name))
|
||||||
}
|
}
|
||||||
if (nestedClassNames.contains(name)) {
|
else {
|
||||||
return ContextPackage.deserializeClass(context, classId.createNestedClassId(name));
|
null
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Set<Name> nestedClassNames() {
|
|
||||||
Set<Name> result = new HashSet<Name>();
|
|
||||||
NameResolver nameResolver = context.getNameResolver();
|
|
||||||
for (Integer index : classProto.getNestedClassNameList()) {
|
|
||||||
result.add(nameResolver.getName(index));
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun nestedClassNames(): Set<Name> {
|
||||||
private Set<Name> enumEntryNames() {
|
val result = HashSet<Name>()
|
||||||
|
val nameResolver = context.nameResolver
|
||||||
|
for (index in classProto.getNestedClassNameList()) {
|
||||||
|
result.add(nameResolver.getName(index!!))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun enumEntryNames(): Set<Name> {
|
||||||
if (getKind() != ClassKind.ENUM_CLASS) {
|
if (getKind() != ClassKind.ENUM_CLASS) {
|
||||||
return Collections.emptySet();
|
return setOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Name> result = new HashSet<Name>();
|
val result = HashSet<Name>()
|
||||||
NameResolver nameResolver = context.getNameResolver();
|
val nameResolver = context.nameResolver
|
||||||
for (Integer index : classProto.getEnumEntryList()) {
|
for (index in classProto.getEnumEntryList()) {
|
||||||
result.add(nameResolver.getName(index));
|
result.add(nameResolver.getName(index!!))
|
||||||
}
|
}
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun computeEnumMemberNames(): Collection<Name> {
|
||||||
private Collection<Name> computeEnumMemberNames() {
|
val result = HashSet<Name>()
|
||||||
Collection<Name> result = new HashSet<Name>();
|
|
||||||
|
|
||||||
for (JetType supertype : getTypeConstructor().getSupertypes()) {
|
for (supertype in getTypeConstructor().getSupertypes()) {
|
||||||
for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) {
|
for (descriptor in supertype.getMemberScope().getAllDescriptors()) {
|
||||||
if (descriptor instanceof SimpleFunctionDescriptor || descriptor instanceof PropertyDescriptor) {
|
if (descriptor is SimpleFunctionDescriptor || descriptor is PropertyDescriptor) {
|
||||||
result.add(descriptor.getName());
|
result.add(descriptor.getName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final NameResolver nameResolver = context.getNameResolver();
|
val nameResolver = context.nameResolver
|
||||||
return KotlinPackage.mapTo(classProto.getMemberList(), result, new Function1<ProtoBuf.Callable, Name>() {
|
return classProto.getMemberList().mapTo(result) { nameResolver.getName(it.getName()) }
|
||||||
@Override
|
|
||||||
public Name invoke(@NotNull ProtoBuf.Callable callable) {
|
|
||||||
return nameResolver.getName(callable.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public fun getAllDescriptors(): Collection<ClassDescriptor> {
|
||||||
public Collection<ClassDescriptor> getAllDescriptors() {
|
val result = ArrayList<ClassDescriptor>(nestedClassNames.size() + enumEntryNames.size())
|
||||||
Collection<ClassDescriptor> result = new ArrayList<ClassDescriptor>(nestedClassNames.size() + enumEntryNames.size());
|
for (name in nestedClassNames) {
|
||||||
for (Name name : nestedClassNames) {
|
val descriptor = findClass.invoke(name)
|
||||||
ClassDescriptor descriptor = findClass.invoke(name);
|
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
result.add(descriptor);
|
result.add(descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Name name : enumEntryNames) {
|
for (name in enumEntryNames) {
|
||||||
ClassDescriptor descriptor = findClass.invoke(name);
|
val descriptor = findClass.invoke(name)
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
result.add(descriptor);
|
result.add(descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user