Drop some ClassDescriptor.getConstructors() usages
supposing that there is only primary constructor
This commit is contained in:
+2
-1
@@ -81,7 +81,8 @@ public abstract class DataClassMethodGenerator {
|
||||
private void generateComponentFunctionsForDataClasses() {
|
||||
if (!declaration.hasPrimaryConstructor()) return;
|
||||
|
||||
ConstructorDescriptor constructor = classDescriptor.getConstructors().iterator().next();
|
||||
ConstructorDescriptor constructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
assert constructor != null : "Data class should have primary constructor";
|
||||
|
||||
for (ValueParameterDescriptor parameter : constructor.getValueParameters()) {
|
||||
FunctionDescriptor function = bindingContext.get(BindingContext.DATA_CLASS_COMPONENT_FUNCTION, parameter);
|
||||
|
||||
@@ -744,7 +744,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.anew(thisDescriptorType);
|
||||
iv.dup();
|
||||
|
||||
ConstructorDescriptor constructor = getConstructorOfDataClass(descriptor);
|
||||
ConstructorDescriptor constructor = getPrimaryConstructorOfDataClass(descriptor);
|
||||
assert function.getValueParameters().size() == constructor.getValueParameters().size() :
|
||||
"Number of parameters of copy function and constructor are different. " +
|
||||
"Copy: " + function.getValueParameters().size() + ", " +
|
||||
@@ -791,10 +791,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private static ConstructorDescriptor getConstructorOfDataClass(@NotNull ClassDescriptor classDescriptor) {
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
assert constructors.size() == 1 : "Data class must have only one constructor: " + classDescriptor.getConstructors();
|
||||
return constructors.iterator().next();
|
||||
@NotNull
|
||||
private static ConstructorDescriptor getPrimaryConstructorOfDataClass(@NotNull ClassDescriptor classDescriptor) {
|
||||
ConstructorDescriptor constructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
assert constructor != null : "Data class must have primary constructor: " + classDescriptor;
|
||||
return constructor;
|
||||
}
|
||||
|
||||
private void generateEnumMethodsAndConstInitializers() {
|
||||
@@ -1071,10 +1072,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
if (ignoreIfTraitOrAnnotation()) return;
|
||||
|
||||
Collection<ConstructorDescriptor> constructors = descriptor.getConstructors();
|
||||
assert constructors.size() == 1 : "Unexpected number of constructors for class: " + descriptor + " " + constructors;
|
||||
|
||||
ConstructorDescriptor constructorDescriptor = KotlinPackage.single(constructors);
|
||||
ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||
if (constructorDescriptor == null) return;
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
|
||||
is JetClass -> {
|
||||
val jetClass: JetClass = declaringElement
|
||||
val classDescriptor = getDescriptor(jetClass, resolveSession) as ClassDescriptor
|
||||
addCorrespondingParameterDescriptor(classDescriptor.getConstructors().first(), parameter)
|
||||
addCorrespondingParameterDescriptor(classDescriptor.getUnsubstitutedPrimaryConstructor(), parameter)
|
||||
}
|
||||
else -> super.visitParameter(parameter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user