[platform] ExportToXMLAction: move method to nested Util

GitOrigin-RevId: d32b892bd04511ee8dd30704eb34a1b9352dfa6c
This commit is contained in:
Yann Cébron
2023-11-09 11:25:57 +01:00
committed by intellij-monorepo-bot
parent 9303014986
commit e849ea4b8e
3 changed files with 54 additions and 53 deletions

View File

@@ -18,52 +18,6 @@ import java.io.IOException
import java.nio.file.Path
import java.util.function.Supplier
fun dumpToXml(profile: InspectionProfileImpl,
tree: InspectionTree,
project: Project,
globalInspectionContext: GlobalInspectionContextImpl,
outputPath: Path) {
fun getWrappersForAllScopes(shortName: String,
context: GlobalInspectionContextImpl): Collection<InspectionToolWrapper<*, *>> {
return when (val tools = context.tools[shortName]) {
null -> emptyList() //dummy entry points tool
else -> ContainerUtil.map(tools.tools) { obj: ScopeToolState -> obj.tool }
}
}
val singleTool = profile.singleTool
val shortName2Wrapper = MultiMap<String, InspectionToolWrapper<*, *>>()
if (singleTool != null) {
shortName2Wrapper.put(singleTool, getWrappersForAllScopes(singleTool, globalInspectionContext))
}
else {
val model: InspectionTreeModel = tree.inspectionTreeModel
model
.traverse(model.root)
.filter(InspectionNode::class.java)
.filter { !it.isExcluded }
.map { obj: InspectionNode -> obj.toolWrapper }
.forEach { w: InspectionToolWrapper<*, *> -> shortName2Wrapper.putValue(w.shortName, w) }
}
for (entry in shortName2Wrapper.entrySet()) {
val shortName: String = entry.key
val wrappers: Collection<InspectionToolWrapper<*, *>> = entry.value
InspectionsResultUtil.writeInspectionResult(project, shortName, wrappers, outputPath) { wrapper: InspectionToolWrapper<*, *> ->
globalInspectionContext.getPresentation(wrapper)
}
}
val descriptionsFile: Path = outputPath.resolve(InspectionsResultUtil.DESCRIPTIONS + InspectionsResultUtil.XML_EXTENSION)
try {
InspectionsResultUtil.describeInspections(descriptionsFile, profile.name, profile)
}
catch (e: javax.xml.stream.XMLStreamException) {
throw IOException(e)
}
}
@Suppress("ComponentNotRegistered") // false positive: AnAction inheritor vs EP
internal class ExportToXMLAction : InspectionResultsExportActionProvider(Supplier { "XML" },
InspectionsBundle.messagePointer(
@@ -75,7 +29,56 @@ internal class ExportToXMLAction : InspectionResultsExportActionProvider(Supplie
globalInspectionContext: GlobalInspectionContextImpl,
project: Project,
outputPath: Path) {
dumpToXml(profile, tree, project, globalInspectionContext, outputPath)
Util.dumpToXml(profile, tree, project, globalInspectionContext, outputPath)
}
object Util {
@JvmStatic
fun dumpToXml(profile: InspectionProfileImpl,
tree: InspectionTree,
project: Project,
globalInspectionContext: GlobalInspectionContextImpl,
outputPath: Path) {
fun getWrappersForAllScopes(shortName: String,
context: GlobalInspectionContextImpl): Collection<InspectionToolWrapper<*, *>> {
return when (val tools = context.tools[shortName]) {
null -> emptyList() //dummy entry points tool
else -> ContainerUtil.map(tools.tools) { obj: ScopeToolState -> obj.tool }
}
}
val singleTool = profile.singleTool
val shortName2Wrapper = MultiMap<String, InspectionToolWrapper<*, *>>()
if (singleTool != null) {
shortName2Wrapper.put(singleTool, getWrappersForAllScopes(singleTool, globalInspectionContext))
}
else {
val model: InspectionTreeModel = tree.inspectionTreeModel
model
.traverse(model.root)
.filter(InspectionNode::class.java)
.filter { !it.isExcluded }
.map { obj: InspectionNode -> obj.toolWrapper }
.forEach { w: InspectionToolWrapper<*, *> -> shortName2Wrapper.putValue(w.shortName, w) }
}
for (entry in shortName2Wrapper.entrySet()) {
val shortName: String = entry.key
val wrappers: Collection<InspectionToolWrapper<*, *>> = entry.value
InspectionsResultUtil.writeInspectionResult(project, shortName, wrappers, outputPath) { wrapper: InspectionToolWrapper<*, *> ->
globalInspectionContext.getPresentation(wrapper)
}
}
val descriptionsFile: Path = outputPath.resolve(InspectionsResultUtil.DESCRIPTIONS + InspectionsResultUtil.XML_EXTENSION)
try {
InspectionsResultUtil.describeInspections(descriptionsFile, profile.name, profile)
}
catch (e: javax.xml.stream.XMLStreamException) {
throw IOException(e)
}
}
}
}

View File

@@ -10,7 +10,6 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.Tools;
import com.intellij.codeInspection.ui.InspectionResultsView;
import com.intellij.codeInspection.ui.actions.ExportToXMLAction;
import com.intellij.codeInspection.ui.actions.ExportToXMLActionKt;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
@@ -154,8 +153,8 @@ public class InspectionCommandEx extends AbstractCommand {
final InspectionResultsView view = getView();
if (view != null) {
ExportToXMLActionKt.dumpToXml(view.getCurrentProfile(), view.getTree(), view.getProject(),
view.getGlobalInspectionContext(), tempDirectory.toPath());
ExportToXMLAction.Util.dumpToXml(view.getCurrentProfile(), view.getTree(), view.getProject(),
view.getGlobalInspectionContext(), tempDirectory.toPath());
File[] files = tempDirectory.listFiles();
if (files != null) {

View File

@@ -10,7 +10,6 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ui.InspectionResultsView;
import com.intellij.codeInspection.ui.actions.ExportToXMLAction;
import com.intellij.codeInspection.ui.actions.ExportToXMLActionKt;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.playback.PlaybackContext;
@@ -70,8 +69,8 @@ public class SingleInspectionCommand extends AbstractCommand {
File tempDirectory = FileUtil.createTempDirectory("inspection", "result");
final InspectionResultsView view = getView();
if (view != null) {
ExportToXMLActionKt.dumpToXml(view.getCurrentProfile(), view.getTree(), view.getProject(),
view.getGlobalInspectionContext(), tempDirectory.toPath());
ExportToXMLAction.Util.dumpToXml(view.getCurrentProfile(), view.getTree(), view.getProject(),
view.getGlobalInspectionContext(), tempDirectory.toPath());
File[] files = tempDirectory.listFiles();
if (files != null) {