Add Project View and Navigation Bar enhancements

Add local declarations to Project View
Show Kotlin file members in navigation bar (Fixed #KT-36218)
Remove deprecated dependency
This commit is contained in:
Igor Yakovlev
2020-04-06 21:19:09 +03:00
parent ca10c40e05
commit 0df54946d9
14 changed files with 266 additions and 402 deletions
@@ -0,0 +1,11 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.codeInsight
import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider
// BUNCH 201
typealias BreadcrumbsProviderCompatBase = BreadcrumbsInfoProvider
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.codeInsight
import com.intellij.ide.ui.UISettings
import com.intellij.ui.breadcrumbs.BreadcrumbsProvider
// BUNCH 201
abstract class BreadcrumbsProviderCompatBase : BreadcrumbsProvider {
override fun isShownByDefault(): Boolean =
!UISettings.instance.showMembersInNavigationBar
}
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.codeInsight
@@ -22,7 +11,6 @@ import com.intellij.psi.ElementDescriptionUtil
import com.intellij.psi.PsiElement
import com.intellij.refactoring.util.RefactoringDescriptionLocation
import com.intellij.usageView.UsageViewShortNameLocation
import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.KotlinLanguage
@@ -35,7 +23,8 @@ import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
import kotlin.reflect.KClass
class KotlinBreadcrumbsInfoProvider : BreadcrumbsInfoProvider() {
// BUNCH 201
class KotlinBreadcrumbsInfoProvider : BreadcrumbsProviderCompatBase() {
private abstract class ElementHandler<TElement : KtElement>(val type: KClass<TElement>) {
abstract fun elementInfo(element: TElement): String
abstract fun elementTooltip(element: TElement): String
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension
import com.intellij.psi.PsiElement
// BUNCH 201
abstract class AbstractNavBarModelExtensionCompatBase : AbstractNavBarModelExtension() {
protected abstract fun adjustElementImpl(psiElement: PsiElement?): PsiElement?
override fun adjustElement(psiElement: PsiElement): PsiElement? =
adjustElementImpl(psiElement)
}
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.StructureAwareNavBarModelExtension
import com.intellij.lang.Language
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinLanguage
// BUNCH 201
abstract class AbstractNavBarModelExtensionCompatBase : StructureAwareNavBarModelExtension() {
protected abstract fun adjustElementImpl(psiElement: PsiElement?): PsiElement?
override fun adjustElement(psiElement: PsiElement): PsiElement? =
adjustElementImpl(psiElement)
override val language: Language
get() = KotlinLanguage.INSTANCE
}
@@ -5,23 +5,20 @@
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinIconProvider
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.idea.projectView.KtDeclarationTreeNode.Companion.tryGetRepresentableText
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
class KotlinNavBarModelExtension : AbstractNavBarModelExtension() {
override fun getPresentableText(item: Any?): String? {
return when (item) {
is KtClassOrObject -> item.name ?: "unknown"
else -> null
}
}
// BUNCH 201
class KotlinNavBarModelExtension : AbstractNavBarModelExtensionCompatBase() {
override fun getPresentableText(item: Any?): String? =
(item as? KtDeclaration)?.let { tryGetRepresentableText(it, it.project) }
override fun adjustElement(psiElement: PsiElement?): PsiElement? {
override fun adjustElementImpl(psiElement: PsiElement?): PsiElement? {
val containingFile = psiElement?.containingFile as? KtFile ?: return psiElement
if (containingFile.isScript()) return psiElement
return KotlinIconProvider.getSingleClass(containingFile) ?: psiElement
}
}
}
@@ -1,27 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinIconProvider
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
class KotlinNavBarModelExtension : AbstractNavBarModelExtension() {
override fun getPresentableText(item: Any?): String? {
return when (item) {
is KtClassOrObject -> item.name ?: "unknown"
else -> null
}
}
override fun adjustElement(psiElement: PsiElement): PsiElement? {
val containingFile = psiElement.containingFile as? KtFile ?: return psiElement
if (containingFile.isScript()) return psiElement
return KotlinIconProvider.getSingleClass(containingFile) ?: psiElement
}
}
@@ -34,8 +34,9 @@ class KtClassOrObjectTreeNode(project: Project?, ktClassOrObject: KtClassOrObjec
}
override fun updateImpl(data: PresentationData) {
val project = project ?: return
value?.let {
data.presentableText = it.name
data.presentableText = KtDeclarationTreeNode.tryGetRepresentableText(it, project)
}
}
@@ -75,5 +76,7 @@ class KtClassOrObjectTreeNode(project: Project?, ktClassOrObject: KtClassOrObjec
return false
}
override fun expandOnDoubleClick(): Boolean = false
override fun getWeight() = 20
}
@@ -1,111 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.projectView;
import com.intellij.application.options.CodeStyle;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import org.jetbrains.kotlin.idea.KotlinBundle;
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings;
import org.jetbrains.kotlin.psi.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class KtDeclarationTreeNode extends AbstractPsiBasedNode<KtDeclaration> {
public static final String CLASS_INITIALIZER = "<" + KotlinBundle.message("project.view.class.initializer") + ">";
protected KtDeclarationTreeNode(Project project, KtDeclaration ktDeclaration, ViewSettings viewSettings) {
super(project, ktDeclaration, viewSettings);
}
@Override
protected PsiElement extractPsiFromValue() {
return getValue();
}
@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
return Collections.emptyList();
}
@Override
protected void updateImpl(PresentationData data) {
KtDeclaration declaration = getValue();
if (declaration != null) {
String text = declaration instanceof KtAnonymousInitializer ? CLASS_INITIALIZER : declaration.getName();
if (text == null) return;
KotlinCodeStyleSettings settings = CodeStyle.getSettings(getProject())
.getCustomSettings(KotlinCodeStyleSettings.class);
if (declaration instanceof KtProperty) {
KtProperty property = (KtProperty) declaration;
KtTypeReference ref = property.getTypeReference();
if (ref != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
text += ref.getText();
}
}
else if (declaration instanceof KtFunction) {
KtFunction function = (KtFunction) declaration;
KtTypeReference receiverTypeRef = function.getReceiverTypeReference();
if (receiverTypeRef != null) {
text = receiverTypeRef.getText() + "." + text;
}
text += "(";
List<KtParameter> parameters = function.getValueParameters();
for (KtParameter parameter : parameters) {
if (parameter.getName() != null) {
text += parameter.getName();
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
}
KtTypeReference typeReference = parameter.getTypeReference();
if (typeReference != null) {
text += typeReference.getText();
}
text += ", ";
}
if (parameters.size() > 0) text = text.substring(0, text.length() - 2);
text += ")";
KtTypeReference typeReference = function.getTypeReference();
if (typeReference != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
text += typeReference.getText();
}
}
data.setPresentableText(text);
}
}
@Override
protected boolean isDeprecated() {
return KtPsiUtil.isDeprecated(getValue());
}
}
@@ -1,111 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.projectView;
import com.intellij.application.options.CodeStyle;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import org.jetbrains.kotlin.idea.KotlinBundle;
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings;
import org.jetbrains.kotlin.psi.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class KtDeclarationTreeNode extends AbstractPsiBasedNode<KtDeclaration> {
public static final String CLASS_INITIALIZER = "<" + KotlinBundle.message("project.view.class.initializer") + ">";
protected KtDeclarationTreeNode(Project project, KtDeclaration ktDeclaration, ViewSettings viewSettings) {
super(project, ktDeclaration, viewSettings);
}
@Override
protected PsiElement extractPsiFromValue() {
return getValue();
}
@Override
protected Collection<AbstractTreeNode<?>> getChildrenImpl() {
return Collections.emptyList();
}
@Override
protected void updateImpl(PresentationData data) {
KtDeclaration declaration = getValue();
if (declaration != null) {
String text = declaration instanceof KtAnonymousInitializer ? CLASS_INITIALIZER : declaration.getName();
if (text == null) return;
KotlinCodeStyleSettings settings = CodeStyle.getSettings(getProject())
.getCustomSettings(KotlinCodeStyleSettings.class);
if (declaration instanceof KtProperty) {
KtProperty property = (KtProperty) declaration;
KtTypeReference ref = property.getTypeReference();
if (ref != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
text += ref.getText();
}
}
else if (declaration instanceof KtFunction) {
KtFunction function = (KtFunction) declaration;
KtTypeReference receiverTypeRef = function.getReceiverTypeReference();
if (receiverTypeRef != null) {
text = receiverTypeRef.getText() + "." + text;
}
text += "(";
List<KtParameter> parameters = function.getValueParameters();
for (KtParameter parameter : parameters) {
if (parameter.getName() != null) {
text += parameter.getName();
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
}
KtTypeReference typeReference = parameter.getTypeReference();
if (typeReference != null) {
text += typeReference.getText();
}
text += ", ";
}
if (parameters.size() > 0) text = text.substring(0, text.length() - 2);
text += ")";
KtTypeReference typeReference = function.getTypeReference();
if (typeReference != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":";
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
text += typeReference.getText();
}
}
data.setPresentableText(text);
}
}
@Override
protected boolean isDeprecated() {
return KtPsiUtil.isDeprecated(getValue());
}
}
@@ -0,0 +1,149 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.projectView
import com.intellij.application.options.CodeStyle
import com.intellij.ide.projectView.PresentationData
import com.intellij.ide.projectView.ViewSettings
import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
import org.jetbrains.kotlin.psi.*
internal class KtDeclarationTreeNode(
project: Project?,
ktDeclaration: KtDeclaration?,
viewSettings: ViewSettings?
) : AbstractPsiBasedNode<KtDeclaration?>(project, ktDeclaration!!, viewSettings) {
override fun extractPsiFromValue(): PsiElement? = value
override fun getChildrenImpl(): Collection<AbstractTreeNode<*>> {
val settings = settings
val project = project
if (!settings.isShowMembers) return emptyList()
val declaration = value ?: return emptyList()
val result = mutableListOf<AbstractTreeNode<*>>()
declaration.acceptChildren(object : KtTreeVisitorVoid() {
override fun visitClassOrObject(classOrObject: KtClassOrObject) {
result.add(
KtClassOrObjectTreeNode(
project = project,
ktClassOrObject = classOrObject,
viewSettings = settings
)
)
}
override fun visitNamedFunction(function: KtNamedFunction) {
result.add(
KtDeclarationTreeNode(
project = project,
ktDeclaration = function,
viewSettings = settings
)
)
}
})
return result
}
override fun updateImpl(data: PresentationData) {
val declaration = value ?: return
val project = project ?: return
data.presentableText = tryGetRepresentableText(declaration, project)
}
override fun expandOnDoubleClick(): Boolean = false
override fun isDeprecated(): Boolean = value?.let { KtPsiUtil.isDeprecated(it) } ?: false
companion object {
private val CLASS_INITIALIZER = "<" + KotlinBundle.message("project.view.class.initializer") + ">"
fun tryGetRepresentableText(declaration: KtDeclaration, project: Project): String? {
val settings = CodeStyle.getSettings(project).getCustomSettings(KotlinCodeStyleSettings::class.java)
fun StringBuilder.appendColon() {
if (settings.SPACE_BEFORE_TYPE_COLON) append(" ")
append(":")
if (settings.SPACE_AFTER_TYPE_COLON) append(" ")
}
fun KtProperty.presentableText() = buildString {
append(name)
typeReference?.text?.let { reference ->
appendColon()
append(reference)
}
}
fun KtFunction.presentableText() = buildString {
receiverTypeReference?.text?.let { receiverReference ->
append(receiverReference)
append('.')
}
append(name)
append("(")
val valueParameters = valueParameters
valueParameters.forEachIndexed { index, parameter ->
parameter.name?.let { parameterName ->
append(parameterName)
appendColon()
}
parameter.typeReference?.text?.let { typeReference ->
append(typeReference)
}
if (index != valueParameters.size - 1) {
append(", ")
}
}
append(")")
typeReference?.text?.let { returnTypeReference ->
appendColon()
append(returnTypeReference)
}
}
fun KtObjectDeclaration.presentableText(): String? = buildString {
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)
}
}
}
}
return when (declaration) {
is KtProperty -> declaration.presentableText()
is KtFunction -> declaration.presentableText()
is KtObjectDeclaration -> declaration.presentableText()
is KtAnonymousInitializer -> CLASS_INITIALIZER
else -> declaration.name
}
}
}
}
@@ -1,63 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.projectView;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import org.jetbrains.kotlin.psi.KtClassOrObject;
import org.jetbrains.kotlin.psi.KtDeclaration;
import org.jetbrains.kotlin.psi.KtFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class KtFileTreeNode extends PsiFileNode {
public KtFileTreeNode(Project project, KtFile value, ViewSettings viewSettings) {
super(project, value, viewSettings);
}
public final KtFile getKtFile() {
return (KtFile) getValue();
}
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
KtFile file = (KtFile) getValue();
if (file == null) return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
if (getSettings().isShowMembers()) {
@SuppressWarnings("ConstantConditions") List<KtDeclaration> declarations = (file.isScript() ? file.getScript() : file).getDeclarations();
for (KtDeclaration declaration : declarations) {
if (declaration instanceof KtClassOrObject) {
result.add(new KtClassOrObjectTreeNode(file.getProject(), (KtClassOrObject) declaration, getSettings()));
}
else if (getSettings().isShowMembers()) {
result.add(new KtDeclarationTreeNode(getProject(), declaration, getSettings()));
}
}
}
return result;
}
}
@@ -1,63 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.projectView;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import org.jetbrains.kotlin.psi.KtClassOrObject;
import org.jetbrains.kotlin.psi.KtDeclaration;
import org.jetbrains.kotlin.psi.KtFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class KtFileTreeNode extends PsiFileNode {
public KtFileTreeNode(Project project, KtFile value, ViewSettings viewSettings) {
super(project, value, viewSettings);
}
public final KtFile getKtFile() {
return (KtFile) getValue();
}
@Override
public Collection<AbstractTreeNode<?>> getChildrenImpl() {
KtFile file = (KtFile) getValue();
if (file == null) return Collections.emptyList();
ArrayList<AbstractTreeNode<?>> result = new ArrayList<>();
if (getSettings().isShowMembers()) {
@SuppressWarnings("ConstantConditions") List<KtDeclaration> declarations = (file.isScript() ? file.getScript() : file).getDeclarations();
for (KtDeclaration declaration : declarations) {
if (declaration instanceof KtClassOrObject) {
result.add(new KtClassOrObjectTreeNode(file.getProject(), (KtClassOrObject) declaration, getSettings()));
}
else if (getSettings().isShowMembers()) {
result.add(new KtDeclarationTreeNode(getProject(), declaration, getSettings()));
}
}
}
return result;
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.projectView
import com.intellij.ide.projectView.ViewSettings
import com.intellij.ide.projectView.impl.nodes.PsiFileNode
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
class KtFileTreeNode(
project: Project?,
val ktFile: KtFile,
viewSettings: ViewSettings
) : PsiFileNode(project, ktFile, viewSettings) {
override fun getChildrenImpl(): Collection<AbstractTreeNode<*>> {
if (!settings.isShowMembers) return emptyList()
val declarations = (if (ktFile.isScript()) ktFile.script else ktFile)
?.declarations
?: return emptyList()
return declarations.map {
if (it is KtClassOrObject)
KtClassOrObjectTreeNode(project, it, settings)
else
KtDeclarationTreeNode(project, it, settings)
}
}
}