Introduce ClassDescriptor.declaredTypeParameters
Should be a subset of type constructor's parameters
This commit is contained in:
@@ -302,7 +302,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private JvmClassSignature signature() {
|
||||
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
|
||||
|
||||
typeMapper.writeFormalTypeParameters(descriptor.getTypeConstructor().getParameters(), sw);
|
||||
typeMapper.writeFormalTypeParameters(descriptor.getDeclaredTypeParameters(), sw);
|
||||
|
||||
sw.writeSuperclass();
|
||||
if (superClassType == null) {
|
||||
|
||||
@@ -143,6 +143,12 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
this.typeParameters = new ArrayList<TypeParameterDescriptor>(typeParameters);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public void createTypeConstructor() {
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = TypeConstructorImpl.createForClass(
|
||||
|
||||
+2
-2
@@ -195,7 +195,7 @@ public class TypeParameterBoundIsNotArrayChecker : DeclarationChecker {
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val typeParameters = (descriptor as? CallableDescriptor)?.typeParameters
|
||||
?: (descriptor as? ClassDescriptor)?.typeConstructor?.parameters
|
||||
?: (descriptor as? ClassDescriptor)?.declaredTypeParameters
|
||||
?: return
|
||||
|
||||
for (typeParameter in typeParameters) {
|
||||
@@ -222,7 +222,7 @@ public class ReifiedTypeParameterAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
if (descriptor is ClassDescriptor) {
|
||||
checkTypeParameterDescriptorsAreNotReified(descriptor.getTypeConstructor().getParameters(), diagnosticHolder)
|
||||
checkTypeParameterDescriptorsAreNotReified(descriptor.declaredTypeParameters, diagnosticHolder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
|
||||
//TODO: non-inner classes
|
||||
for (parent in ownerClass.parentsWithSelf) {
|
||||
if (parent !is ClassDescriptor) break
|
||||
sourceTypeParams += parent.typeConstructor.parameters
|
||||
sourceTypeParams += parent.declaredTypeParameters
|
||||
}
|
||||
//TODO: duplicated parameter names
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ public class DeclarationsChecker {
|
||||
EffectiveVisibility classVisibility = EffectiveVisibility.Companion.forClass(classDescriptor);
|
||||
List<KtTypeParameter> typeParameterList = klass.getTypeParameters();
|
||||
int i = 0;
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getDeclaredTypeParameters()) {
|
||||
if (i >= typeParameterList.size()) return;
|
||||
for (KotlinType upperBound : typeParameterDescriptor.getUpperBounds()) {
|
||||
EffectiveVisibility upperBoundVisibility = EffectiveVisibility.Companion.forType(upperBound);
|
||||
|
||||
@@ -96,7 +96,7 @@ class VarianceChecker(private val trace: BindingTrace) {
|
||||
val containingClass = descriptor.getContainingDeclaration()
|
||||
if (containingClass !is ClassDescriptor) return true
|
||||
|
||||
return containingClass.getTypeConstructor().getParameters().all { it.getVariance() == INVARIANT }
|
||||
return containingClass.typeConstructor.parameters.all { it.getVariance() == INVARIANT }
|
||||
}
|
||||
|
||||
private fun recordPrivateToThis(descriptor: CallableMemberDescriptor) {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class ClassResolutionScopesSupport(
|
||||
) {
|
||||
private fun scopeWithGenerics(parent: LexicalScope, debugName: String): LexicalScopeImpl {
|
||||
return LexicalScopeImpl(parent, classDescriptor, false, null, debugName) {
|
||||
classDescriptor.typeConstructor.parameters.forEach { addClassifierDescriptor(it) }
|
||||
classDescriptor.declaredTypeParameters.forEach { addClassifierDescriptor(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-16
@@ -101,9 +101,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final boolean isCompanionObject;
|
||||
|
||||
private final ClassResolutionScopesSupport resolutionScopesSupport;
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull final LazyClassContext c,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull JetClassLikeInfo classLikeInfo
|
||||
@@ -239,6 +240,30 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return getOuterScope();
|
||||
}
|
||||
}, classLikeInfo.getPrimaryConstructorParameters());
|
||||
|
||||
this.parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
JetClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// NOTE: Called from constructor!
|
||||
@@ -489,6 +514,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
getVisibility();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
|
||||
return parameters.invoke();
|
||||
}
|
||||
|
||||
private static class Supertypes {
|
||||
@Mutable
|
||||
public final Collection<KotlinType> trueSupertypes;
|
||||
@@ -545,21 +576,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
JetClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
return LazyClassDescriptor.this.getDeclaredTypeParameters();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -104,7 +104,7 @@ public class DescriptorSerializer {
|
||||
new MutableTypeTable(),
|
||||
false
|
||||
);
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeConstructor().getParameters()) {
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getDeclaredTypeParameters()) {
|
||||
serializer.typeParameters.intern(typeParameter);
|
||||
}
|
||||
return serializer;
|
||||
@@ -137,7 +137,7 @@ public class DescriptorSerializer {
|
||||
|
||||
builder.setFqName(getClassId(classDescriptor));
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getDeclaredTypeParameters()) {
|
||||
builder.addTypeParameter(typeParameter(typeParameterDescriptor));
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ public class DescriptorValidator {
|
||||
public Boolean visitClassDescriptor(
|
||||
ClassDescriptor descriptor, DiagnosticCollector collector
|
||||
) {
|
||||
validateTypeParameters(collector, descriptor.getTypeConstructor().getParameters());
|
||||
validateTypeParameters(collector, descriptor.getDeclaredTypeParameters());
|
||||
|
||||
Collection<KotlinType> supertypes = descriptor.getTypeConstructor().getSupertypes();
|
||||
if (supertypes.isEmpty() && descriptor.getKind() != ClassKind.INTERFACE
|
||||
|
||||
Reference in New Issue
Block a user