Skip to content

Commit

Permalink
KT-37144 Respect quotes in package name during decompilation
Browse files Browse the repository at this point in the history
- 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

(cherry picked from commit d766720)
  • Loading branch information
fedochet authored and erokhins committed Apr 13, 2020
1 parent 1f76edc commit 398d8a9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
Expand Down Expand Up @@ -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("\n\n")
if (!packageFqName.isRoot) {
builder.append("package ").append(packageFqName).append("\n\n")
builder.append("package ").append(packageFqName.quoteIfNeeded()).append("\n\n")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package `try`.`package`

class PackageWithQuotes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
try.package
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@ import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
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.KtClsFile
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.serializeToString
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
import org.junit.Assert
import java.nio.file.Paths
import kotlin.test.assertTrue

abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPackage: Boolean) :
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) {
val fileWithDecompiledText = KtPsiFactory(project).createFile(decompiledText)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 398d8a9

Please sign in to comment.