Probably fixed EA-69004
This commit is contained in:
@@ -64,34 +64,36 @@ public object SuperClassNotInitialized : JetIntentionActionsFactory() {
|
|||||||
fixes.add(AddParenthesisFix(delegator, putCaretIntoParenthesis = constructors.singleOrNull()?.getValueParameters()?.isNotEmpty() ?: true))
|
fixes.add(AddParenthesisFix(delegator, putCaretIntoParenthesis = constructors.singleOrNull()?.getValueParameters()?.isNotEmpty() ?: true))
|
||||||
|
|
||||||
if (classOrObjectDeclaration is JetClass) {
|
if (classOrObjectDeclaration is JetClass) {
|
||||||
val superType = classDescriptor.getTypeConstructor().getSupertypes().first { it.getConstructor().getDeclarationDescriptor() == superClass }
|
val superType = classDescriptor.getTypeConstructor().getSupertypes().firstOrNull { it.getConstructor().getDeclarationDescriptor() == superClass }
|
||||||
val typeArgsMap = superClass.getTypeConstructor().getParameters().zip(superType.getArguments()).toMap()
|
if (superType != null) {
|
||||||
val substitutor = TypeUtils.makeSubstitutorForTypeParametersMap(typeArgsMap)
|
val typeArgsMap = superClass.getTypeConstructor().getParameters().zip(superType.getArguments()).toMap()
|
||||||
|
val substitutor = TypeUtils.makeSubstitutorForTypeParametersMap(typeArgsMap)
|
||||||
|
|
||||||
val substitutedConstructors = constructors
|
val substitutedConstructors = constructors
|
||||||
.filter { it.getValueParameters().isNotEmpty() }
|
.filter { it.getValueParameters().isNotEmpty() }
|
||||||
.map { it.substitute(substitutor) as ConstructorDescriptor }
|
.map { it.substitute(substitutor) as ConstructorDescriptor }
|
||||||
|
|
||||||
if (substitutedConstructors.isNotEmpty()) {
|
if (substitutedConstructors.isNotEmpty()) {
|
||||||
val parameterTypes: List<List<JetType>> = substitutedConstructors.map {
|
val parameterTypes: List<List<JetType>> = substitutedConstructors.map {
|
||||||
it.getValueParameters().map { it.getType() }
|
it.getValueParameters().map { it.getType() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size() == parameterTypes.size()
|
fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size() == parameterTypes.size()
|
||||||
|
|
||||||
val maxParams = parameterTypes.map { it.size() }.max()!!
|
val maxParams = parameterTypes.map { it.size() }.max()!!
|
||||||
val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) {
|
val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) {
|
||||||
maxParams
|
maxParams
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(DISPLAY_MAX_PARAMS..maxParams-1).firstOrNull(::canRenderOnlyFirstParameters) ?: maxParams
|
(DISPLAY_MAX_PARAMS..maxParams-1).firstOrNull(::canRenderOnlyFirstParameters) ?: maxParams
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((constructor, types) in substitutedConstructors.zip(parameterTypes)) {
|
for ((constructor, types) in substitutedConstructors.zip(parameterTypes)) {
|
||||||
val typesRendered = types.take(maxParamsToDisplay).map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }
|
val typesRendered = types.take(maxParamsToDisplay).map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }
|
||||||
val parameterString = typesRendered.joinToString(", ", "(", if (types.size() <= maxParamsToDisplay) ")" else ",...)")
|
val parameterString = typesRendered.joinToString(", ", "(", if (types.size() <= maxParamsToDisplay) ")" else ",...)")
|
||||||
val text = "Add constructor parameters from " + superClass.getName().asString() + parameterString
|
val text = "Add constructor parameters from " + superClass.getName().asString() + parameterString
|
||||||
fixes.add(AddParametersFix(delegator, classOrObjectDeclaration, constructor, text))
|
fixes.add(AddParametersFix(delegator, classOrObjectDeclaration, constructor, text))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user