New J2K: Fix supertypes constructor calls
This commit is contained in:
committed by
Ilya Kirillov
parent
5cdc01621d
commit
d1c1aeed0b
@@ -204,16 +204,16 @@ class NewCodeBuilder {
|
|||||||
if (isInInterface) {
|
if (isInInterface) {
|
||||||
renderList(extendTypes) { renderType(it) }
|
renderList(extendTypes) { renderType(it) }
|
||||||
} else {
|
} else {
|
||||||
extendTypes.singleOrNull()?.also {
|
extendTypes.singleOrNull()?.also { superType ->
|
||||||
renderType(it)
|
renderType(superType)
|
||||||
|
val primaryConstructor = parentClass.primaryConstructor()
|
||||||
val delegationCall =
|
val delegationCall =
|
||||||
parentClass
|
primaryConstructor
|
||||||
.primaryConstructor()
|
|
||||||
?.delegationCall
|
?.delegationCall
|
||||||
?.let { it as? JKDelegationConstructorCall }
|
?.let { it as? JKDelegationConstructorCall }
|
||||||
if (delegationCall != null) {
|
if (delegationCall != null) {
|
||||||
printer.par { delegationCall.arguments.accept(this) }
|
printer.par { delegationCall.arguments.accept(this) }
|
||||||
} else {
|
} else if (!superType.isInterface()) {
|
||||||
printer.printWithNoIndent("()")
|
printer.printWithNoIndent("()")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -608,7 +608,7 @@ class NewCodeBuilder {
|
|||||||
}
|
}
|
||||||
printer.printWithNoIndent(javaNewExpression.classSymbol.displayName().escapedAsQualifiedName())
|
printer.printWithNoIndent(javaNewExpression.classSymbol.displayName().escapedAsQualifiedName())
|
||||||
javaNewExpression.typeArgumentList.accept(this)
|
javaNewExpression.typeArgumentList.accept(this)
|
||||||
if (javaNewExpression.constructorIsPresent() || !javaNewExpression.isAnonymousClass()) {
|
if (!javaNewExpression.classSymbol.isInterface()) {
|
||||||
printer.par(ROUND) {
|
printer.par(ROUND) {
|
||||||
javaNewExpression.arguments.accept(this)
|
javaNewExpression.arguments.accept(this)
|
||||||
}
|
}
|
||||||
@@ -709,6 +709,8 @@ class NewCodeBuilder {
|
|||||||
printer.printWithNoIndent(" constructor ")
|
printer.printWithNoIndent(" constructor ")
|
||||||
if (ktPrimaryConstructor.parameters.isNotEmpty()) {
|
if (ktPrimaryConstructor.parameters.isNotEmpty()) {
|
||||||
renderParameterList(ktPrimaryConstructor.parameters)
|
renderParameterList(ktPrimaryConstructor.parameters)
|
||||||
|
} else {
|
||||||
|
printer.print("()")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,17 +44,6 @@ interface JKJavaNewExpression : JKExpression, JKTypeArgumentListOwner, PsiOwner
|
|||||||
fun JKJavaNewExpression.isAnonymousClass() =
|
fun JKJavaNewExpression.isAnonymousClass() =
|
||||||
classBody !is JKEmptyClassBody
|
classBody !is JKEmptyClassBody
|
||||||
|
|
||||||
fun JKJavaNewExpression.constructorIsPresent(): Boolean {
|
|
||||||
if (arguments.expressions.isNotEmpty()) return true
|
|
||||||
val symbol = classSymbol
|
|
||||||
return when (symbol) {
|
|
||||||
is JKMultiverseClassSymbol -> symbol.target.constructors.isNotEmpty()
|
|
||||||
is JKMultiverseKtClassSymbol -> symbol.target.constructor != null
|
|
||||||
is JKUniverseClassSymbol -> symbol.target.classBody.declarations.any { it is JKKtConstructor }
|
|
||||||
is JKUnresolvedClassSymbol -> true //TODO ???
|
|
||||||
else -> TODO(symbol::class.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaDefaultNewExpression : JKExpression {
|
interface JKJavaDefaultNewExpression : JKExpression {
|
||||||
val classSymbol: JKClassSymbol
|
val classSymbol: JKClassSymbol
|
||||||
|
|||||||
@@ -296,4 +296,17 @@ fun JKType.arrayInnerType(): JKType? =
|
|||||||
|
|
||||||
val namesOfPrimitiveTypes by lazy {
|
val namesOfPrimitiveTypes by lazy {
|
||||||
KotlinBuiltIns.FQ_NAMES.primitiveTypeShortNames.map { it.identifier.decapitalize() }
|
KotlinBuiltIns.FQ_NAMES.primitiveTypeShortNames.map { it.identifier.decapitalize() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun JKClassSymbol.isInterface(): Boolean {
|
||||||
|
val target = target
|
||||||
|
return when (target) {
|
||||||
|
is PsiClass -> target.isInterface
|
||||||
|
is KtClass -> target.isInterface()
|
||||||
|
is JKClass -> target.classKind == JKClass.ClassKind.INTERFACE
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun JKType.isInterface(): Boolean =
|
||||||
|
(this as? JKClassType)?.classReference?.isInterface() ?: false
|
||||||
Reference in New Issue
Block a user