diff --git a/compiler/testData/renderer/ObjectWithConstructor.kt b/compiler/testData/renderer/ObjectWithConstructor.kt index ff57fa5cd33..b32aaf29a34 100644 --- a/compiler/testData/renderer/ObjectWithConstructor.kt +++ b/compiler/testData/renderer/ObjectWithConstructor.kt @@ -29,7 +29,7 @@ class A3 { //value-parameter val y: kotlin.Int defined in A2. //public final class A3 defined in root package //public constructor A3() defined in A3 -//public companion object defined in A3 +//public companion object B defined in A3 //private constructor B(prop: kotlin.Int) defined in A3.B //value-parameter val prop: kotlin.Int defined in A3.B. //public constructor B() defined in A3.B diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 9b5d480cb72..c7ab2232a26 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.name.FqNameBase import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject import org.jetbrains.kotlin.resolve.constants.AnnotationValue @@ -106,7 +107,7 @@ internal class DescriptorRendererImpl( builder.append(renderName(containingDeclaration.getName())) } } - if (verbose) { + if (verbose || descriptor.name != SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) { if (!startFromName) renderSpaceIfNeeded(builder) builder.append(renderName(descriptor.getName())) } diff --git a/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject.expected.kt b/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject.expected.kt new file mode 100644 index 00000000000..58b55d81ccd --- /dev/null +++ b/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject.expected.kt @@ -0,0 +1,11 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +public final class ClassWithNamedClassObject public constructor() { + public companion object Named { + public final fun a(): kotlin.Unit { /* compiled code */ } + } +} + diff --git a/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject/ClassWithNamedClassObject.kt b/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject/ClassWithNamedClassObject.kt new file mode 100644 index 00000000000..da72981edae --- /dev/null +++ b/idea/testData/decompiler/decompiledText/ClassWithNamedClassObject/ClassWithNamedClassObject.kt @@ -0,0 +1,8 @@ +package test + +class ClassWithNamedClassObject { + companion object Named { + fun a() { + } + } +} diff --git a/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.kt b/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.kt new file mode 100644 index 00000000000..568f2af652c --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.kt @@ -0,0 +1,45 @@ +package test + +class NamedCompanionObject { + fun f() { + } + + val c = 1 + + public companion object Named { + val j = 0 + fun z() = 0 + + class A { + class B { + val i: Int = 0 + fun f() = 0 + } + } + } + + + class B { + companion object NamedInB { + class C { + companion object NamedInC { + class D { + companion object Companion { + val i = 3 + fun f() { + } + + enum class En { + A; + + companion object NamedInEn + } + + annotation class Anno + } + } + } + } + } + } +} \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.txt b/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.txt new file mode 100644 index 00000000000..f634410b424 --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/NamedCompanionObject/NamedCompanionObject.txt @@ -0,0 +1,172 @@ +PsiJetFileStubImpl[package=test] + PACKAGE_DIRECTIVE: + REFERENCE_EXPRESSION:[referencedName=test] + IMPORT_LIST: + CLASS:[fqName=test.NamedCompanionObject, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=NamedCompanionObject, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + OBJECT_DECLARATION:[fqName=test.NamedCompanionObject.Named, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Named, superNames=[]] + MODIFIER_LIST:[public companion] + CLASS_BODY: + PROPERTY:[fqName=test.NamedCompanionObject.Named.j, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=j] + MODIFIER_LIST:[public final] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + FUN:[fqName=test.NamedCompanionObject.Named.z, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=z] + MODIFIER_LIST:[public final] + VALUE_PARAMETER_LIST: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + CLASS:[fqName=test.NamedCompanionObject.Named.A, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=A, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + CLASS:[fqName=test.NamedCompanionObject.Named.A.B, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=B, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + PROPERTY:[fqName=test.NamedCompanionObject.Named.A.B.i, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=i] + MODIFIER_LIST:[public final] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + FUN:[fqName=test.NamedCompanionObject.Named.A.B.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + MODIFIER_LIST:[public final] + VALUE_PARAMETER_LIST: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + PROPERTY:[fqName=test.NamedCompanionObject.c, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=c] + MODIFIER_LIST:[public final] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + FUN:[fqName=test.NamedCompanionObject.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + MODIFIER_LIST:[public final] + VALUE_PARAMETER_LIST: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Unit] + CLASS:[fqName=test.NamedCompanionObject.B, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=B, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + OBJECT_DECLARATION:[fqName=test.NamedCompanionObject.B.NamedInB, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=NamedInB, superNames=[]] + MODIFIER_LIST:[public companion] + CLASS_BODY: + CLASS:[fqName=test.NamedCompanionObject.B.NamedInB.C, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=C, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + OBJECT_DECLARATION:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=NamedInC, superNames=[]] + MODIFIER_LIST:[public companion] + CLASS_BODY: + CLASS:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=D, superNames=[]] + MODIFIER_LIST:[public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + CLASS_BODY: + OBJECT_DECLARATION:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Companion, superNames=[]] + MODIFIER_LIST:[public companion] + CLASS_BODY: + PROPERTY:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.i, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=i] + MODIFIER_LIST:[public final] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Int] + FUN:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + MODIFIER_LIST:[public final] + VALUE_PARAMETER_LIST: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Unit] + CLASS:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.Anno, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=Anno, superNames=[Annotation]] + MODIFIER_LIST:[public final] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=annotation] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=annotation] + REFERENCE_EXPRESSION:[referencedName=annotation] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[public] + VALUE_PARAMETER_LIST: + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Annotation] + CLASS_BODY: + CLASS:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.En, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=En, superNames=[Enum]] + MODIFIER_LIST:[enum public final] + PRIMARY_CONSTRUCTOR: + MODIFIER_LIST:[private] + VALUE_PARAMETER_LIST: + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=kotlin] + REFERENCE_EXPRESSION:[referencedName=Enum] + TYPE_ARGUMENT_LIST: + TYPE_PROJECTION:[projectionKind=NONE] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=test] + REFERENCE_EXPRESSION:[referencedName=NamedCompanionObject] + REFERENCE_EXPRESSION:[referencedName=B] + REFERENCE_EXPRESSION:[referencedName=NamedInB] + REFERENCE_EXPRESSION:[referencedName=C] + REFERENCE_EXPRESSION:[referencedName=NamedInC] + REFERENCE_EXPRESSION:[referencedName=D] + REFERENCE_EXPRESSION:[referencedName=Companion] + REFERENCE_EXPRESSION:[referencedName=En] + CLASS_BODY: + ENUM_ENTRY:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.En.A, isEnumEntry=true, isInterface=false, isLocal=false, isTopLevel=false, name=A, superNames=[]] + OBJECT_DECLARATION:[fqName=test.NamedCompanionObject.B.NamedInB.C.NamedInC.D.Companion.En.NamedInEn, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=NamedInEn, superNames=[]] + MODIFIER_LIST:[public companion] + CLASS_BODY: diff --git a/idea/testData/stubs/ClassObject.expected b/idea/testData/stubs/ClassObject.expected index 30a375ab01c..b7ec6d3907a 100644 --- a/idea/testData/stubs/ClassObject.expected +++ b/idea/testData/stubs/ClassObject.expected @@ -8,3 +8,12 @@ PsiJetFileStubImpl[package=] CLASS_BODY: FUN:[fqName=C.Companion.foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=foo] VALUE_PARAMETER_LIST: + CLASS:[fqName=D, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=D, superNames=[]] + CLASS_BODY: + OBJECT_DECLARATION:[fqName=D.Named, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Named, superNames=[]] + MODIFIER_LIST:[companion] + CLASS_BODY: + PROPERTY:[fqName=D.Named.c, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=c] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] diff --git a/idea/testData/stubs/ClassObject.kt b/idea/testData/stubs/ClassObject.kt index be791bf12f8..6cf56230fc8 100644 --- a/idea/testData/stubs/ClassObject.kt +++ b/idea/testData/stubs/ClassObject.kt @@ -1,5 +1,12 @@ -class C { companion object { - fun foo() { +class C { + companion object { + fun foo() { + } } } + +class D { + companion object Named { + val c: Int + } } \ 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 a23440ca2bd..4187f43449a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java @@ -119,6 +119,12 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest { doTest(fileName); } + @TestMetadata("NamedCompanionObject") + public void testNamedCompanionObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/NamedCompanionObject/"); + doTest(fileName); + } + @TestMetadata("NestedClasses") public void testNestedClasses() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/NestedClasses/"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextFromJsMetadataTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextFromJsMetadataTestGenerated.java index 4533231dbfb..9197fea28ae 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextFromJsMetadataTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextFromJsMetadataTestGenerated.java @@ -77,6 +77,12 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom doTest(fileName); } + @TestMetadata("ClassWithNamedClassObject") + public void testClassWithNamedClassObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/ClassWithNamedClassObject/"); + doTest(fileName); + } + @TestMetadata("Const") public void testConst() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Const/"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextTestGenerated.java index 298af744461..8ce0b30cf3a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/CommonDecompiledTextTestGenerated.java @@ -53,6 +53,12 @@ public class CommonDecompiledTextTestGenerated extends AbstractCommonDecompiledT doTest(fileName); } + @TestMetadata("ClassWithNamedClassObject") + public void testClassWithNamedClassObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/ClassWithNamedClassObject/"); + doTest(fileName); + } + @TestMetadata("Const") public void testConst() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Const/");