diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt index a7ff75390a9..8adc07d458c 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt @@ -5,15 +5,14 @@ package org.jetbrains.kotlin.fir +import com.intellij.openapi.util.JDOMUtil +import org.jdom.Element import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.w3c.dom.Node -import org.w3c.dom.NodeList import java.io.File import java.text.SimpleDateFormat import java.util.* -import javax.xml.parsers.DocumentBuilderFactory data class ModuleData( val name: String, @@ -44,17 +43,6 @@ data class JavaSourceRootData(val path: Path, val packagePrefix: Str private fun String.fixPath(): File = File(ROOT_PATH_PREFIX, this.removePrefix("/")) -private fun NodeList.toList(): List { - val list = mutableListOf() - for (index in 0 until this.length) { - list += item(index) - } - return list -} - - -private val Node.childNodesList get() = childNodes.toList() - private val ROOT_PATH_PREFIX:String = System.getProperty("fir.bench.prefix", "/") private val OUTPUT_DIR_REGEX_FILTER:String = System.getProperty("fir.bench.filter", ".*") private val MODULE_NAME_FILTER: String? = System.getProperty("fir.bench.filter.name") @@ -89,52 +77,43 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { AbstractTypeChecker.RUN_SLOW_ASSERTIONS = true } - private fun loadModule(file: File): ModuleData { - - val factory = DocumentBuilderFactory.newInstance() - factory.isIgnoringComments = true - factory.isIgnoringElementContentWhitespace = true - val builder = factory.newDocumentBuilder() - val document = builder.parse(file) - val moduleElement = document.childNodes.item(0).childNodesList.first { it.nodeType == Node.ELEMENT_NODE } - val moduleName = moduleElement.attributes.getNamedItem("name").nodeValue - val outputDir = moduleElement.attributes.getNamedItem("outputDir").nodeValue + private fun loadModule(moduleElement: Element): ModuleData { + val outputDir = moduleElement.getAttribute("outputDir").value + val moduleName = moduleElement.getAttribute("name").value val moduleNameQualifier = outputDir.substringAfterLast("/") val javaSourceRoots = mutableListOf>() val classpath = mutableListOf() val sources = mutableListOf() val friendDirs = mutableListOf() val optInAnnotations = mutableListOf() - val timestamp = moduleElement.attributes.getNamedItem("timestamp")?.nodeValue?.toLong() ?: 0 - val jdkHome = moduleElement.attributes.getNamedItem("jdkHome")?.nodeValue + val timestamp = moduleElement.getAttribute("timestamp")?.longValue ?: 0 + val jdkHome = moduleElement.getAttribute("jdkHome")?.value var modularJdkRoot: String? = null var isCommon = false - for (index in 0 until moduleElement.childNodes.length) { - val item = moduleElement.childNodes.item(index) - - when (item.nodeName) { + for (item in moduleElement.children) { + when (item.name) { "classpath" -> { - val path = item.attributes.getNamedItem("path").nodeValue + val path = item.getAttribute("path").value if (path != outputDir) { classpath += path } } "friendDir" -> { - val path = item.attributes.getNamedItem("path").nodeValue + val path = item.getAttribute("path").value friendDirs += path } "javaSourceRoots" -> { javaSourceRoots += JavaSourceRootData( - item.attributes.getNamedItem("path").nodeValue, - item.attributes.getNamedItem("packagePrefix")?.nodeValue, + item.getAttribute("path").value, + item.getAttribute("packagePrefix")?.value, ) } - "sources" -> sources += item.attributes.getNamedItem("path").nodeValue + "sources" -> sources += item.getAttribute("path").value "commonSources" -> isCommon = true - "modularJdkRoot" -> modularJdkRoot = item.attributes.getNamedItem("path").nodeValue - "useOptIn" -> optInAnnotations += item.attributes.getNamedItem("annotation").nodeValue + "modularJdkRoot" -> modularJdkRoot = item.getAttribute("path").value + "useOptIn" -> optInAnnotations += item.getAttribute("annotation").value } } @@ -154,6 +133,11 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { ) } + private fun loadModuleDumpFile(file: File): List { + val rootElement = JDOMUtil.load(file) + val modules = rootElement.getChildren("module") + return modules.map { node -> loadModule(node) } + } protected abstract fun beforePass(pass: Int) protected abstract fun afterPass(pass: Int) @@ -172,7 +156,7 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { val files = root.listFiles() ?: emptyArray() val modules = files.filter { it.extension == "xml" } .sortedBy { it.lastModified() } - .map { loadModule(it) } + .flatMap { loadModuleDumpFile(it) } .sortedBy { it.timestamp } .filter { it.rawOutputDir.matches(filterRegex) } .filter { (moduleName == null) || it.name == moduleName }