From 97f134eab1621a75cb9870c792330fac6629a863 Mon Sep 17 00:00:00 2001 From: "simon.ogorodnik" Date: Wed, 22 Jan 2020 12:08:31 +0300 Subject: [PATCH] Remove outdated fir-view module --- idea/build.gradle.kts | 1 - idea/fir-view/build.gradle.kts | 37 --- idea/fir-view/src/FirExplorerToolWindow.kt | 306 --------------------- idea/fir-view/src/ShowFirAction.kt | 45 --- prepare/idea-plugin/build.gradle.kts | 1 - settings.gradle | 1 - 6 files changed, 391 deletions(-) delete mode 100644 idea/fir-view/build.gradle.kts delete mode 100644 idea/fir-view/src/FirExplorerToolWindow.kt delete mode 100644 idea/fir-view/src/ShowFirAction.kt diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index 8c1b4e94aec..7066ddd15e6 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -79,7 +79,6 @@ dependencies { compile(project(":j2k")) compile(project(":idea:idea-j2k")) compile(project(":idea:formatter")) - compile(project(":idea:fir-view")) compile(project(":compiler:fir:fir2ir")) compile(project(":compiler:fir:resolve")) compile(project(":compiler:fir:java")) diff --git a/idea/fir-view/build.gradle.kts b/idea/fir-view/build.gradle.kts deleted file mode 100644 index 93539b16d2e..00000000000 --- a/idea/fir-view/build.gradle.kts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2000-2018 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. - */ - - -apply { plugin("kotlin") } -apply { plugin("jps-compatible") } - -dependencies { - val compile by configurations - val compileOnly by configurations - - - compile(kotlinStdlib()) - compileOnly(project(":kotlin-reflect-api")) - compile(project(":core:descriptors")) - compile(project(":compiler:fir:tree")) - compile(project(":compiler:fir:psi2fir")) - - compile(project(":idea:idea-core")) - - compileOnly(intellijDep()) - - Platform[192].orHigher { - compileOnly(intellijPluginDep("java")) - } - - compileOnly(intellijPluginDep("gradle")) -} - -sourceSets { - "main" { - projectDefault() - } - "test" {} -} diff --git a/idea/fir-view/src/FirExplorerToolWindow.kt b/idea/fir-view/src/FirExplorerToolWindow.kt deleted file mode 100644 index 9e3d6625acd..00000000000 --- a/idea/fir-view/src/FirExplorerToolWindow.kt +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2000-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.actions.internal - -import com.intellij.icons.AllIcons -import com.intellij.ide.projectView.PresentationData -import com.intellij.ide.util.treeView.IndexComparator -import com.intellij.openapi.Disposable -import com.intellij.openapi.application.runInEdt -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.markup.* -import com.intellij.openapi.fileEditor.* -import com.intellij.openapi.progress.EmptyProgressIndicator -import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.progress.ProgressManager -import com.intellij.openapi.progress.Task -import com.intellij.openapi.project.Project -import com.intellij.openapi.wm.ToolWindow -import com.intellij.psi.PsiDocumentManager -import com.intellij.ui.JBColor -import com.intellij.ui.SimpleTextAttributes -import com.intellij.ui.treeStructure.SimpleNode -import com.intellij.ui.treeStructure.SimpleTreeBuilder -import com.intellij.ui.treeStructure.SimpleTreeStructure -import com.intellij.ui.treeStructure.Tree -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.declarations.FirResolvePhase -import org.jetbrains.kotlin.fir.psi -import org.jetbrains.kotlin.idea.fir.firResolveState -import org.jetbrains.kotlin.idea.fir.getOrBuildFir -import org.jetbrains.kotlin.idea.util.application.runReadAction -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.psiUtil.endOffset -import org.jetbrains.kotlin.psi.psiUtil.startOffset -import java.awt.BorderLayout -import javax.swing.JPanel -import javax.swing.tree.DefaultMutableTreeNode -import javax.swing.tree.DefaultTreeModel -import kotlin.math.min -import kotlin.reflect.* -import kotlin.reflect.full.* -import kotlin.reflect.jvm.isAccessible - -class FirExplorerToolWindow(private val project: Project, private val toolWindow: ToolWindow) : JPanel(BorderLayout()), Disposable { - - - private val tree = Tree() - private val treeStructure = FirExplorerTreeStructure() - private val builder = SimpleTreeBuilder(tree, DefaultTreeModel(DefaultMutableTreeNode()), treeStructure, IndexComparator.INSTANCE) - - private val level = HighlighterLayer.SELECTION - 100 - private val highlightingAttributes = TextAttributes().apply { - effectType = EffectType.ROUNDED_BOX - effectColor = JBColor.RED - } - - - private val rangeHighlightMarkers = mutableListOf() - - private var currentEditor: Editor? = FileEditorManager.getInstance(project).selectedTextEditor - - fun clearHighlighting(editor: Editor) { - rangeHighlightMarkers.forEach { editor.markupModel.removeHighlighter(it) } - rangeHighlightMarkers.clear() - } - - fun postponeTreeRebuild(editor: Editor, init: Boolean) { - ProgressManager.getInstance().runProcessWithProgressAsynchronously( - object : Task.Backgroundable(project, "") { - override fun run(indicator: ProgressIndicator) { - val psiDocumentManager = PsiDocumentManager.getInstance(project) - val file = runReadAction { psiDocumentManager.getPsiFile(editor.document) as? KtFile } - if (file != null) { - val firFile = runReadAction { file.getOrBuildFir(file.firResolveState(), phase = FirResolvePhase.RAW_FIR) } - runInEdt { - treeStructure.root = FirExplorerTreeNode("root = ", firFile, null) - builder.updateFromRoot(!init) - } - } - } - }, - EmptyProgressIndicator() - ) - - } - - init { - - - project.messageBus.connect(this).subscribe( - FileEditorManagerListener.FILE_EDITOR_MANAGER, - object : FileEditorManagerListener { - override fun selectionChanged(event: FileEditorManagerEvent) { - runInEdt { - val oldEditor = (event.oldEditor as? TextEditor) - val textEditor = (event.newEditor as? TextEditor) - if (oldEditor != null && oldEditor.editor == currentEditor) { - clearHighlighting(currentEditor!!) - currentEditor = null - } - - if (textEditor != null) { - currentEditor = textEditor.editor - postponeTreeRebuild(currentEditor!!, false) - } - } - } - } - ) - - tree.addTreeSelectionListener { event -> - val currentEditor = FileEditorManager.getInstance(project).selectedTextEditor - if (currentEditor != null) { - runReadAction { - clearHighlighting(currentEditor) - event.paths.filter { event.isAddedPath(it) }.mapNotNull { - val treeNode = it.lastPathComponent - if (treeNode is DefaultMutableTreeNode) { - val userObject = treeNode.userObject - if (userObject is FirExplorerTreeNode) { - - val data = userObject.data - val psi = (data as? FirElement)?.psi - if (data is FirElement && psi != null) { - if (FileDocumentManager.getInstance().getFile(currentEditor.document) == psi.containingFile.virtualFile) { - rangeHighlightMarkers += currentEditor.markupModel.addRangeHighlighter( - psi.startOffset, - min(currentEditor.document.textLength, psi.endOffset), - level, - highlightingAttributes, - HighlighterTargetArea.EXACT_RANGE - ) - } - } - } - } - } - } - - } - } - - - - - - - add(tree) - builder.initRoot() - postponeTreeRebuild(currentEditor!!, true) - } - - abstract class AbstractFirExplorerTreeNode(val propertyName: String, parent: SimpleNode?) : SimpleNode(parent) { - - init { - templatePresentation.addText(propertyName, SimpleTextAttributes.REGULAR_ATTRIBUTES) - } - - } - - class FirExplorerTreeNode(propertyName: String, val data: Any?, parent: SimpleNode?) : - AbstractFirExplorerTreeNode(propertyName, parent) { - - init { - templatePresentation.setIcon(AllIcons.Nodes.Property) - if (data != null) { - templatePresentation.addText(data::class.java.simpleName, SimpleTextAttributes.REGULAR_ATTRIBUTES) - templatePresentation.addText("(toString = $data)", SimpleTextAttributes.REGULAR_ATTRIBUTES) - } else { - templatePresentation.addText("null", SimpleTextAttributes.GRAY_ATTRIBUTES) - } - } - - - private fun KClass<*>.getMemberProperties(): Collection> { - return try { - memberProperties - } catch (e: Throwable) { - try { - declaredMemberProperties - } catch (e: Throwable) { - emptyList() - } - } - } - - override fun getChildren(): Array { - if (data == null) { - return NO_CHILDREN - } else { - val classOfData = data::class - - val members = classOfData.getMemberProperties() - - return members.filter { - it.visibility == null || it.visibility!! <= KVisibility.PROTECTED - }.filter { - it.instanceParameter != null - }.map { - it.getter.isAccessible = true - val value = it.getter.call(data) - val notNullValueType = it.returnType.withNullability(false) - - val namePrefix = "${it.name}: ${it.returnType.renderSimple()} = " - - when { - notNullValueType.isSubtypeOf(firElementType) -> { - FirExplorerTreeNode(namePrefix, value as FirElement?, this) - } - notNullValueType.isSubtypeOf(listElementType) -> { - FirExplorerTreeListNode(namePrefix, value as List<*>?, this) - } - else -> { - FirExplorerTreeNode(namePrefix, value, this) - } - } - }.toTypedArray() - } - } - - companion object { - val firElementKlass = FirElement::class - val firElementType = firElementKlass.starProjectedType - val listElementType = List::class.starProjectedType - } - } - - - class FirExplorerTreeListNode(propertyName: String, val data: List?, parent: SimpleNode?) : - AbstractFirExplorerTreeNode(propertyName, parent) { - - init { - if (data != null) { - templatePresentation.addText(data::class.simpleName, SimpleTextAttributes.REGULAR_ATTRIBUTES) - templatePresentation.addText("(size = ${data.size})", SimpleTextAttributes.REGULAR_ATTRIBUTES) - } else { - templatePresentation.addText("null", SimpleTextAttributes.REGULAR_ATTRIBUTES) - } - } - - override fun update(presentation: PresentationData) { - super.update(presentation) - presentation.setIcon(AllIcons.Actions.ShowAsTree) - } - - override fun getChildren(): Array { - if (data == null) return NO_CHILDREN - - - return data.mapIndexed { index, any -> - val propName = "[$index] = " - if (any is List<*>) { - FirExplorerTreeListNode(propName, any, this) - } else { - FirExplorerTreeNode(propName, any, this) - } - }.toTypedArray() - - } - - } - - - inner class FirExplorerTreeStructure : SimpleTreeStructure() { - var root: SimpleNode = FirExplorerTreeListNode("root = ", null, null) - - override fun getRootElement(): Any { - return root - } - } - - override fun dispose() { - - } - -} - -private fun KType.renderSimple(): String { - fun KVariance?.render(): String { - return when (this) { - KVariance.IN -> "in " - KVariance.OUT -> "out " - else -> "" - } - } - - return buildString { - when (val classifier = classifier) { - is KClass<*> -> append(classifier.simpleName) - is KTypeParameter -> append(classifier.name) - } - if (arguments.isNotEmpty()) { - append("<") - arguments.joinTo(this) { - it.variance.render() + it.type?.renderSimple() - } - append(">") - } - if (isMarkedNullable) { - append("?") - } - } -} \ No newline at end of file diff --git a/idea/fir-view/src/ShowFirAction.kt b/idea/fir-view/src/ShowFirAction.kt deleted file mode 100644 index ad24703e977..00000000000 --- a/idea/fir-view/src/ShowFirAction.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2000-2018 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.actions.internal - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.wm.ToolWindowAnchor -import com.intellij.openapi.wm.ToolWindowManager -import com.intellij.ui.content.ContentFactory -import org.jetbrains.kotlin.idea.KotlinFileType -import org.jetbrains.kotlin.idea.KotlinIcons - -class ShowFirAction : AnAction() { - - val TOOLWINDOW_ID = "FIR Explorer" - - - override fun actionPerformed(e: AnActionEvent) { - val project = e.project ?: return - val toolWindowManager = ToolWindowManager.getInstance(project) - - var toolWindow = toolWindowManager.getToolWindow(TOOLWINDOW_ID) - if (toolWindow == null) { - toolWindow = toolWindowManager.registerToolWindow(TOOLWINDOW_ID, false, ToolWindowAnchor.RIGHT) - toolWindow.icon = KotlinIcons.SMALL_LOGO_13 - - val contentManager = toolWindow.contentManager - val contentFactory = ContentFactory.SERVICE.getInstance() - contentManager.addContent(contentFactory.createContent(FirExplorerToolWindow(project, toolWindow), "", false)) - } - toolWindow.activate(null) - } - - override fun update(e: AnActionEvent) { - val file = e.getData(CommonDataKeys.PSI_FILE) - e.presentation.isVisible = ApplicationManager.getApplication().isInternal - e.presentation.isEnabled = e.project != null && file?.fileType == KotlinFileType.INSTANCE - } - -} \ No newline at end of file diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index ade20c000f5..dd722b337f9 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -50,7 +50,6 @@ val projectsToShadow by extra(listOf( ":compiler:fir:jvm", ":compiler:fir:psi2fir", ":compiler:fir:fir2ir", - ":idea:fir-view", ":compiler:frontend", ":compiler:frontend.common", ":compiler:frontend.java", diff --git a/settings.gradle b/settings.gradle index b9d138accb0..cd355b17b61 100644 --- a/settings.gradle +++ b/settings.gradle @@ -137,7 +137,6 @@ include ":kotlin-build-common", ":core:metadata.jvm", ":core:util.runtime", ":dependencies:android-sdk", - ":idea:fir-view", ":idea:idea-jvm", ":idea:idea-maven", ":idea:idea-gradle",