diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt new file mode 100644 index 00000000000..96a5ecf271a --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt @@ -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 \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt.201 b/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt.201 new file mode 100644 index 00000000000..d331cff93c2 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/BreadcrumbsProviderCompatBase.kt.201 @@ -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 +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt index ca7a4fa64e8..e6bda2dd7d1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt @@ -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(val type: KClass) { abstract fun elementInfo(element: TElement): String abstract fun elementTooltip(element: TElement): String diff --git a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt new file mode 100644 index 00000000000..9f04f317866 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt @@ -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) +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt.201 b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt.201 new file mode 100644 index 00000000000..ce6da0a6334 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/AbstractNavBarModelExtensionCompatBase.kt.201 @@ -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 +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt index a63bdfe8006..e26d4c84a02 100644 --- a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt +++ b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt @@ -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 } -} +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt.201 b/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt.201 deleted file mode 100644 index 5b2d93adbe2..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/navigationToolbar/KotlinNavBarModelExtension.kt.201 +++ /dev/null @@ -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 - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt b/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt index 0d6e3e1a40d..3967363ad83 100644 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt @@ -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 } diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java b/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java deleted file mode 100644 index c5e5a646b75..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java +++ /dev/null @@ -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 { - 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 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 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()); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java.201 b/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java.201 deleted file mode 100644 index e1f95102927..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.java.201 +++ /dev/null @@ -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 { - 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> 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 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()); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.kt b/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.kt new file mode 100644 index 00000000000..13a95e164bb --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/KtDeclarationTreeNode.kt @@ -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(project, ktDeclaration!!, viewSettings) { + + override fun extractPsiFromValue(): PsiElement? = value + + override fun getChildrenImpl(): Collection> { + val settings = settings + val project = project + + if (!settings.isShowMembers) return emptyList() + val declaration = value ?: return emptyList() + + val result = mutableListOf>() + 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 + } + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java b/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java deleted file mode 100644 index 2a13bc85284..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java +++ /dev/null @@ -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 getChildrenImpl() { - KtFile file = (KtFile) getValue(); - - if (file == null) return Collections.emptyList(); - ArrayList result = new ArrayList(); - - if (getSettings().isShowMembers()) { - @SuppressWarnings("ConstantConditions") List 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; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java.201 b/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java.201 deleted file mode 100644 index 07198c9e7cb..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.java.201 +++ /dev/null @@ -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> getChildrenImpl() { - KtFile file = (KtFile) getValue(); - - if (file == null) return Collections.emptyList(); - ArrayList> result = new ArrayList<>(); - - if (getSettings().isShowMembers()) { - @SuppressWarnings("ConstantConditions") List 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; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.kt b/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.kt new file mode 100644 index 00000000000..e3022e36599 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/KtFileTreeNode.kt @@ -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> { + 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) + } + } +} \ No newline at end of file