[devkit, uast] *Dump UAST Tree By Each PsiElement* action added (IDEA-210615)

GitOrigin-RevId: 20d5ca7e598c51b21090e269f09d865b0377d858
This commit is contained in:
Nicolay Mitropolsky
2019-11-21 15:11:54 +00:00
committed by intellij-monorepo-bot
parent 78aef36ed7
commit bd29416405
6 changed files with 27 additions and 6 deletions
@@ -40,8 +40,11 @@
<blockingMethodChecker implementation="com.intellij.codeInspection.blockingCallsDetection.ThrowsTypeBlockingMethodChecker"/>
</extensions>
<actions>
<action id="DumpUastLog" internal="true" class="com.intellij.analysis.internal.DumpUastTreeAction" text="Dump UAST Tree">
<group id="UastInternal" text="UAST" internal="true" popup="true">
<action id="DumpUastLog" internal="true" class="com.intellij.analysis.internal.DumpUastTreeAction" text="Dump UAST Tree"/>
<action id="DumpUastLogByElement" internal="true" class="com.intellij.analysis.internal.DumpUastTreeActionByEach"
text="Dump UAST Tree By Each PsiElement"/>
<add-to-group group-id="Internal" anchor="last"/>
</action>
</group>
</actions>
</idea-plugin>
@@ -12,18 +12,19 @@ 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.psi.PsiFile
import com.intellij.testFramework.LightVirtualFile
import org.jetbrains.uast.UastLanguagePlugin
import org.jetbrains.uast.asRecursiveLogString
import org.jetbrains.uast.toUElement
class DumpUastTreeAction : AnAction() {
open 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() }
val dump = runReadAction { buildDump(file) }
if (dump == null) {
Notifications.Bus.notify(
Notification("UAST", "UAST", "Can't build UAST tree for file '${file.name}'", NotificationType.ERROR)
@@ -37,6 +38,8 @@ class DumpUastTreeAction : AnAction() {
)
}
open fun buildDump(file: PsiFile) = file.toUElement()?.asRecursiveLogString()
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = ApplicationManager.getApplication().isInternal && run {
val file = e.getData(LangDataKeys.PSI_FILE) ?: return@run false
@@ -0,0 +1,14 @@
// 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.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.uast.toUElement
import org.jetbrains.uast.util.IndentedPrintingVisitor
class DumpUastTreeActionByEach : DumpUastTreeAction() {
override fun buildDump(file: PsiFile): String? = object : IndentedPrintingVisitor({true}){
override fun render(element: PsiElement): CharSequence? = element.toUElement()?.asLogString()
}.also { file.accept(it) }.result
}
@@ -1,5 +1,5 @@
// 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 org.jetbrains.uast.test.common
package org.jetbrains.uast.util
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
@@ -7,6 +7,7 @@ import com.intellij.psi.PsiCodeBlock
import com.intellij.psi.PsiElement
import junit.framework.TestCase
import org.jetbrains.uast.*
import org.jetbrains.uast.util.IndentedPrintingVisitor
import kotlin.reflect.KClass
@@ -7,7 +7,7 @@ import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiModifierListOwner
import org.jetbrains.uast.UFile
import org.jetbrains.uast.UReferenceExpression
import org.jetbrains.uast.test.common.IndentedPrintingVisitor
import org.jetbrains.uast.util.IndentedPrintingVisitor
import org.jetbrains.uast.test.common.visitUFileAndGetResult
import org.jetbrains.uast.test.env.assertEqualsToFile
import org.jetbrains.uast.toUElementOfType