From c0a031eafe791abed51c442274bdca8d7f888ee8 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 12 Mar 2015 13:06:38 +0300 Subject: [PATCH] Support secondary constructors in decompiled text Build cls stubs for secondary constructors --- .../stubs/elements/JetFileElementType.java | 2 +- .../renderer/DescriptorRendererBuilder.java | 12 ++- .../renderer/DescriptorRendererImpl.java | 22 +++-- .../stubBuilder/CallableClsStubBuilder.kt | 41 ++++---- .../stubBuilder/ClassClsStubBuilder.kt | 5 +- .../textBuilder/DecompiledTextFactory.kt | 5 +- .../SecondaryConstructors.expected.kt | 20 ++++ .../SecondaryConstructors.kt | 27 ++++++ .../SecondaryConstructors.kt | 27 ++++++ .../SecondaryConstructors.txt | 95 +++++++++++++++++++ .../stubs/SecondaryConstructors.expected | 78 +++++++++++++++ idea/testData/stubs/SecondaryConstructors.kt | 27 ++++++ .../ClsStubBuilderTestGenerated.java | 6 ++ .../DecompiledTextTestGenerated.java | 6 ++ .../idea/stubs/StubBuilderTestGenerated.java | 6 ++ 15 files changed, 351 insertions(+), 28 deletions(-) create mode 100644 idea/testData/decompiler/decompiledText/SecondaryConstructors.expected.kt create mode 100644 idea/testData/decompiler/decompiledText/SecondaryConstructors/SecondaryConstructors.kt create mode 100644 idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.kt create mode 100644 idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.txt create mode 100644 idea/testData/stubs/SecondaryConstructors.expected create mode 100644 idea/testData/stubs/SecondaryConstructors.kt 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 b8005d7f706..45fd858984f 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 = 38; + public static final int STUB_VERSION = 39; private static final String NAME = "kotlin.FILE"; diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererBuilder.java b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererBuilder.java index 30024827f14..8f20a742de5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererBuilder.java +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererBuilder.java @@ -53,6 +53,7 @@ public class DescriptorRendererBuilder { }; private boolean renderDefaultValues = true; private boolean flexibleTypesForCode = false; + private boolean secondaryConstructorsAsPrimary = true; @NotNull private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN; @@ -211,6 +212,7 @@ public class DescriptorRendererBuilder { return this; } + @NotNull public DescriptorRendererBuilder setRenderDefaultValues(boolean renderDefaultValues) { this.renderDefaultValues = renderDefaultValues; return this; @@ -222,11 +224,18 @@ public class DescriptorRendererBuilder { return this; } + @NotNull public DescriptorRendererBuilder setFlexibleTypesForCode(boolean flexibleTypesForCode) { this.flexibleTypesForCode = flexibleTypesForCode; return this; } + @NotNull + public DescriptorRendererBuilder setSecondaryConstructorsAsPrimary(boolean secondaryConstructorsAsPrimary) { + this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary; + return this; + } + @NotNull public DescriptorRenderer build() { return new DescriptorRendererImpl( @@ -234,7 +243,8 @@ public class DescriptorRendererBuilder { normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName, overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant, includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName, - renderDefaultObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode); + renderDefaultObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode, + secondaryConstructorsAsPrimary); } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.java b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.java index 8d42bdecd3f..7c3678c5263 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.java @@ -76,6 +76,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer { @NotNull private final TextFormat textFormat; private final boolean includePropertyConstant; + private final boolean secondaryConstructorsAsPrimary; @NotNull private final Set excludedAnnotationClasses; @@ -105,7 +106,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer { boolean withoutSuperTypes, @NotNull Function1 typeNormalizer, boolean renderDefaultValues, - boolean flexibleTypesForCode + boolean flexibleTypesForCode, + boolean secondaryConstructorsAsPrimary ) { this.nameShortness = nameShortness; this.withDefinedIn = withDefinedIn; @@ -121,6 +123,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer { this.debugMode = debugMode; this.textFormat = textFormat; this.includePropertyConstant = includePropertyConstant; + this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary; this.excludedAnnotationClasses = new HashSet(excludedAnnotationClasses); this.prettyFunctionTypes = prettyFunctionTypes; this.uninferredTypeParameterAsName = uninferredTypeParameterAsName; @@ -802,14 +805,19 @@ public class DescriptorRendererImpl implements DescriptorRenderer { renderVisibility(constructor.getVisibility(), builder); renderMemberKind(constructor, builder); - builder.append(renderKeyword("constructor")).append(" "); + builder.append(renderKeyword("constructor")); + if (secondaryConstructorsAsPrimary) { + ClassDescriptor classDescriptor = constructor.getContainingDeclaration(); + builder.append(" "); + renderName(classDescriptor, builder); + renderTypeParameters(classDescriptor.getTypeConstructor().getParameters(), builder, false); + } - ClassDescriptor classDescriptor = constructor.getContainingDeclaration(); - renderName(classDescriptor, builder); - - renderTypeParameters(classDescriptor.getTypeConstructor().getParameters(), builder, false); renderValueParameters(constructor, builder); - renderWhereSuffix(constructor.getTypeParameters(), builder); + + if (secondaryConstructorsAsPrimary) { + renderWhereSuffix(constructor.getTypeParameters(), builder); + } } private void renderWhereSuffix(@NotNull List typeParameters, @NotNull StringBuilder builder) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt index f623205a816..5658b176f38 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt @@ -16,19 +16,23 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder -import com.intellij.psi.stubs.StubElement import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.serialization.ProtoBuf -import org.jetbrains.kotlin.serialization.Flags -import org.jetbrains.kotlin.serialization.ProtoBuf.Modality +import com.intellij.psi.stubs.StubElement +import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.MODALITY +import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.VISIBILITY +import org.jetbrains.kotlin.psi.JetSecondaryConstructor +import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl +import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyStubImpl -import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.CallableKind -import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer -import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.MemberKind import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike +import org.jetbrains.kotlin.serialization.Flags +import org.jetbrains.kotlin.serialization.ProtoBuf +import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.CallableKind +import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.MemberKind +import org.jetbrains.kotlin.serialization.ProtoBuf.Modality import org.jetbrains.kotlin.serialization.deserialization.NameResolver -import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.* +import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer fun createCallableStub( parentStub: StubElement, @@ -60,11 +64,14 @@ private class CallableClsStubBuilder( private val c = outerContext.child(callableProto.getTypeParameterList()) private val typeStubBuilder = TypeClsStubBuilder(c) private val isTopLevel: Boolean get() = protoContainer.packageFqName != null + private val callableKind = Flags.CALLABLE_KIND[callableProto.getFlags()] + private val isConstructor = callableKind == ProtoBuf.Callable.CallableKind.CONSTRUCTOR private val callableStub = doCreateCallableStub() fun build() { createModifierListStub() - val typeConstraintListData = typeStubBuilder.createTypeParameterListStub(callableStub, callableProto.getTypeParameterList()) + val typeParameterList = if (isConstructor) emptyList() else callableProto.getTypeParameterList() + val typeConstraintListData = typeStubBuilder.createTypeParameterListStub(callableStub, typeParameterList) createReceiverTypeReferenceStub() createValueParameterList() createReturnTypeStub() @@ -82,11 +89,13 @@ private class CallableClsStubBuilder( } private fun createReturnTypeStub() { - typeStubBuilder.createTypeReferenceStub(callableStub, callableProto.getReturnType()) + if (!isConstructor) + typeStubBuilder.createTypeReferenceStub(callableStub, callableProto.getReturnType()) } private fun createModifierListStub() { - val relevantModifiers = if (isTopLevel) listOf(VISIBILITY) else listOf(VISIBILITY, MODALITY) + val isModalityIrrelevant = isTopLevel || isConstructor + val relevantModifiers = if (isModalityIrrelevant) listOf(VISIBILITY) else listOf(VISIBILITY, MODALITY) val modifierListStubImpl = createModifierListStubForDeclaration(callableStub, callableProto.getFlags(), relevantModifiers) val annotationIds = c.components.annotationLoader.loadCallableAnnotations( @@ -96,9 +105,7 @@ private class CallableClsStubBuilder( } private fun doCreateCallableStub(): StubElement { - val callableKind = Flags.CALLABLE_KIND[callableProto.getFlags()] val callableName = c.nameResolver.getName(callableProto.getName()) - val callableFqName = c.containerFqName.child(callableName) return when (callableKind) { ProtoBuf.Callable.CallableKind.FUN -> { @@ -106,7 +113,7 @@ private class CallableClsStubBuilder( parent, callableName.ref(), isTopLevel, - callableFqName, + c.containerFqName.child(callableName), isExtension = callableProto.hasReceiverType(), hasBlockBody = true, hasBody = Flags.MODALITY[callableProto.getFlags()] != Modality.ABSTRACT, @@ -125,11 +132,13 @@ private class CallableClsStubBuilder( hasInitializer = false, hasReceiverTypeRef = callableProto.hasReceiverType(), hasReturnTypeRef = true, - fqName = callableFqName, + fqName = c.containerFqName.child(callableName), isProbablyNothingType = isProbablyNothing(callableProto) ) } - ProtoBuf.Callable.CallableKind.CONSTRUCTOR -> throw IllegalStateException("Should not be called for constructor!") + ProtoBuf.Callable.CallableKind.CONSTRUCTOR -> { + KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.SECONDARY_CONSTRUCTOR) + } else -> throw IllegalStateException("Unknown callable kind $callableKind") } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt index 7d82ac46882..06784f17e32 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt @@ -135,7 +135,7 @@ private class ClassClsStubBuilder( } private fun createConstructorStub() { - if (!isClass()) return + if (!isClass() || !classProto.hasPrimaryConstructor()) return val primaryConstructorProto = classProto.getPrimaryConstructor() if (primaryConstructorProto.hasData()) { @@ -198,7 +198,8 @@ private class ClassClsStubBuilder( private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl) { val container = ProtoContainer(classProto, null) - for (callableProto in classProto.getMemberList()) { + val allMembers = classProto.getSecondaryConstructorList() + classProto.getMemberList() + for (callableProto in allMembers) { createCallableStub(classBody, callableProto, c, container) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt index f856d6d62dc..1de42f53cbe 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.types.isFlexible import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind import org.jetbrains.kotlin.load.kotlin.header.isCompatibleClassKind +import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors import org.jetbrains.kotlin.types.flexibility private val FILE_ABI_VERSION_MARKER: String = "FILE_ABI" @@ -85,6 +86,7 @@ private val descriptorRendererForDecompiler = DescriptorRendererBuilder() else type } + .setSecondaryConstructorsAsPrimary(false) .build() private val descriptorRendererForKeys = DescriptorRenderer.COMPACT_WITH_MODIFIERS @@ -153,7 +155,8 @@ private fun buildDecompiledText(packageFqName: FqName, descriptors: List where G : kotlin.Number { + public constructor(x: T, g: G) { /* compiled code */ } + } + + internal final class Nested { + test.anno public constructor(z: kotlin.Int) { /* compiled code */ } + + internal constructor() { /* compiled code */ } + } +} \ No newline at end of file diff --git a/idea/testData/decompiler/decompiledText/SecondaryConstructors/SecondaryConstructors.kt b/idea/testData/decompiler/decompiledText/SecondaryConstructors/SecondaryConstructors.kt new file mode 100644 index 00000000000..7ee8627aeed --- /dev/null +++ b/idea/testData/decompiler/decompiledText/SecondaryConstructors/SecondaryConstructors.kt @@ -0,0 +1,27 @@ +package test + +class SecondaryConstructors(x: Boolean) { + init { + } + + anno constructor(x: String) : this(x == "abc") { + } + + init { + } + + private constructor(x: Int) : this(x < 0) { + } + + inner class Inner where G : Number { + constructor(x: T, g: G) { + } + } + + class Nested { + anno constructor(z: Int) {} + internal constructor() {} + } +} + +annotation class anno \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.kt b/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.kt new file mode 100644 index 00000000000..7ee8627aeed --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.kt @@ -0,0 +1,27 @@ +package test + +class SecondaryConstructors(x: Boolean) { + init { + } + + anno constructor(x: String) : this(x == "abc") { + } + + init { + } + + private constructor(x: Int) : this(x < 0) { + } + + inner class Inner where G : Number { + constructor(x: T, g: G) { + } + } + + class Nested { + anno constructor(z: Int) {} + internal constructor() {} + } +} + +annotation class anno \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.txt b/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.txt new file mode 100644 index 00000000000..22d9d611adb --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/SecondaryConstructors/SecondaryConstructors.txt @@ -0,0 +1,95 @@ +PsiJetFileStubImpl[package=test] + PACKAGE_DIRECTIVE: + REFERENCE_EXPRESSION:[referencedName=test] + CLASS:[fqName=test.SecondaryConstructors, isEnumEntry=false, isLocal=false, isTopLevel=true, isTrait=false, name=SecondaryConstructors, superNames=[]] + MODIFIER_LIST:[internal final] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Boolean] + CLASS_BODY: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=anno] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=test] + REFERENCE_EXPRESSION:[referencedName=anno] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=String] + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[private] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + CLASS:[fqName=test.SecondaryConstructors.Inner, isEnumEntry=false, isLocal=false, isTopLevel=false, isTrait=false, name=Inner, superNames=[]] + MODIFIER_LIST:[inner internal final] + TYPE_PARAMETER_LIST: + TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=T] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=String] + TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=G] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + TYPE_CONSTRAINT_LIST: + TYPE_CONSTRAINT:[isDefaultObjectConstraint=false] + REFERENCE_EXPRESSION:[referencedName=G] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Number] + CLASS_BODY: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=g] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=G] + CLASS:[fqName=test.SecondaryConstructors.Nested, isEnumEntry=false, isLocal=false, isTopLevel=false, isTrait=false, name=Nested, superNames=[]] + MODIFIER_LIST:[internal final] + CLASS_BODY: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=anno] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=test] + REFERENCE_EXPRESSION:[referencedName=anno] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=z] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[internal] + VALUE_PARAMETER_LIST: diff --git a/idea/testData/stubs/SecondaryConstructors.expected b/idea/testData/stubs/SecondaryConstructors.expected new file mode 100644 index 00000000000..2d95664715c --- /dev/null +++ b/idea/testData/stubs/SecondaryConstructors.expected @@ -0,0 +1,78 @@ +PsiJetFileStubImpl[package=test] + PACKAGE_DIRECTIVE: + REFERENCE_EXPRESSION:[referencedName=test] + CLASS:[fqName=test.SecondaryConstructors, isEnumEntry=false, isLocal=false, isTopLevel=true, isTrait=false, name=SecondaryConstructors, superNames=[]] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Boolean] + CLASS_BODY: + ANONYMOUS_INITIALIZER: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=anno] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=anno] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=String] + ANONYMOUS_INITIALIZER: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[private] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] + CLASS:[fqName=test.SecondaryConstructors.Inner, isEnumEntry=false, isLocal=false, isTopLevel=false, isTrait=false, name=Inner, superNames=[]] + MODIFIER_LIST:[inner] + TYPE_PARAMETER_LIST: + TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=T] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=String] + TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=G] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] + TYPE_CONSTRAINT_LIST: + TYPE_CONSTRAINT:[isDefaultObjectConstraint=false] + REFERENCE_EXPRESSION:[referencedName=G] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Number] + CLASS_BODY: + SECONDARY_CONSTRUCTOR: + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=x] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=g] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=G] + CLASS:[fqName=test.SecondaryConstructors.Nested, isEnumEntry=false, isLocal=false, isTopLevel=false, isTrait=false, name=Nested, superNames=[]] + CLASS_BODY: + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=anno] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=anno] + VALUE_PARAMETER_LIST: + VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=z] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] + SECONDARY_CONSTRUCTOR: + MODIFIER_LIST:[internal] + VALUE_PARAMETER_LIST: + CLASS:[fqName=test.anno, isEnumEntry=false, isLocal=false, isTopLevel=true, isTrait=false, name=anno, superNames=[]] + MODIFIER_LIST:[annotation] diff --git a/idea/testData/stubs/SecondaryConstructors.kt b/idea/testData/stubs/SecondaryConstructors.kt new file mode 100644 index 00000000000..7ee8627aeed --- /dev/null +++ b/idea/testData/stubs/SecondaryConstructors.kt @@ -0,0 +1,27 @@ +package test + +class SecondaryConstructors(x: Boolean) { + init { + } + + anno constructor(x: String) : this(x == "abc") { + } + + init { + } + + private constructor(x: Int) : this(x < 0) { + } + + inner class Inner where G : Number { + constructor(x: T, g: G) { + } + } + + class Nested { + anno constructor(z: Int) {} + internal constructor() {} + } +} + +annotation class anno \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java index 019dd2a1219..6bb55c70967 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java @@ -120,6 +120,12 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest { doTest(fileName); } + @TestMetadata("SecondaryConstructors") + public void testSecondaryConstructors() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/SecondaryConstructors/"); + doTest(fileName); + } + @TestMetadata("TopLevelMembersAnnotatedPackage") public void testTopLevelMembersAnnotatedPackage() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/TopLevelMembersAnnotatedPackage/"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextTestGenerated.java index e7eab3e8fb8..fa302ae77ce 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextTestGenerated.java @@ -86,6 +86,12 @@ public class DecompiledTextTestGenerated extends AbstractDecompiledTextTest { doTest(fileName); } + @TestMetadata("SecondaryConstructors") + public void testSecondaryConstructors() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SecondaryConstructors/"); + doTest(fileName); + } + @TestMetadata("SimpleClass") public void testSimpleClass() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SimpleClass/"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/StubBuilderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/stubs/StubBuilderTestGenerated.java index e1193b8e53d..d0073362c1b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/StubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/StubBuilderTestGenerated.java @@ -216,6 +216,12 @@ public class StubBuilderTestGenerated extends AbstractStubBuilderTest { doTest(fileName); } + @TestMetadata("SecondaryConstructors.kt") + public void testSecondaryConstructors() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/stubs/SecondaryConstructors.kt"); + doTest(fileName); + } + @TestMetadata("SimpleEnumBuild.kt") public void testSimpleEnumBuild() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/stubs/SimpleEnumBuild.kt");