Approximating flexible types in decompiled text
This commit is contained in:
@@ -30,6 +30,8 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumEntry
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils.isSyntheticClassObject
|
||||
import org.jetbrains.jet.lang.types.error.MissingDependencyErrorClass
|
||||
import org.jetbrains.jet.lang.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.lang.types.isFlexible
|
||||
|
||||
public fun buildDecompiledText(
|
||||
classFile: VirtualFile,
|
||||
@@ -53,9 +55,12 @@ public fun buildDecompiledText(
|
||||
}
|
||||
|
||||
private val DECOMPILED_COMMENT = "/* compiled code */"
|
||||
private val FLEXIBLE_TYPE_COMMENT = "/* platform type */"
|
||||
|
||||
public val descriptorRendererForDecompiler: DescriptorRenderer = DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setClassWithPrimaryConstructor(true)
|
||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
||||
.build()
|
||||
|
||||
//TODO: should use more accurate way to identify descriptors
|
||||
@@ -99,6 +104,13 @@ private fun buildDecompiledText(packageFqName: FqName, descriptors: List<Declara
|
||||
builder.append(header)
|
||||
var endOffset = builder.length()
|
||||
|
||||
if (descriptor is CallableDescriptor) {
|
||||
//NOTE: assuming that only return types can be flexible
|
||||
if (descriptor.getReturnType().isFlexible()) {
|
||||
builder.append(" ").append(FLEXIBLE_TYPE_COMMENT)
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor is FunctionDescriptor || descriptor is PropertyDescriptor) {
|
||||
if ((descriptor as MemberDescriptor).getModality() != Modality.ABSTRACT) {
|
||||
if (descriptor is FunctionDescriptor) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// IntelliJ API Decompiler stub source generated from a class file
|
||||
// Implementation of methods is not available
|
||||
|
||||
package test
|
||||
|
||||
internal abstract class FlexibleTypes() {
|
||||
internal abstract val p: kotlin.Int? /* platform type */
|
||||
|
||||
internal abstract fun collection(): kotlin.List<kotlin.Any> /* platform type */
|
||||
|
||||
internal final fun withBody(): kotlin.Int? /* platform type */ { /* compiled code */ }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
import kotlin.internal.flexible.ft
|
||||
|
||||
abstract class FlexibleTypes() {
|
||||
abstract fun collection(): ft<List<Int>, List<Any>>
|
||||
|
||||
abstract val p: ft<Int, Int?>
|
||||
|
||||
fun withBody(): ft<Int, Int?> { return 1 }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package kotlin.internal.flexible
|
||||
|
||||
class ft<L, U>
|
||||
@@ -61,6 +61,12 @@ public class DecompiledTextTestGenerated extends AbstractDecompiledTextTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FlexibleTypes")
|
||||
public void testFlexibleTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/libraries/decompiledText/FlexibleTypes/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionTypes")
|
||||
public void testFunctionTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/libraries/decompiledText/FunctionTypes/");
|
||||
|
||||
Reference in New Issue
Block a user