New J2K: Add rendering for type-parameters
This commit is contained in:
committed by
Ilya Kirillov
parent
b12a91c111
commit
c87cd20a9d
@@ -220,7 +220,7 @@ class JavaToJKTreeBuilder(var symbolProvider: JKSymbolProvider) {
|
||||
nullability
|
||||
)
|
||||
} else {
|
||||
JKUnresolvedClassType(this.presentableText, parameters, nullability)
|
||||
JKUnresolvedClassType(this.rawType().canonicalText, parameters, nullability)
|
||||
}
|
||||
}
|
||||
is PsiArrayType -> JKJavaArrayTypeImpl(componentType.toJK(), nullability)
|
||||
|
||||
@@ -295,8 +295,8 @@ class NewCodeBuilder {
|
||||
printer.printlnWithNoIndent()
|
||||
}
|
||||
|
||||
override fun visitTypeElement(typeElement: JKTypeElement) {
|
||||
val type = typeElement.type
|
||||
|
||||
private fun renderType(type: JKType) {
|
||||
when (type) {
|
||||
is JKClassType ->
|
||||
(type.classReference as JKClassSymbol).fqName?.let { printer.printWithNoIndent(FqName(it).shortName().asString()) }
|
||||
@@ -310,6 +310,19 @@ class NewCodeBuilder {
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
if (type is JKParametrizedType && type.parameters.isNotEmpty()) {
|
||||
printer.par(ANGLE) {
|
||||
renderList(type.parameters) {
|
||||
renderType(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeElement(typeElement: JKTypeElement) {
|
||||
val type = typeElement.type
|
||||
|
||||
renderType(type)
|
||||
}
|
||||
|
||||
override fun visitBlock(block: JKBlock) {
|
||||
@@ -354,10 +367,6 @@ class NewCodeBuilder {
|
||||
body()
|
||||
this.printWithNoIndent(kind.close)
|
||||
}
|
||||
}
|
||||
|
||||
private enum class ParenthesisKind(val open: String, val close: String) {
|
||||
ROUND("(", ")"), SQUARE("[", "]"), CURVED("{", "}"), CURVED_MULTILINE("{\n", "}\n"), INLINE_COMMENT("/*", "*/")
|
||||
|
||||
override fun visitLambdaExpression(lambdaExpression: JKLambdaExpression) {
|
||||
printer.printWithNoIndent("{")
|
||||
@@ -387,6 +396,10 @@ class NewCodeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private enum class ParenthesisKind(val open: String, val close: String) {
|
||||
ROUND("(", ")"), SQUARE("[", "]"), CURVED("{", "}"), CURVED_MULTILINE("{\n", "}\n"), INLINE_COMMENT("/*", "*/"), ANGLE("<", ">")
|
||||
}
|
||||
|
||||
fun printCodeOut(root: JKTreeElement): String {
|
||||
Visitor().also { root.accept(it) }
|
||||
return builder.toString()
|
||||
|
||||
@@ -179,9 +179,9 @@ class JKClassTypeImpl(
|
||||
|
||||
class JKUnresolvedClassType(
|
||||
val name: String,
|
||||
var parameters: List<JKType>,
|
||||
override var parameters: List<JKType>,
|
||||
override val nullability: Nullability = Nullability.Default
|
||||
) : JKType
|
||||
) : JKParametrizedType
|
||||
|
||||
|
||||
class JKNullLiteral : JKLiteralExpression, JKElementBase() {
|
||||
|
||||
@@ -50,10 +50,13 @@ interface JKType {
|
||||
val nullability: Nullability
|
||||
}
|
||||
|
||||
interface JKClassType : JKType {
|
||||
interface JKParametrizedType : JKType {
|
||||
val parameters: List<JKType>
|
||||
}
|
||||
|
||||
interface JKClassType : JKParametrizedType {
|
||||
val classReference: JKSymbol?
|
||||
override val nullability: Nullability
|
||||
val parameters: List<JKType>
|
||||
}
|
||||
|
||||
interface JKJavaPrimitiveType : JKType {
|
||||
|
||||
Reference in New Issue
Block a user