New J2K: Add type parameters to methods declaration
This commit is contained in:
committed by
Ilya Kirillov
parent
4097ebe583
commit
14f5d866ee
@@ -290,7 +290,8 @@ class JavaToJKTreeBuilder(var symbolProvider: JKSymbolProvider) {
|
|||||||
},
|
},
|
||||||
JKNameIdentifierImpl(name),
|
JKNameIdentifierImpl(name),
|
||||||
parameterList.parameters.map { it.toJK() },
|
parameterList.parameters.map { it.toJK() },
|
||||||
body?.toJK() ?: JKBodyStub
|
body?.toJK() ?: JKBodyStub,
|
||||||
|
typeParameterList?.toJK() ?: JKTypeParameterListImpl()
|
||||||
).also {
|
).also {
|
||||||
it.psi = this
|
it.psi = this
|
||||||
symbolProvider.provideUniverseSymbol(this, it)
|
symbolProvider.provideUniverseSymbol(this, it)
|
||||||
|
|||||||
@@ -266,12 +266,15 @@ class NewCodeBuilder {
|
|||||||
override fun visitKtFunction(ktFunction: JKKtFunction) {
|
override fun visitKtFunction(ktFunction: JKKtFunction) {
|
||||||
printer.printIndent()
|
printer.printIndent()
|
||||||
ktFunction.modifierList.accept(this)
|
ktFunction.modifierList.accept(this)
|
||||||
printer.printWithNoIndent(" fun ", ktFunction.name.value, "(")
|
printer.printWithNoIndent(" fun ")
|
||||||
|
ktFunction.typeParameterList.accept(this)
|
||||||
|
printer.printWithNoIndent(ktFunction.name.value, "(")
|
||||||
renderList(ktFunction.parameters) {
|
renderList(ktFunction.parameters) {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
printer.printWithNoIndent(")", ": ")
|
printer.printWithNoIndent(")", ": ")
|
||||||
ktFunction.returnType.accept(this)
|
ktFunction.returnType.accept(this)
|
||||||
|
renderExtraTypeParametersUpperBounds(ktFunction.typeParameterList)
|
||||||
if (ktFunction.block !== JKBodyStub) {
|
if (ktFunction.block !== JKBodyStub) {
|
||||||
printer.block(multiline = ktFunction.block.statements.isNotEmpty()) {
|
printer.block(multiline = ktFunction.block.statements.isNotEmpty()) {
|
||||||
ktFunction.block.accept(this)
|
ktFunction.block.accept(this)
|
||||||
|
|||||||
+2
-1
@@ -36,7 +36,8 @@ class JavaMethodToKotlinFunctionConversion : TransformerBasedConversion() {
|
|||||||
it.name,
|
it.name,
|
||||||
it.parameters,
|
it.parameters,
|
||||||
it.block,
|
it.block,
|
||||||
it.modifierList
|
it.modifierList,
|
||||||
|
it.typeParameterList
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ class JKJavaFieldImpl(modifierList: JKModifierList, type: JKTypeElement, name: J
|
|||||||
}
|
}
|
||||||
|
|
||||||
class JKJavaMethodImpl(
|
class JKJavaMethodImpl(
|
||||||
modifierList: JKModifierList, returnType: JKTypeElement, name: JKNameIdentifier, parameters: List<JKParameter>, block: JKBlock
|
modifierList: JKModifierList,
|
||||||
|
returnType: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
parameters: List<JKParameter>,
|
||||||
|
block: JKBlock,
|
||||||
|
typeParameterList: JKTypeParameterList
|
||||||
) : JKJavaMethod, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
) : JKJavaMethod, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitJavaMethod(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitJavaMethod(this, data)
|
||||||
|
|
||||||
@@ -47,7 +52,7 @@ class JKJavaMethodImpl(
|
|||||||
override var name: JKNameIdentifier by child(name)
|
override var name: JKNameIdentifier by child(name)
|
||||||
override var parameters: List<JKParameter> by children(parameters)
|
override var parameters: List<JKParameter> by children(parameters)
|
||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
||||||
}
|
}
|
||||||
|
|
||||||
class JKJavaLiteralExpressionImpl(
|
class JKJavaLiteralExpressionImpl(
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ class JKKtFunctionImpl(
|
|||||||
name: JKNameIdentifier,
|
name: JKNameIdentifier,
|
||||||
parameters: List<JKParameter>,
|
parameters: List<JKParameter>,
|
||||||
block: JKBlock,
|
block: JKBlock,
|
||||||
modifierList: JKModifierList
|
modifierList: JKModifierList,
|
||||||
|
typeParameterList: JKTypeParameterList
|
||||||
) : JKBranchElementBase(), JKKtFunction {
|
) : JKBranchElementBase(), JKKtFunction {
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtFunction(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtFunction(this, data)
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ class JKKtFunctionImpl(
|
|||||||
override var parameters: List<JKParameter> by children(parameters)
|
override var parameters: List<JKParameter> by children(parameters)
|
||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
override var modifierList: JKModifierList by child(modifierList)
|
override var modifierList: JKModifierList by child(modifierList)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class JKKtQualifierImpl : JKQualifier, JKElementBase() {
|
sealed class JKKtQualifierImpl : JKQualifier, JKElementBase() {
|
||||||
@@ -166,7 +168,7 @@ class JKKtConstructorImpl(
|
|||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
override var modifierList: JKModifierList by child(modifierList)
|
override var modifierList: JKModifierList by child(modifierList)
|
||||||
override var delegationCall: JKExpression by child(delegationCall)
|
override var delegationCall: JKExpression by child(delegationCall)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterListImpl())
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtConstructor(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtConstructor(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +186,7 @@ class JKKtPrimaryConstructorImpl(
|
|||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
override var modifierList: JKModifierList by child(modifierList)
|
override var modifierList: JKModifierList by child(modifierList)
|
||||||
override var delegationCall: JKExpression by child(delegationCall)
|
override var delegationCall: JKExpression by child(delegationCall)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterListImpl())
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtPrimaryConstructor(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtPrimaryConstructor(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ interface JKInheritanceInfo : JKTreeElement, JKBranchElement {
|
|||||||
val inherit: List<JKTypeElement>
|
val inherit: List<JKTypeElement>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKMethod : JKDeclaration, JKModifierListOwner {
|
interface JKMethod : JKDeclaration, JKModifierListOwner, JKTypeParameterListOwner {
|
||||||
val name: JKNameIdentifier
|
val name: JKNameIdentifier
|
||||||
var parameters: List<JKParameter>
|
var parameters: List<JKParameter>
|
||||||
val returnType: JKTypeElement
|
val returnType: JKTypeElement
|
||||||
|
|||||||
Reference in New Issue
Block a user