Drop tests on JS decompiled text / stub consistency
They're no longer needed because the logic of the decompiler / stub builder is now trivial (see KotlinJavaScriptDeserializerForDecompiler, KotlinJavaScriptStubBuilder) and after it's merged to the decompiler for built-ins, it's going to be tested anyway with BuiltInDecompilerConsistencyTest
This commit is contained in:
-12
@@ -17,9 +17,7 @@
|
||||
package org.jetbrains.kotlin.fileClasses;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
public final class OldPackageFacadeClassUtils {
|
||||
private static final String PACKAGE_CLASS_NAME_SUFFIX = "Package";
|
||||
@@ -41,14 +39,4 @@ public final class OldPackageFacadeClassUtils {
|
||||
private static String capitalizeNonEmptyString(@NotNull String s) {
|
||||
return Character.isUpperCase(s.charAt(0)) ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName getPackageClassFqName(@NotNull FqName packageFQN) {
|
||||
return packageFQN.child(Name.identifier(getPackageClassName(packageFQN)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassId getPackageClassId(@NotNull FqName packageFQN) {
|
||||
return new ClassId(packageFQN, Name.identifier(getPackageClassName(packageFQN)));
|
||||
}
|
||||
}
|
||||
|
||||
+21
-8
@@ -16,22 +16,35 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.util.indexing.FileContentImpl
|
||||
import org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClsStubBuilder
|
||||
import org.jetbrains.kotlin.idea.decompiler.classFile.buildDecompiledTextForClassFile
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinder
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
|
||||
import org.junit.Assert
|
||||
|
||||
class ClsStubConsistencyTest : StubConsistencyBaseTest() {
|
||||
override fun getVirtualFileFinder(): VirtualFileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
|
||||
override fun getFileIds(): List<ClassId> = listOf(ClassId.topLevel(FqName("kotlin.collections.CollectionsKt")))
|
||||
class ClsStubConsistencyTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
private fun doTest(id: ClassId) {
|
||||
val packageFile = JvmVirtualFileFinder.SERVICE.getInstance(project).findVirtualFileWithHeader(id)
|
||||
?: throw AssertionError("File not found for id: $id")
|
||||
val decompiledText = buildDecompiledTextForClassFile(packageFile).text
|
||||
val fileWithDecompiledText = KtPsiFactory(project).createFile(decompiledText)
|
||||
val stubTreeFromDecompiledText = KtFileStubBuilder().buildStubTree(fileWithDecompiledText)
|
||||
val expectedText = stubTreeFromDecompiledText.serializeToString()
|
||||
|
||||
override fun createStubBuilder() = KotlinClsStubBuilder()
|
||||
val fileStub = KotlinClsStubBuilder().buildFileStub(FileContentImpl.createByFile(packageFile))!!
|
||||
Assert.assertEquals(expectedText, fileStub.serializeToString())
|
||||
}
|
||||
|
||||
override fun getDecompiledText(packageFile: VirtualFile): String = buildDecompiledTextForClassFile(packageFile).text
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
fun testConsistency() {
|
||||
doTest(ClassId.topLevel(FqName("kotlin.collections.CollectionsKt")))
|
||||
}
|
||||
}
|
||||
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.js.KotlinJavaScriptStubBuilder
|
||||
import org.jetbrains.kotlin.idea.decompiler.js.buildDecompiledTextFromJsMetadata
|
||||
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
|
||||
override fun getFileIds() = listOf(
|
||||
"jquery", "jquery.ui",
|
||||
"kotlin", "kotlin.collections", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
||||
).map { OldPackageFacadeClassUtils.getPackageClassId(FqName(it)) } + ClassId.topLevel(FqName("kotlin.js.Console"))
|
||||
|
||||
override fun getVirtualFileFinder(): VirtualFileFinder =
|
||||
JsVirtualFileFinder.SERVICE.getInstance(project)
|
||||
|
||||
override fun createStubBuilder() = KotlinJavaScriptStubBuilder()
|
||||
|
||||
override fun getDecompiledText(packageFile: VirtualFile): String = buildDecompiledTextFromJsMetadata(packageFile).text
|
||||
|
||||
override fun getProjectDescriptor() = KotlinStdJSProjectDescriptor.instance
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.compiled.ClsStubBuilder
|
||||
import com.intellij.util.indexing.FileContentImpl
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
|
||||
import org.junit.Assert
|
||||
|
||||
abstract class StubConsistencyBaseTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
protected abstract fun getFileIds(): List<ClassId>
|
||||
protected abstract fun getVirtualFileFinder(): VirtualFileFinder
|
||||
|
||||
protected abstract fun createStubBuilder(): ClsStubBuilder
|
||||
|
||||
protected abstract fun getDecompiledText(packageFile: VirtualFile): String
|
||||
|
||||
fun testConsistency() {
|
||||
getFileIds().forEach { doTest(it) }
|
||||
}
|
||||
|
||||
private fun doTest(id: ClassId) {
|
||||
val project = project
|
||||
val packageFile = getVirtualFileFinder().findVirtualFileWithHeader(id) ?: throw AssertionError("File not found for id: $id")
|
||||
val decompiledText = getDecompiledText(packageFile)
|
||||
val fileWithDecompiledText = KtPsiFactory(project).createFile(decompiledText)
|
||||
val stubTreeFromDecompiledText = KtFileStubBuilder().buildStubTree(fileWithDecompiledText)
|
||||
val expectedText = stubTreeFromDecompiledText.serializeToString()
|
||||
|
||||
val fileStub = createStubBuilder().buildFileStub(FileContentImpl.createByFile(packageFile))!!
|
||||
Assert.assertEquals(expectedText, fileStub.serializeToString())
|
||||
}
|
||||
}
|
||||
+50
-25
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
@@ -24,41 +27,63 @@ import org.jetbrains.kotlin.idea.caches.resolve.IDEPackagePartProvider
|
||||
import org.jetbrains.kotlin.idea.decompiler.classFile.buildDecompiledTextForClassFile
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.descriptors.isFromJvmPackagePart
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinder
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberDescriptor
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert
|
||||
|
||||
class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
||||
|
||||
override fun getPackages(): List<FqName> = emptyList()
|
||||
|
||||
override fun getFacades(): List<FqName> = listOf(FqName("kotlin.collections.CollectionsKt"), FqName("kotlin.collections.TypeAliasesKt"))
|
||||
|
||||
override fun getTopLevelMembers(): Map<String, String> = mapOf("kotlin.collections.CollectionsKt" to "mutableListOf")
|
||||
|
||||
override fun getVirtualFileFinder(): VirtualFileFinder =
|
||||
JvmVirtualFileFinder.SERVICE.getInstance(project)
|
||||
|
||||
override fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler?): String =
|
||||
(resolver?.let { buildDecompiledTextForClassFile(packageFile, it) } ?: buildDecompiledTextForClassFile(packageFile)).text
|
||||
|
||||
override fun getModuleDescriptor(): ModuleDescriptor =
|
||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
project, listOf(), BindingTraceContext(), KotlinTestUtils.newConfiguration(), ::IDEPackagePartProvider
|
||||
).moduleDescriptor
|
||||
|
||||
class DecompiledTextConsistencyTest : LightCodeInsightFixtureTestCase() {
|
||||
override fun getProjectDescriptor() =
|
||||
object : KotlinWithJdkAndRuntimeLightProjectDescriptor() {
|
||||
override fun getSdk() = PluginTestCaseBase.fullJdk()
|
||||
}
|
||||
|
||||
override fun isFromFacade(descriptor: MemberDescriptor, facadeFqName: FqName): Boolean =
|
||||
descriptor is DeserializedMemberDescriptor &&
|
||||
descriptor.isFromJvmPackagePart() &&
|
||||
facadeFqName == JvmFileClassUtil.getPartFqNameForDeserialized(descriptor)
|
||||
fun testConsistency() {
|
||||
for ((packageFacadeFqName, topLevelMembers) in listOf(
|
||||
FqName("kotlin.collections.CollectionsKt") to "mutableListOf",
|
||||
FqName("kotlin.collections.TypeAliasesKt") to null
|
||||
)) {
|
||||
val classId = ClassId.topLevel(packageFacadeFqName)
|
||||
val classFile = JvmVirtualFileFinder.SERVICE.getInstance(project).findVirtualFileWithHeader(classId)!!
|
||||
|
||||
val module = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
project, listOf(), BindingTraceContext(), KotlinTestUtils.newConfiguration(), ::IDEPackagePartProvider
|
||||
).moduleDescriptor
|
||||
|
||||
val projectBasedText = buildDecompiledTextForClassFile(classFile, ResolverForDecompilerImpl(module)).text
|
||||
val deserializedText = buildDecompiledTextForClassFile(classFile).text
|
||||
Assert.assertEquals(projectBasedText, deserializedText)
|
||||
|
||||
// sanity checks
|
||||
if (topLevelMembers != null) {
|
||||
Assert.assertTrue(topLevelMembers in projectBasedText)
|
||||
}
|
||||
|
||||
Assert.assertFalse("ERROR" in projectBasedText)
|
||||
}
|
||||
}
|
||||
|
||||
private inner class ResolverForDecompilerImpl(val module: ModuleDescriptor) : ResolverForDecompiler {
|
||||
override fun resolveTopLevelClass(classId: ClassId): ClassDescriptor? =
|
||||
module.resolveTopLevelClass(classId.asSingleFqName(), NoLookupLocation.FROM_TEST)
|
||||
|
||||
override fun resolveDeclarationsInFacade(facadeFqName: FqName): List<DeclarationDescriptor> =
|
||||
module.getPackage(facadeFqName.parent()).memberScope.getContributedDescriptors().filter { descriptor ->
|
||||
(descriptor is MemberDescriptor && descriptor !is ClassDescriptor && isFromFacade(descriptor, facadeFqName)) &&
|
||||
!KotlinBuiltIns.isBuiltIn(descriptor)
|
||||
}.sortedWith(MemberComparator.INSTANCE)
|
||||
|
||||
private fun isFromFacade(descriptor: MemberDescriptor, facadeFqName: FqName): Boolean =
|
||||
descriptor is DeserializedMemberDescriptor &&
|
||||
descriptor.isFromJvmPackagePart() &&
|
||||
facadeFqName == JvmFileClassUtil.getPartFqNameForDeserialized(descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.js.buildDecompiledTextFromJsMetadata
|
||||
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
class KotlinJavaScriptDecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
||||
override fun getPackages(): List<FqName> = listOf(
|
||||
"jquery", "jquery.ui", "kotlin", "kotlin.collections", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
||||
).map { FqName(it) }
|
||||
|
||||
override fun getTopLevelMembers(): Map<String, String> = mapOf("kotlin" to "intArrayOf")
|
||||
|
||||
override fun getVirtualFileFinder(): VirtualFileFinder = JsVirtualFileFinder.SERVICE.getInstance(project)
|
||||
|
||||
override fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler?): String =
|
||||
// TODO: use resolver here
|
||||
buildDecompiledTextFromJsMetadata(packageFile).text
|
||||
|
||||
override fun getModuleDescriptor(): ModuleDescriptor {
|
||||
val stdlibJar = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath.absolutePath
|
||||
val module = KotlinTestUtils.createEmptyModule("<module for stdlib>", JsPlatform.builtIns)
|
||||
val metadata = KotlinJavascriptMetadataUtils.loadMetadata(stdlibJar)
|
||||
assert(metadata.size == 1)
|
||||
|
||||
val provider = KotlinJavascriptSerializationUtil.readModule(
|
||||
metadata.single().body, LockBasedStorageManager(), module, DeserializationConfiguration.Default
|
||||
).data.sure { "No package fragment provider was created" }
|
||||
|
||||
module.initialize(provider)
|
||||
module.setDependencies(module, module.builtIns.builtInsModule)
|
||||
|
||||
return module
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = KotlinStdJSProjectDescriptor.instance
|
||||
|
||||
override fun isFromFacade(descriptor: MemberDescriptor, facadeFqName: FqName): Boolean {
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
return containingDeclaration is PackageFragmentDescriptor &&
|
||||
facadeFqName == OldPackageFacadeClassUtils.getPackageClassFqName(containingDeclaration.fqName)
|
||||
}
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.junit.Assert
|
||||
|
||||
abstract class TextConsistencyBaseTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
protected abstract fun getPackages(): List<FqName>
|
||||
|
||||
protected open fun getFacades(): List<FqName> = emptyList()
|
||||
|
||||
protected abstract fun getTopLevelMembers(): Map<String, String>
|
||||
|
||||
protected abstract fun getVirtualFileFinder(): VirtualFileFinder
|
||||
|
||||
protected abstract fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler? = null): String
|
||||
|
||||
protected abstract fun getModuleDescriptor(): ModuleDescriptor
|
||||
|
||||
protected abstract fun isFromFacade(descriptor: MemberDescriptor, facadeFqName: FqName): Boolean
|
||||
|
||||
fun testConsistency() {
|
||||
getPackages().forEach { doTestPackage(it) }
|
||||
getFacades().forEach { doTestFacade(it) }
|
||||
}
|
||||
|
||||
private fun doTestPackage(packageFqName: FqName) {
|
||||
doTestClass(packageFqName, OldPackageFacadeClassUtils.getPackageClassId(packageFqName))
|
||||
}
|
||||
|
||||
private fun doTestFacade(facadeFqName: FqName) {
|
||||
doTestClass(facadeFqName, ClassId.topLevel(facadeFqName))
|
||||
}
|
||||
|
||||
private fun doTestClass(testFqName: FqName, classId: ClassId) {
|
||||
val classFile = getVirtualFileFinder().findVirtualFileWithHeader(classId)!!
|
||||
val projectBasedText = getDecompiledText(classFile, ResolverForDecompilerImpl(getModuleDescriptor()))
|
||||
val deserializedText = getDecompiledText(classFile)
|
||||
Assert.assertEquals(projectBasedText, deserializedText)
|
||||
// sanity checks
|
||||
getTopLevelMembers()[testFqName.asString()]?.let {
|
||||
Assert.assertTrue(projectBasedText.contains(it))
|
||||
}
|
||||
Assert.assertFalse(projectBasedText.contains("ERROR"))
|
||||
}
|
||||
|
||||
private inner class ResolverForDecompilerImpl(val module: ModuleDescriptor) : ResolverForDecompiler {
|
||||
override fun resolveTopLevelClass(classId: ClassId): ClassDescriptor? =
|
||||
module.resolveTopLevelClass(classId.asSingleFqName(), NoLookupLocation.FROM_TEST)
|
||||
|
||||
override fun resolveDeclarationsInFacade(facadeFqName: FqName): List<DeclarationDescriptor> =
|
||||
module.getPackage(facadeFqName.parent()).memberScope.getContributedDescriptors().filter {
|
||||
(it is MemberDescriptor && it !is ClassDescriptor && isFromFacade(it, facadeFqName)) &&
|
||||
!KotlinBuiltIns.isBuiltIn(it)
|
||||
}.sortedWith(MemberComparator.INSTANCE)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user