Extract DeserializedType to top level and convert to Kotlin
This commit is contained in:
+73
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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.descriptors.serialization.context.DeserializationContext
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||||
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.jet.lang.types.*
|
||||||
|
|
||||||
|
class DeserializedType(
|
||||||
|
context: DeserializationContext,
|
||||||
|
private val typeProto: ProtoBuf.Type
|
||||||
|
) : AbstractJetType(), LazyType {
|
||||||
|
private val typeDeserializer = context.typeDeserializer
|
||||||
|
|
||||||
|
private val constructor = context.components.storageManager.createLazyValue {
|
||||||
|
typeDeserializer.typeConstructor(typeProto)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val arguments = typeDeserializer.typeArguments(typeProto.getArgumentList())
|
||||||
|
|
||||||
|
private val memberScope = context.components.storageManager.createLazyValue {
|
||||||
|
computeMemberScope()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getConstructor(): TypeConstructor = constructor()
|
||||||
|
|
||||||
|
override fun getArguments(): List<TypeProjection> = arguments
|
||||||
|
|
||||||
|
override fun isNullable(): Boolean = typeProto.getNullable()
|
||||||
|
|
||||||
|
private fun computeMemberScope(): JetScope =
|
||||||
|
if (isError()) {
|
||||||
|
ErrorUtils.createErrorScope(getConstructor().toString())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
getTypeMemberScope(getConstructor(), getArguments())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTypeMemberScope(constructor: TypeConstructor, typeArguments: List<TypeProjection>): JetScope {
|
||||||
|
val descriptor = constructor.getDeclarationDescriptor()
|
||||||
|
return when (descriptor) {
|
||||||
|
is TypeParameterDescriptor -> descriptor.getDefaultType().getMemberScope()
|
||||||
|
is ClassDescriptor -> descriptor.getMemberScope(typeArguments)
|
||||||
|
else -> throw IllegalStateException("Unsupported classifier: $descriptor")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMemberScope(): JetScope = memberScope()
|
||||||
|
|
||||||
|
override fun isError(): Boolean {
|
||||||
|
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||||
|
return descriptor != null && ErrorUtils.isError(descriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAnnotations(): Annotations = Annotations.EMPTY
|
||||||
|
}
|
||||||
-92
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.descriptors.serialization;
|
package org.jetbrains.jet.descriptors.serialization;
|
||||||
|
|
||||||
import kotlin.Function0;
|
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -24,13 +23,9 @@ import org.jetbrains.jet.descriptors.serialization.context.DeserializationCompon
|
|||||||
import org.jetbrains.jet.descriptors.serialization.context.DeserializationContext;
|
import org.jetbrains.jet.descriptors.serialization.context.DeserializationContext;
|
||||||
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeParameterDescriptor;
|
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
||||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
|
||||||
import org.jetbrains.jet.utils.UtilsPackage;
|
import org.jetbrains.jet.utils.UtilsPackage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -163,91 +158,4 @@ public class TypeDeserializer {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return debugName;
|
return debugName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DeserializedType extends AbstractJetType implements LazyType {
|
|
||||||
private final TypeDeserializer typeDeserializer;
|
|
||||||
private final ProtoBuf.Type typeProto;
|
|
||||||
private final NotNullLazyValue<TypeConstructor> constructor;
|
|
||||||
private final List<TypeProjection> arguments;
|
|
||||||
private final NotNullLazyValue<JetScope> memberScope;
|
|
||||||
|
|
||||||
public DeserializedType(@NotNull DeserializationContext context, @NotNull ProtoBuf.Type proto) {
|
|
||||||
this.typeDeserializer = context.getTypeDeserializer();
|
|
||||||
this.typeProto = proto;
|
|
||||||
this.arguments = typeDeserializer.typeArguments(proto.getArgumentList());
|
|
||||||
|
|
||||||
this.constructor = context.getComponents().getStorageManager().createLazyValue(new Function0<TypeConstructor>() {
|
|
||||||
@Override
|
|
||||||
public TypeConstructor invoke() {
|
|
||||||
return typeDeserializer.typeConstructor(typeProto);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.memberScope = context.getComponents().getStorageManager().createLazyValue(new Function0<JetScope>() {
|
|
||||||
@Override
|
|
||||||
public JetScope invoke() {
|
|
||||||
return computeMemberScope();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TypeConstructor getConstructor() {
|
|
||||||
return constructor.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TypeProjection> getArguments() {
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNullable() {
|
|
||||||
return typeProto.getNullable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private JetScope computeMemberScope() {
|
|
||||||
if (isError()) {
|
|
||||||
return ErrorUtils.createErrorScope(getConstructor().toString());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getTypeMemberScope(getConstructor(), getArguments());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JetScope getTypeMemberScope(@NotNull TypeConstructor constructor, @NotNull List<TypeProjection> typeArguments) {
|
|
||||||
ClassifierDescriptor descriptor = constructor.getDeclarationDescriptor();
|
|
||||||
if (descriptor instanceof TypeParameterDescriptor) {
|
|
||||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor;
|
|
||||||
return typeParameterDescriptor.getDefaultType().getMemberScope();
|
|
||||||
}
|
|
||||||
else if (descriptor instanceof ClassDescriptor) {
|
|
||||||
return ((ClassDescriptor) descriptor).getMemberScope(typeArguments);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Unsupported classifier: " + descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public JetScope getMemberScope() {
|
|
||||||
return memberScope.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isError() {
|
|
||||||
ClassifierDescriptor descriptor = getConstructor().getDeclarationDescriptor();
|
|
||||||
return descriptor != null && ErrorUtils.isError(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Annotations getAnnotations() {
|
|
||||||
return Annotations.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user