Fixed generated text from jvm classfile, when quotes is required

#KT-34759 Fixed
This commit is contained in:
Alexander Podkhalyuzin
2020-03-04 15:08:57 +03:00
parent 36ec0a2e2e
commit 5bb74d9840
4 changed files with 35 additions and 1 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.contracts.description.ContractProviderKey
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
@@ -62,7 +63,7 @@ fun buildDecompiledText(
builder.append(descriptorRenderer.renderAnnotation(annotation))
builder.append(" ")
}
builder.append(descriptor.name.asString())
builder.append(descriptor.name.asString().quoteIfNeeded())
builder.append(if (lastEnumEntry!!) ";" else ",")
} else {
builder.append(descriptorRenderer.render(descriptor).replace("= ...", DECOMPILED_COMMENT_FOR_PARAMETER))
@@ -0,0 +1,19 @@
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package test
public final class EnumWithQuotes public constructor() {
internal final class B public constructor() {
private final enum class Zoo private constructor() : kotlin.Enum<test.EnumWithQuotes.B.Zoo> {
Bear,
`Bear+`,
`Polar Bear`,
Panda;
}
}
}
@@ -0,0 +1,9 @@
package test
class EnumWithQuotes {
internal class B {
private enum class Zoo {
Bear, `Bear+`, `Polar Bear`, Panda
}
}
}
@@ -28,6 +28,11 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/decompiler/decompiledTextJvm"), Pattern.compile("^([^\\.]+)$"), null, true);
}
@TestMetadata("EnumWithQuotes")
public void testEnumWithQuotes() throws Exception {
runTest("idea/testData/decompiler/decompiledTextJvm/EnumWithQuotes/");
}
@TestMetadata("Modifiers")
public void testModifiers() throws Exception {
runTest("idea/testData/decompiler/decompiledTextJvm/Modifiers/");