mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Show expression script nodes
#KTIJ-12844 #KTIJ-24328 GitOrigin-RevId: ba129af8351283565d57354de7d8852af53629eb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f3283b046f
commit
54386022e2
@@ -488,6 +488,7 @@ presentation.text.for.receiver.in.container.paren.no.brackets=for {0} in {1}
|
||||
presentation.text.object.in.container=object in {0}
|
||||
|
||||
project.view.class.initializer=class initializer
|
||||
project.view.expression=expression
|
||||
project.view.class.error.name=no name provided
|
||||
|
||||
copy.text.adding.imports=Adding imports\u2026
|
||||
|
||||
@@ -134,6 +134,7 @@ abstract class KotlinIconProvider : IconProvider(), DumbAware {
|
||||
fun PsiElement.getBaseIcon(): Icon? = when (this) {
|
||||
is KtPackageDirective -> AllIcons.Nodes.Package
|
||||
is KtFile, is KtLightClassForFacade -> FILE
|
||||
is KtScript -> (parent as? KtFile)?.scriptIcon()
|
||||
is KtLightClassForSourceDeclaration -> navigationElement.getBaseIcon()
|
||||
is KtNamedFunction -> when {
|
||||
receiverTypeReference != null ->
|
||||
|
||||
+10
-12
@@ -31,6 +31,7 @@ internal class KtDeclarationTreeNode private constructor(
|
||||
|
||||
internal companion object {
|
||||
private val CLASS_INITIALIZER = "<" + KotlinBundle.message("project.view.class.initializer") + ">"
|
||||
private val EXPRESSION = "<" + KotlinBundle.message("project.view.expression") + ">"
|
||||
private val ERROR_NAME = "<" + KotlinBundle.message("project.view.class.error.name") + ">"
|
||||
|
||||
private fun String?.orErrorName() = if (!isNullOrBlank()) this else ERROR_NAME
|
||||
@@ -100,10 +101,16 @@ internal class KtDeclarationTreeNode private constructor(
|
||||
declaration.referenceExpression()
|
||||
|
||||
val referencedNameAsName = nameReferenceExpression?.getReferencedNameAsName()
|
||||
referencedNameAsName?.asString() ?: CLASS_INITIALIZER
|
||||
referencedNameAsName?.asString()?.let { return it }
|
||||
return if (declaration.body is KtExpression) {
|
||||
EXPRESSION
|
||||
} else {
|
||||
CLASS_INITIALIZER
|
||||
}
|
||||
}
|
||||
|
||||
is KtAnonymousInitializer -> CLASS_INITIALIZER
|
||||
is KtScript -> (declaration.parent as? KtFile)?.name ?: declaration.name.orErrorName()
|
||||
else -> declaration.name.orErrorName()
|
||||
}
|
||||
}
|
||||
@@ -117,16 +124,7 @@ internal class KtDeclarationTreeNode private constructor(
|
||||
} as? KtNameReferenceExpression
|
||||
}
|
||||
|
||||
fun KtDeclaration.isApplicableNode(): Boolean =
|
||||
this !is KtScriptInitializer || referenceExpression() != null
|
||||
|
||||
fun create(project: Project?,
|
||||
ktDeclaration: KtDeclaration,
|
||||
viewSettings: ViewSettings): KtDeclarationTreeNode? =
|
||||
if (ktDeclaration.isApplicableNode()) {
|
||||
KtDeclarationTreeNode(project, ktDeclaration, viewSettings)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
fun create(project: Project?, ktDeclaration: KtDeclaration, viewSettings: ViewSettings): KtDeclarationTreeNode =
|
||||
KtDeclarationTreeNode(project, ktDeclaration, viewSettings)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.projectView.KtDeclarationTreeNode.Companion.isApplicableNode
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import javax.swing.Icon
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
@@ -73,7 +72,7 @@ class KotlinStructureViewElement(
|
||||
(declarations.singleOrNull() as? KtScript) ?: element
|
||||
} else {
|
||||
element
|
||||
}.declarations.filter { it.isApplicableNode() }
|
||||
}.declarations
|
||||
}
|
||||
is KtClass -> element.getStructureDeclarations()
|
||||
is KtClassOrObject -> element.declarations
|
||||
|
||||
@@ -11,6 +11,7 @@ Navigation item file #0: src/build.gradle.kts
|
||||
-Project
|
||||
-PsiDirectory: src
|
||||
-[build.gradle.kts]
|
||||
<expression>
|
||||
application
|
||||
dependencies
|
||||
plugins
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// FILE: settings.gradle.kts
|
||||
// PATH: settings.gradle.kts
|
||||
// SHOW_MEMBERS: TRUE
|
||||
rootProject.name = "simple2"
|
||||
"".length + 1
|
||||
|
||||
include()
|
||||
@@ -11,5 +11,6 @@ Navigation item file #0: src/settings.gradle.kts
|
||||
-Project
|
||||
-PsiDirectory: src
|
||||
-[settings.gradle.kts]
|
||||
<expression>
|
||||
include
|
||||
+External Libraries
|
||||
Reference in New Issue
Block a user