New J2K: Add rendering for type-parameters

This commit is contained in:
Simon Ogorodnik
2018-07-23 22:41:20 +03:00
committed by Ilya Kirillov
parent b12a91c111
commit c87cd20a9d
4 changed files with 27 additions and 11 deletions
@@ -220,7 +220,7 @@ class JavaToJKTreeBuilder(var symbolProvider: JKSymbolProvider) {
nullability nullability
) )
} else { } else {
JKUnresolvedClassType(this.presentableText, parameters, nullability) JKUnresolvedClassType(this.rawType().canonicalText, parameters, nullability)
} }
} }
is PsiArrayType -> JKJavaArrayTypeImpl(componentType.toJK(), nullability) is PsiArrayType -> JKJavaArrayTypeImpl(componentType.toJK(), nullability)
@@ -295,8 +295,8 @@ class NewCodeBuilder {
printer.printlnWithNoIndent() printer.printlnWithNoIndent()
} }
override fun visitTypeElement(typeElement: JKTypeElement) {
val type = typeElement.type private fun renderType(type: JKType) {
when (type) { when (type) {
is JKClassType -> is JKClassType ->
(type.classReference as JKClassSymbol).fqName?.let { printer.printWithNoIndent(FqName(it).shortName().asString()) } (type.classReference as JKClassSymbol).fqName?.let { printer.printWithNoIndent(FqName(it).shortName().asString()) }
@@ -310,6 +310,19 @@ class NewCodeBuilder {
else -> { 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) { override fun visitBlock(block: JKBlock) {
@@ -354,10 +367,6 @@ class NewCodeBuilder {
body() body()
this.printWithNoIndent(kind.close) 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) { override fun visitLambdaExpression(lambdaExpression: JKLambdaExpression) {
printer.printWithNoIndent("{") 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 { fun printCodeOut(root: JKTreeElement): String {
Visitor().also { root.accept(it) } Visitor().also { root.accept(it) }
return builder.toString() return builder.toString()
@@ -179,9 +179,9 @@ class JKClassTypeImpl(
class JKUnresolvedClassType( class JKUnresolvedClassType(
val name: String, val name: String,
var parameters: List<JKType>, override var parameters: List<JKType>,
override val nullability: Nullability = Nullability.Default override val nullability: Nullability = Nullability.Default
) : JKType ) : JKParametrizedType
class JKNullLiteral : JKLiteralExpression, JKElementBase() { class JKNullLiteral : JKLiteralExpression, JKElementBase() {
@@ -50,10 +50,13 @@ interface JKType {
val nullability: Nullability val nullability: Nullability
} }
interface JKClassType : JKType { interface JKParametrizedType : JKType {
val parameters: List<JKType>
}
interface JKClassType : JKParametrizedType {
val classReference: JKSymbol? val classReference: JKSymbol?
override val nullability: Nullability override val nullability: Nullability
val parameters: List<JKType>
} }
interface JKJavaPrimitiveType : JKType { interface JKJavaPrimitiveType : JKType {