KT-37144 Respect quotes in package name during decompilation
- Odd package names (for example `try` in `arrow-core`) were pasted as-is to the decompiled text - Because of this, stub checks were failing, forcing completion to start over and over again, as if something changed in the files - See EA-5572315 for the error - ^KT-37144 Fixed
This commit is contained in:
committed by
Alexander Podkhalyuzin
parent
ec9c7c98cd
commit
d7667209b2
+2
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
|||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
|
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||||
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
|
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||||
@@ -46,7 +47,7 @@ fun buildDecompiledText(
|
|||||||
builder.append("// IntelliJ API Decompiler stub source generated from a class file\n" + "// Implementation of methods is not available")
|
builder.append("// IntelliJ API Decompiler stub source generated from a class file\n" + "// Implementation of methods is not available")
|
||||||
builder.append("\n\n")
|
builder.append("\n\n")
|
||||||
if (!packageFqName.isRoot) {
|
if (!packageFqName.isRoot) {
|
||||||
builder.append("package ").append(packageFqName).append("\n\n")
|
builder.append("package ").append(packageFqName.quoteIfNeeded()).append("\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// IntelliJ API Decompiler stub source generated from a class file
|
||||||
|
// Implementation of methods is not available
|
||||||
|
|
||||||
|
package `try`.`package`
|
||||||
|
|
||||||
|
public final class PackageWithQuotes public constructor() {
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package `try`.`package`
|
||||||
|
|
||||||
|
class PackageWithQuotes
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
try.package
|
||||||
+14
-1
@@ -12,17 +12,30 @@ import com.intellij.openapi.roots.OrderRootType
|
|||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.util.indexing.FileContentImpl
|
import com.intellij.util.indexing.FileContentImpl
|
||||||
|
import com.intellij.util.io.exists
|
||||||
|
import com.intellij.util.io.readText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClsStubBuilder
|
import org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClsStubBuilder
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
||||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.serializeToString
|
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.serializeToString
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
|
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
import java.nio.file.Paths
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPackage: Boolean) :
|
abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPackage: Boolean) :
|
||||||
AbstractDecompiledTextBaseTest(baseDirectory, allowKotlinPackage = allowKotlinPackage) {
|
AbstractDecompiledTextBaseTest(baseDirectory, allowKotlinPackage = allowKotlinPackage) {
|
||||||
override fun getFileToDecompile(): VirtualFile = getClassFile(TEST_PACKAGE, getTestName(false), module!!)
|
|
||||||
|
private val CUSTOM_PACKAGE_FILE = "package.txt"
|
||||||
|
|
||||||
|
override fun getFileToDecompile(): VirtualFile {
|
||||||
|
val className = getTestName(false)
|
||||||
|
|
||||||
|
val customPackageFile = Paths.get(TEST_DATA_PATH, className, CUSTOM_PACKAGE_FILE)
|
||||||
|
val testFilePackage = customPackageFile.takeIf { it.exists() }?.readText()?.trimEnd() ?: TEST_PACKAGE
|
||||||
|
|
||||||
|
return getClassFile(testFilePackage, className, module!!)
|
||||||
|
}
|
||||||
|
|
||||||
override fun checkStubConsistency(file: VirtualFile, decompiledText: String) {
|
override fun checkStubConsistency(file: VirtualFile, decompiledText: String) {
|
||||||
val fileWithDecompiledText = KtPsiFactory(project).createFile(decompiledText)
|
val fileWithDecompiledText = KtPsiFactory(project).createFile(decompiledText)
|
||||||
|
|||||||
Generated
+18
@@ -43,6 +43,11 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
|
|||||||
runTest("idea/testData/decompiler/decompiledTextJvm/MultifileClass/");
|
runTest("idea/testData/decompiler/decompiledTextJvm/MultifileClass/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PackageWithQuotes")
|
||||||
|
public void testPackageWithQuotes() throws Exception {
|
||||||
|
runTest("idea/testData/decompiler/decompiledTextJvm/PackageWithQuotes/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("TestKt")
|
@TestMetadata("TestKt")
|
||||||
public void testTestKt() throws Exception {
|
public void testTestKt() throws Exception {
|
||||||
runTest("idea/testData/decompiler/decompiledTextJvm/TestKt/");
|
runTest("idea/testData/decompiler/decompiledTextJvm/TestKt/");
|
||||||
@@ -92,6 +97,19 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/PackageWithQuotes")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class PackageWithQuotes extends AbstractJvmDecompiledTextTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInPackageWithQuotes() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/decompiler/decompiledTextJvm/PackageWithQuotes"), Pattern.compile("^([^\\.]+)$"), null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/TestKt")
|
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/TestKt")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user