From 9a9d70fd98120069992dd05121ddd6520c2fdc33 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 30 Jun 2015 20:45:20 +0300 Subject: [PATCH] Decompiler: do not try to render function types with star projections prettily --- .../stubs/elements/JetFileElementType.java | 2 +- .../kotlin/renderer/DescriptorRendererImpl.kt | 3 +- .../stubBuilder/TypeClsStubBuilder.kt | 4 +- .../decompiledText/FunctionTypes.expected.kt | 8 ++ .../FunctionTypes/FunctionTypes.kt | 12 +++ .../decompiler/stubBuilder/Types/Types.kt | 6 ++ .../decompiler/stubBuilder/Types/Types.txt | 73 +++++++++++++++++++ 7 files changed, 105 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetFileElementType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetFileElementType.java index b70839aa584..5a4320a31f5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetFileElementType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetFileElementType.java @@ -36,7 +36,7 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinFileStubImpl; import java.io.IOException; public class JetFileElementType extends IStubFileElementType { - public static final int STUB_VERSION = 48; + public static final int STUB_VERSION = 49; private static final String NAME = "kotlin.FILE"; diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index e2457d90830..6678fa46a11 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -199,7 +199,8 @@ internal class DescriptorRendererImpl( } private fun shouldRenderAsPrettyFunctionType(type: JetType): Boolean { - return KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && prettyFunctionTypes + return prettyFunctionTypes && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) + && type.getArguments().none { it.isStarProjection() } } private fun renderFlexibleType(type: JetType): String { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index eefb572a9ef..66ae2034b30 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -77,7 +77,9 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { } val classId = c.nameResolver.getClassId(type.getConstructor().getId()) - if (KotlinBuiltIns.isNumberedFunctionClassFqName(classId.asSingleFqName().toUnsafe())) { + val shouldBuildAsFunctionType = KotlinBuiltIns.isNumberedFunctionClassFqName(classId.asSingleFqName().toUnsafe()) + && type.getArgumentList().none { it.getProjection() == Projection.STAR } + if (shouldBuildAsFunctionType) { val extension = annotations.any { annotation -> annotation.asSingleFqName() == KotlinBuiltIns.FQ_NAMES.extension } createFunctionTypeStub(parent, type, extension) return diff --git a/idea/testData/decompiler/decompiledText/FunctionTypes.expected.kt b/idea/testData/decompiler/decompiledText/FunctionTypes.expected.kt index f18c7e21044..6b138f0dc77 100644 --- a/idea/testData/decompiler/decompiledText/FunctionTypes.expected.kt +++ b/idea/testData/decompiler/decompiledText/FunctionTypes.expected.kt @@ -4,6 +4,14 @@ package test internal final class FunctionTypes public constructor() { + public final fun f1(f: kotlin.Function1<*, *>): kotlin.Unit { /* compiled code */ } + + public final fun f2(f: kotlin.Function2): kotlin.Unit { /* compiled code */ } + + public final fun f3(f: kotlin.Int.(kotlin.Int) -> kotlin.Unit): kotlin.Unit { /* compiled code */ } + + public final fun f4(f: kotlin.List>): kotlin.Unit { /* compiled code */ } + public final fun (A.(A) -> A)?.bar(): kotlin.Unit { /* compiled code */ } public final fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R { /* compiled code */ } diff --git a/idea/testData/decompiler/decompiledText/FunctionTypes/FunctionTypes.kt b/idea/testData/decompiler/decompiledText/FunctionTypes/FunctionTypes.kt index 2e944fc4368..8bb9dc0b7a1 100644 --- a/idea/testData/decompiler/decompiledText/FunctionTypes/FunctionTypes.kt +++ b/idea/testData/decompiler/decompiledText/FunctionTypes/FunctionTypes.kt @@ -14,4 +14,16 @@ class FunctionTypes { public fun (A.(A) -> A)?.bar() { } + + public fun f1(f: Function1<*, *>) { + } + + public fun f2(f: Function2) { + } + + public fun f3(f: @extension Function2) { + } + + public fun f4(f: List<@extension Function1<*, *>>) { + } } diff --git a/idea/testData/decompiler/stubBuilder/Types/Types.kt b/idea/testData/decompiler/stubBuilder/Types/Types.kt index aa433b3a398..ace2bbb3e8c 100644 --- a/idea/testData/decompiler/stubBuilder/Types/Types.kt +++ b/idea/testData/decompiler/stubBuilder/Types/Types.kt @@ -16,4 +16,10 @@ abstract class Types { public fun Function3.extOnFunctionType() { } + + abstract val starList: List<*> + abstract val starFun: Function1<*, *> + abstract val extFun: @extension Function2 + abstract val listExtStarFun: List<@extension Function1<*, *>> + abstract val funTypeWithStarAndNonStar: Function1<*, Int> } \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/Types/Types.txt b/idea/testData/decompiler/stubBuilder/Types/Types.txt index d46bda4d0b3..29b658a0207 100644 --- a/idea/testData/decompiler/stubBuilder/Types/Types.txt +++ b/idea/testData/decompiler/stubBuilder/Types/Types.txt @@ -55,6 +55,28 @@ PsiJetFileStubImpl[package=test] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] REFERENCE_EXPRESSION:[referencedName=String] + PROPERTY:[fqName=test.Types.extFun, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=extFun] + MODIFIER_LIST:[abstract internal] + TYPE_REFERENCE: + FUNCTION_TYPE: + FUNCTION_TYPE_RECEIVER: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Unit] PROPERTY:[fqName=test.Types.extFunction, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=extFunction] MODIFIER_LIST:[abstract internal] TYPE_REFERENCE: @@ -152,6 +174,21 @@ PsiJetFileStubImpl[package=test] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] REFERENCE_EXPRESSION:[referencedName=String] + PROPERTY:[fqName=test.Types.funTypeWithStarAndNonStar, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=funTypeWithStarAndNonStar] + MODIFIER_LIST:[abstract internal] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Function1] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=STAR] + TYPE_PROJECTION:[projectionKind=NONE] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] PROPERTY:[fqName=test.Types.function, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=function] MODIFIER_LIST:[internal final] TYPE_REFERENCE: @@ -205,6 +242,23 @@ PsiJetFileStubImpl[package=test] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] REFERENCE_EXPRESSION:[referencedName=Int] + PROPERTY:[fqName=test.Types.listExtStarFun, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=listExtStarFun] + MODIFIER_LIST:[abstract internal] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=List] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=NONE] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Function1] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=STAR] + TYPE_PROJECTION:[projectionKind=STAR] PROPERTY:[fqName=test.Types.map, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=map] MODIFIER_LIST:[abstract internal] TYPE_REFERENCE: @@ -278,6 +332,25 @@ PsiJetFileStubImpl[package=test] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] REFERENCE_EXPRESSION:[referencedName=String] + PROPERTY:[fqName=test.Types.starFun, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=starFun] + MODIFIER_LIST:[abstract internal] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Function1] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=STAR] + TYPE_PROJECTION:[projectionKind=STAR] + PROPERTY:[fqName=test.Types.starList, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=starList] + MODIFIER_LIST:[abstract internal] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=List] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=STAR] FUN:[fqName=test.Types.extOnFunctionType, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=extOnFunctionType] MODIFIER_LIST:[public final] TYPE_PARAMETER_LIST: