Remove object name and type in project view

This commit is contained in:
Igor Yakovlev
2020-04-20 19:43:13 +03:00
parent 72303fd2ad
commit 7d917634d0
2 changed files with 8 additions and 18 deletions
@@ -423,6 +423,7 @@ presentation.text.for.receiver.in.container.paren=(for {0} in {1})
presentation.text.object.in.container=object in {0}
project.view.class.initializer=class initializer
project.view.class.error.name=no name provided
copy.text.adding.imports=Adding imports ...
copy.text.clipboard.content.seems.to.be.java.code.do.you.want.to.convert.it.to.kotlin=Clipboard content seems to be Java code. Do you want to convert it to Kotlin?
@@ -35,6 +35,9 @@ internal class KtDeclarationTreeNode(
companion object {
private val CLASS_INITIALIZER = "<" + KotlinBundle.message("project.view.class.initializer") + ">"
private val ERROR_NAME = "<" + KotlinBundle.message("project.view.class.error.name") + ">"
private fun String?.orErrorName() = if (!isNullOrBlank()) this else ERROR_NAME
fun tryGetRepresentableText(declaration: KtDeclaration, project: Project): String? {
@@ -46,7 +49,7 @@ internal class KtDeclarationTreeNode(
}
fun KtProperty.presentableText() = buildString {
append(name)
append(name.orErrorName())
typeReference?.text?.let { reference ->
appendColon()
append(reference)
@@ -58,7 +61,7 @@ internal class KtDeclarationTreeNode(
append(receiverReference)
append('.')
}
append(name)
append(name.orErrorName())
append("(")
val valueParameters = valueParameters
valueParameters.forEachIndexed { index, parameter ->
@@ -86,21 +89,7 @@ internal class KtDeclarationTreeNode(
if (isCompanion()) {
append("companion object")
} else {
append("object")
if (!name.isNullOrEmpty()) {
append(" $name")
}
}
if (superTypeListEntries.any()) {
appendColon()
val lastIndex = superTypeListEntries.size - 1
superTypeListEntries.forEachIndexed { index, entry ->
entry.typeReference?.text?.let {
if (index > 0 && index != lastIndex) append(", ")
append(it)
}
}
append(name.orErrorName())
}
}
@@ -109,7 +98,7 @@ internal class KtDeclarationTreeNode(
is KtFunction -> declaration.presentableText()
is KtObjectDeclaration -> declaration.presentableText()
is KtAnonymousInitializer -> CLASS_INITIALIZER
else -> declaration.name
else -> declaration.name.orErrorName()
}
}
}