From 0df966323d4d99f9842b3293737e703a1252e705 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 26 Dec 2012 17:52:40 +0400 Subject: [PATCH] Smarter members sorting. --- .../jet/lang/resolve/MemberComparator.java | 28 ++++++++++++------- .../libraries/decompiled/namespace.kt | 8 +++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/MemberComparator.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/MemberComparator.java index acd05c7dad1..bb737b42e73 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/MemberComparator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/MemberComparator.java @@ -32,21 +32,28 @@ public class MemberComparator implements Comparator { } private static int getDeclarationPriority(DeclarationDescriptor descriptor) { - if (descriptor instanceof ClassDescriptor) { - return 4; + if (descriptor instanceof ConstructorDescriptor) { + return 6; } else if (descriptor instanceof PropertyDescriptor) { - return 3; - } - else if (descriptor instanceof FunctionDescriptor) { - FunctionDescriptor fun = (FunctionDescriptor)descriptor; - if (fun.getReceiverParameter() == null) { - return 2; + if (((PropertyDescriptor)descriptor).getReceiverParameter() == null) { + return 5; } else { - return 1; + return 4; } } + else if (descriptor instanceof FunctionDescriptor) { + if (((FunctionDescriptor)descriptor).getReceiverParameter() == null) { + return 3; + } + else { + return 2; + } + } + else if (descriptor instanceof ClassDescriptor) { + return 1; + } return 0; } @@ -71,7 +78,8 @@ public class MemberComparator implements Comparator { ReceiverParameterDescriptor c1ReceiverParameter = c1.getReceiverParameter(); ReceiverParameterDescriptor c2ReceiverParameter = c2.getReceiverParameter(); - if (c1ReceiverParameter != null && c2ReceiverParameter != null) { + assert (c1ReceiverParameter != null) == (c2ReceiverParameter != null); + if (c1ReceiverParameter != null) { String r1 = DescriptorRenderer.TEXT.renderType(c1ReceiverParameter.getType()); String r2 = DescriptorRenderer.TEXT.renderType(c2ReceiverParameter.getType()); int receiversCompareTo = r1.compareTo(r2); diff --git a/idea/testData/libraries/decompiled/namespace.kt b/idea/testData/libraries/decompiled/namespace.kt index a193c9135a4..81770ac4986 100644 --- a/idea/testData/libraries/decompiled/namespace.kt +++ b/idea/testData/libraries/decompiled/namespace.kt @@ -3,16 +3,16 @@ package testData.libraries +[public final val globalVal : testData.libraries.Pair] /* compiled code */ + +[public final val globalValWithGetter : jet.Long] /* compiled code */ + [public final val jet.Int.exProp : jet.Int] /* compiled code */ [public final val jet.String.exProp : jet.String] /* compiled code */ [public final val testData.libraries.Pair.exProp : jet.String] /* compiled code */ -[public final val globalVal : testData.libraries.Pair] /* compiled code */ - -[public final val globalValWithGetter : jet.Long] /* compiled code */ - [public final fun func() : Unit { /* compiled code */ }] [public final fun func(a : jet.Int, b : jet.Int) : Unit { /* compiled code */ }]