diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java index 2bcf8554b82..3b223c6bd90 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java @@ -36,7 +36,7 @@ import org.jetbrains.jet.plugin.JetLanguage; import java.io.IOException; public class JetFileElementType extends IStubFileElementType { - public static final int STUB_VERSION = 33; + public static final int STUB_VERSION = 34; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java index 41b817eae3f..3ae00e68287 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java @@ -25,6 +25,7 @@ public final class JvmAbi { * This constant is used to identify binary format (class file) versions * If you change class file metadata format and/or naming conventions, please increase this number */ + //TODO: remove clsStubBuilding#sortCallableStubs and this comment when abi version is increased to 20 public static final int VERSION = 19; public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl"; diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/ClassClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/ClassClsStubBuilder.kt index 7d0471966d0..ded257b8f9b 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/ClassClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/ClassClsStubBuilder.kt @@ -208,7 +208,7 @@ private class ClassClsStubBuilder( private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl) { val container = ProtoContainer(classProto, null) - for (callableProto in classProto.getMemberList()) { + for (callableProto in sortCallableStubs(classProto.getMemberList())) { createCallableStub(classBody, callableProto, c, container) } } diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/clsStubBuilding.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/clsStubBuilding.kt index 6a17a30cf72..f1b8e8707c7 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/clsStubBuilding.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/decompiler/stubBuilder/clsStubBuilding.kt @@ -44,6 +44,7 @@ import org.jetbrains.jet.lang.psi.JetTypeReference import org.jetbrains.jet.lang.resolve.name.Name import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotatedCallableKind import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.CallableKind +import java.util.ArrayList fun createTopLevelClassStub(classId: ClassId, classProto: ProtoBuf.Class, context: ClsStubBuilderContext): KotlinFileStubImpl { val fileStub = createFileStub(classId.getPackageFqName()) @@ -58,7 +59,7 @@ fun createPackageFacadeFileStub( ): KotlinFileStubImpl { val fileStub = createFileStub(packageFqName) val container = ProtoContainer(null, packageFqName) - for (callableProto in packageProto.getMemberList()) { + for (callableProto in sortCallableStubs(packageProto.getMemberList())) { createCallableStub(fileStub, callableProto, c, container) } return fileStub @@ -202,3 +203,32 @@ val ProtoBuf.Callable.annotatedCallableKind: AnnotatedCallableKind fun Name.ref() = StringRef.fromString(this.asString()) fun FqName.ref() = StringRef.fromString(this.asString()) + +//NOTE: sorting should be removed when stub version is increased next time +// this workaround is relevant for abi version 19 +// this is needed to avoid building stubs in wrong order for compilers built before 77dd027d690c0fe48abccdea04bfeab871c7c6de was introduced +fun sortCallableStubs(unordered: List): List { + val extensionProperties = arrayListOf() + val nonExtensionProperties = arrayListOf() + val extensionFunctions = arrayListOf() + val nonExtensionFunctions = arrayListOf() + for (callable in unordered) { + val isExtension = callable.hasReceiverType() + when (Flags.CALLABLE_KIND[callable.getFlags()]) { + CallableKind.FUN -> { + if (isExtension) extensionFunctions.add(callable) else nonExtensionFunctions.add(callable) + } + CallableKind.VAL, CallableKind.VAR -> { + if (isExtension) extensionProperties.add(callable) else nonExtensionProperties.add(callable) + } + } + } + val result = ArrayList( + extensionProperties.size() + nonExtensionProperties.size() + extensionFunctions.size() + nonExtensionFunctions.size() + ) + result.addAll(nonExtensionProperties) + result.addAll(extensionProperties) + result.addAll(nonExtensionFunctions) + result.addAll(extensionFunctions) + return result +} \ No newline at end of file