Add substitution concept into JetType
In most cases it's just a map { Parameter_i => Argument_i }
Will be used when loading Raw types from Java.
Also add ClassDescriptor.getMemberScope by substitution.
This commit is contained in:
+2
@@ -271,6 +271,8 @@ class LazyJavaTypeResolver(
|
|||||||
return (descriptor as ClassDescriptor).getMemberScope(getArguments())
|
return (descriptor as ClassDescriptor).getMemberScope(getArguments())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun computeCustomSubstitution(): TypeSubstitution? = null
|
||||||
|
|
||||||
private val nullable = c.storageManager.createLazyValue l@ {
|
private val nullable = c.storageManager.createLazyValue l@ {
|
||||||
when (attr.flexibility) {
|
when (attr.flexibility) {
|
||||||
FLEXIBLE_LOWER_BOUND -> return@l false
|
FLEXIBLE_LOWER_BOUND -> return@l false
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.ReadOnly;
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
import org.jetbrains.kotlin.types.TypeProjection;
|
import org.jetbrains.kotlin.types.TypeProjection;
|
||||||
|
import org.jetbrains.kotlin.types.TypeSubstitution;
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -31,6 +32,9 @@ public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor,
|
|||||||
@NotNull
|
@NotNull
|
||||||
JetScope getMemberScope(@NotNull List<? extends TypeProjection> typeArguments);
|
JetScope getMemberScope(@NotNull List<? extends TypeProjection> typeArguments);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
JetScope getMemberScope(@NotNull TypeSubstitution typeSubstitution);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
JetScope getUnsubstitutedMemberScope();
|
JetScope getUnsubstitutedMemberScope();
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.storage.StorageManager;
|
|||||||
import org.jetbrains.kotlin.types.*;
|
import org.jetbrains.kotlin.types.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||||
private final Name name;
|
private final Name name;
|
||||||
@@ -94,6 +93,15 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
|||||||
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JetScope getMemberScope(@NotNull TypeSubstitution typeSubstitution) {
|
||||||
|
if (typeSubstitution.isEmpty()) return getUnsubstitutedMemberScope();
|
||||||
|
|
||||||
|
TypeSubstitutor substitutor = TypeSubstitutor.create(typeSubstitution);
|
||||||
|
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||||
|
|||||||
+10
@@ -97,6 +97,16 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
|||||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JetScope getMemberScope(@NotNull TypeSubstitution typeSubstitution) {
|
||||||
|
JetScope memberScope = original.getMemberScope(typeSubstitution);
|
||||||
|
if (originalSubstitutor.isEmpty()) {
|
||||||
|
return memberScope;
|
||||||
|
}
|
||||||
|
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetScope getUnsubstitutedMemberScope() {
|
public JetScope getUnsubstitutedMemberScope() {
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ public abstract class AbstractLazyType(storageManager: StorageManager) : Abstrac
|
|||||||
|
|
||||||
protected abstract fun computeArguments(): List<TypeProjection>
|
protected abstract fun computeArguments(): List<TypeProjection>
|
||||||
|
|
||||||
|
override fun getSubstitution() = computeCustomSubstitution() ?: IndexedParametersSubstitution(constructor, getArguments())
|
||||||
|
|
||||||
|
protected open fun computeCustomSubstitution(): TypeSubstitution? = null
|
||||||
|
|
||||||
private val memberScope = storageManager.createLazyValue { computeMemberScope() }
|
private val memberScope = storageManager.createLazyValue { computeMemberScope() }
|
||||||
override fun getMemberScope() = memberScope()
|
override fun getMemberScope() = memberScope()
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ public abstract class DelegatingType implements JetType {
|
|||||||
return getDelegate().getArguments();
|
return getDelegate().getArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TypeSubstitution getSubstitution() {
|
||||||
|
return getDelegate().getSubstitution();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return getDelegate().isMarkedNullable();
|
return getDelegate().isMarkedNullable();
|
||||||
|
|||||||
@@ -314,6 +314,12 @@ public class ErrorUtils {
|
|||||||
public JetScope getMemberScope(@NotNull List<? extends TypeProjection> typeArguments) {
|
public JetScope getMemberScope(@NotNull List<? extends TypeProjection> typeArguments) {
|
||||||
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments);
|
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JetScope getMemberScope(@NotNull TypeSubstitution typeSubstitution) {
|
||||||
|
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeSubstitution);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -463,6 +469,12 @@ public class ErrorUtils {
|
|||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TypeSubstitution getSubstitution() {
|
||||||
|
return new IndexedParametersSubstitution(constructor, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public interface JetType extends Annotated {
|
|||||||
@ReadOnly
|
@ReadOnly
|
||||||
List<TypeProjection> getArguments();
|
List<TypeProjection> getArguments();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
TypeSubstitution getSubstitution();
|
||||||
|
|
||||||
boolean isMarkedNullable();
|
boolean isMarkedNullable();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.types;
|
package org.jetbrains.kotlin.types;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
|
|
||||||
@@ -29,12 +30,14 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
private final boolean nullable;
|
private final boolean nullable;
|
||||||
private final JetScope memberScope;
|
private final JetScope memberScope;
|
||||||
private final Annotations annotations;
|
private final Annotations annotations;
|
||||||
|
private final TypeSubstitution substitution;
|
||||||
|
|
||||||
public JetTypeImpl(
|
public JetTypeImpl(
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
@NotNull TypeConstructor constructor,
|
@NotNull TypeConstructor constructor,
|
||||||
boolean nullable,
|
boolean nullable,
|
||||||
@NotNull List<? extends TypeProjection> arguments,
|
@NotNull List<? extends TypeProjection> arguments,
|
||||||
|
@Nullable TypeSubstitution substitution,
|
||||||
@NotNull JetScope memberScope
|
@NotNull JetScope memberScope
|
||||||
) {
|
) {
|
||||||
this.annotations = annotations;
|
this.annotations = annotations;
|
||||||
@@ -47,6 +50,17 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
this.nullable = nullable;
|
this.nullable = nullable;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
this.memberScope = memberScope;
|
this.memberScope = memberScope;
|
||||||
|
this.substitution = substitution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JetTypeImpl(
|
||||||
|
@NotNull Annotations annotations,
|
||||||
|
@NotNull TypeConstructor constructor,
|
||||||
|
boolean nullable,
|
||||||
|
@NotNull List<? extends TypeProjection> arguments,
|
||||||
|
@NotNull JetScope memberScope
|
||||||
|
) {
|
||||||
|
this(annotations, constructor, nullable, arguments, null, memberScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -55,6 +69,15 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TypeSubstitution getSubstitution() {
|
||||||
|
if (substitution == null) {
|
||||||
|
return new IndexedParametersSubstitution(getConstructor(), getArguments());
|
||||||
|
}
|
||||||
|
return substitution;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TypeConstructor getConstructor() {
|
public TypeConstructor getConstructor() {
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ public class TypeUtils {
|
|||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TypeSubstitution getSubstitution() {
|
||||||
|
throw new IllegalStateException(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedNullable() {
|
public boolean isMarkedNullable() {
|
||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
@@ -785,6 +791,12 @@ public class TypeUtils {
|
|||||||
public Annotations getAnnotations() {
|
public Annotations getAnnotations() {
|
||||||
return delegate.getAnnotations();
|
return delegate.getAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TypeSubstitution getSubstitution() {
|
||||||
|
return delegate.getSubstitution();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NullableType extends AbstractTypeWithKnownNullability {
|
private static class NullableType extends AbstractTypeWithKnownNullability {
|
||||||
|
|||||||
-1
@@ -52,7 +52,6 @@ class DeserializedType(
|
|||||||
c.components.annotationAndConstantLoader.loadTypeAnnotations(typeProto, c.nameResolver)
|
c.components.annotationAndConstantLoader.loadTypeAnnotations(typeProto, c.nameResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun isMarkedNullable(): Boolean = typeProto.getNullable()
|
override fun isMarkedNullable(): Boolean = typeProto.getNullable()
|
||||||
|
|
||||||
private fun getTypeMemberScope(constructor: TypeConstructor, typeArguments: List<TypeProjection>): JetScope {
|
private fun getTypeMemberScope(constructor: TypeConstructor, typeArguments: List<TypeProjection>): JetScope {
|
||||||
|
|||||||
+2
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
|
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils.createErrorType
|
import org.jetbrains.kotlin.types.ErrorUtils.createErrorType
|
||||||
import org.jetbrains.kotlin.types.TypeProjection
|
import org.jetbrains.kotlin.types.TypeProjection
|
||||||
|
import org.jetbrains.kotlin.types.TypeSubstitution
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass
|
import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -81,4 +82,5 @@ private class MissingDependencyErrorClassDescriptor(
|
|||||||
override fun getUnsubstitutedMemberScope() = scope
|
override fun getUnsubstitutedMemberScope() = scope
|
||||||
|
|
||||||
override fun getMemberScope(typeArguments: List<TypeProjection?>) = scope
|
override fun getMemberScope(typeArguments: List<TypeProjection?>) = scope
|
||||||
|
override fun getMemberScope(typeSubstitution: TypeSubstitution) = scope
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user