Uast: Internal action for dumping the uast tree introduced

This commit is contained in:
Nicolay Mitropolsky
2019-01-28 14:52:33 +03:00
parent 8b09908a69
commit f05ee260a3
2 changed files with 52 additions and 0 deletions
@@ -23,4 +23,9 @@
<extensions defaultExtensionNs="com.intellij.codeInsight">
<blockingMethodChecker implementation="com.intellij.codeInspection.blockingCallsDetection.ThrowsTypeBlockingMethodChecker"/>
</extensions>
<actions>
<action id="DumpUastLog" internal="true" class="com.intellij.analysis.internal.DumpUastTreeAction" text="Dump UAST tree">
<add-to-group group-id="Internal" anchor="last"/>
</action>
</actions>
</idea-plugin>
@@ -0,0 +1,47 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.analysis.internal
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.application.ex.ApplicationManagerEx
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.fileTypes.PlainTextLanguage
import com.intellij.testFramework.LightVirtualFile
import org.jetbrains.uast.UastLanguagePlugin
import org.jetbrains.uast.asRecursiveLogString
import org.jetbrains.uast.toUElement
class DumpUastTreeAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val file = e.getData(LangDataKeys.PSI_FILE) ?: return
val project = e.project ?: return
val dump = runReadAction { file.toUElement()?.asRecursiveLogString() }
if (dump == null) {
Notifications.Bus.notify(
Notification("UAST", "UAST", "Can't build UAST tree for file '${file.name}'", NotificationType.ERROR)
)
return
}
FileEditorManager.getInstance(project).openEditor(
OpenFileDescriptor(project, LightVirtualFile(file.name + ".uast-log", PlainTextLanguage.INSTANCE, dump)),
true
)
}
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible =
ApplicationManagerEx.getApplicationEx().isInternal && run {
val file = e.getData(LangDataKeys.PSI_FILE) ?: return@run false
UastLanguagePlugin.byLanguage(file.language) != null
}
}
}