From 011f733aad0aa6567ec1db9a37310682c059057a Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 3 Jul 2013 20:34:09 +0400 Subject: [PATCH] Serialize properties for objects A new special CallableKind for properties created for objects -- OBJECT_PROPERTY. Also fix PropertyPsiData.isFinal() in case of properties backed by fields --- .../resolve/java/wrapper/PropertyPsiData.java | 4 +- .../frontend/builtins/jet/Array.kotlin_class | Bin 219 -> 219 bytes .../builtins/jet/BooleanArray.kotlin_class | Bin 133 -> 133 bytes .../builtins/jet/ByteArray.kotlin_class | Bin 133 -> 133 bytes .../builtins/jet/ByteProgression.kotlin_class | Bin 118 -> 118 bytes .../builtins/jet/ByteRange.kotlin_class | Bin 146 -> 146 bytes .../jet/ByteRange.object.kotlin_class | 2 +- .../builtins/jet/CharArray.kotlin_class | Bin 133 -> 133 bytes .../builtins/jet/CharProgression.kotlin_class | Bin 118 -> 118 bytes .../builtins/jet/CharRange.kotlin_class | Bin 146 -> 146 bytes .../jet/CharRange.object.kotlin_class | 2 +- .../builtins/jet/CharSequence.kotlin_class | Bin 59 -> 59 bytes .../builtins/jet/DoubleArray.kotlin_class | Bin 133 -> 133 bytes .../jet/DoubleProgression.kotlin_class | Bin 118 -> 118 bytes .../builtins/jet/DoubleRange.kotlin_class | Bin 146 -> 146 bytes .../jet/DoubleRange.object.kotlin_class | 2 +- .../builtins/jet/FloatArray.kotlin_class | Bin 134 -> 134 bytes .../jet/FloatProgression.kotlin_class | Bin 119 -> 119 bytes .../builtins/jet/FloatRange.kotlin_class | Bin 146 -> 146 bytes .../jet/FloatRange.object.kotlin_class | 2 +- .../builtins/jet/IntArray.kotlin_class | Bin 134 -> 134 bytes .../builtins/jet/IntProgression.kotlin_class | Bin 119 -> 119 bytes .../builtins/jet/IntRange.kotlin_class | Bin 146 -> 146 bytes .../builtins/jet/IntRange.object.kotlin_class | 2 +- .../builtins/jet/LongArray.kotlin_class | Bin 134 -> 134 bytes .../builtins/jet/LongProgression.kotlin_class | Bin 119 -> 119 bytes .../builtins/jet/LongRange.kotlin_class | Bin 146 -> 146 bytes .../jet/LongRange.object.kotlin_class | 2 +- .../builtins/jet/Progression.kotlin_class | Bin 76 -> 76 bytes .../jet/PropertyMetadata.kotlin_class | 2 +- .../jet/PropertyMetadataImpl.kotlin_class | Bin 49 -> 49 bytes .../frontend/builtins/jet/Range.kotlin_class | Bin 90 -> 90 bytes .../builtins/jet/ShortArray.kotlin_class | Bin 134 -> 134 bytes .../jet/ShortProgression.kotlin_class | Bin 119 -> 119 bytes .../builtins/jet/ShortRange.kotlin_class | Bin 146 -> 146 bytes .../jet/ShortRange.object.kotlin_class | 2 +- .../frontend/builtins/jet/String.kotlin_class | Bin 163 -> 163 bytes .../builtins/jet/Unit.object.kotlin_class | 2 +- .../serialization/src/descriptors.proto | 3 +- .../descriptors/serialization/ClassId.java | 22 ++++---- .../serialization/DescriptorDeserializer.java | 50 +++++++++++++----- .../serialization/DescriptorSerializer.java | 5 +- .../descriptors/serialization/ProtoBuf.java | 3 ++ .../serialization/TypeDeserializer.java | 4 ++ .../descriptors/DeserializedMemberScope.java | 8 ++- .../jet/lang/resolve/name/FqNameUnsafe.java | 7 +++ 46 files changed, 85 insertions(+), 39 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/wrapper/PropertyPsiData.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/wrapper/PropertyPsiData.java index 12de73162c0..8a50ced17e2 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/wrapper/PropertyPsiData.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/wrapper/PropertyPsiData.java @@ -199,10 +199,10 @@ public final class PropertyPsiData { if (getter != null) { return getter.getMember().isFinal(); } - if (setter != null) { return setter.getMember().isFinal(); } - return false; + assert field != null : "Property with no getter and no setter should at least have a backing field"; + return field.getMember().isFinal(); } } diff --git a/compiler/frontend/builtins/jet/Array.kotlin_class b/compiler/frontend/builtins/jet/Array.kotlin_class index 81ac69f50dd58bfcce8ad8d621587f7d621e3d1d..647cceb3adffb4876ebf286195f1f92cd74f4c90 100644 GIT binary patch delta 21 ccmcc3c$;xTC!@l|E)Pxx12!iXE+zpc08C>A82|tP delta 21 ccmcc3c$;xTC!@f`E)Pxt12!iXE+zpc07~-&`2YX_ diff --git a/compiler/frontend/builtins/jet/BooleanArray.kotlin_class b/compiler/frontend/builtins/jet/BooleanArray.kotlin_class index dfc8a9ef45684ebd5446c17809f9ead643a64438..7771e7548164c46b5a28915ecb0199baa68cf47c 100644 GIT binary patch delta 21 ccmZo=Y-OBa&!{lb!G=@8fX#`8i%Eb905(?x%>V!Z delta 21 ccmZo=Y-OBa&nPg_!G=@7fX#`8i%Eb905sV!Z delta 21 ccmZo=Y-OBa&nPg_!G=@7fX#`8i%Eb905s60R00`a)umAu6 delta 52 scmXRbo8Yc5VBqY;!o?)O8^z6WO~Akf%wdY+;t(_71GA+d5>60R00TYoJ3IoJ0tQYH5dec`27v$o diff --git a/compiler/frontend/builtins/jet/ByteRange.object.kotlin_class b/compiler/frontend/builtins/jet/ByteRange.object.kotlin_class index 01ad0fbf162..222f9338e89 100644 --- a/compiler/frontend/builtins/jet/ByteRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/ByteRange.object.kotlin_class @@ -1,4 +1,4 @@ † H2 R Â0B -Z Æ0IB +Z Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/CharArray.kotlin_class b/compiler/frontend/builtins/jet/CharArray.kotlin_class index 39b481e385d7fd6ad5e499321ba1af451d98aff0..b5c7e1fe3a14e0b22a754aa4625daee41fe97eca 100644 GIT binary patch delta 21 ccmZo=Y-OBa&!{lb!G=@8fX#`8i%Eb905(?x%>V!Z delta 21 ccmZo=Y-OBa&nPg_!G=@7fX#`8i%Eb905s60R00~+MxBvhE delta 52 scmXRbo8Yc5VBqY;!o?)O7sbtSO~Akf%wdY+;t(_71G5z%5>60R00X)RhyVZp diff --git a/compiler/frontend/builtins/jet/CharRange.kotlin_class b/compiler/frontend/builtins/jet/CharRange.kotlin_class index e0da727f77cb663d8efc97e28622130ade407d76..cfc776a0da7c54ec1eaee7e0f9bb4d1d9be6c81a 100644 GIT binary patch delta 34 lcmbQlIEisWGM|Ehvl9y!lK@{7H^()FiG>oJ3IoJ0tQYH5dedF27>?q diff --git a/compiler/frontend/builtins/jet/CharRange.object.kotlin_class b/compiler/frontend/builtins/jet/CharRange.object.kotlin_class index 44e85b154e7..6fe17e41a23 100644 --- a/compiler/frontend/builtins/jet/CharRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/CharRange.object.kotlin_class @@ -1,4 +1,4 @@ † N2 R Â0B -"Z Æ0IB +"Z Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/CharSequence.kotlin_class b/compiler/frontend/builtins/jet/CharSequence.kotlin_class index 4186c13c87868b753c5b4ee05f9ca3831f5398ad..582048817fe7836c1e4bf7e79cf83ce0bc2dfd7b 100644 GIT binary patch delta 26 ecmcDvo}ebGU=ZNM!o?)O6vf4%W)KKwD+2&Mmjm7a delta 26 ecmcDvo}eZwU=ZNM!o?)O6vf4%W)KKwD+2&LM+43P diff --git a/compiler/frontend/builtins/jet/DoubleArray.kotlin_class b/compiler/frontend/builtins/jet/DoubleArray.kotlin_class index a67fe299bf4e32feaa8191cc558b8270e24c228a..37135c227661d1ac81cb9abab0d60f0fb4a2a3ec 100644 GIT binary patch delta 21 ccmZo=Y-OBa&!{lb!G=@8fX#`8i%Eb905(?x%>V!Z delta 21 ccmZo=Y-OBa&nPg_!G=@7fX#`8i%Eb905soJ3IoJ0tQYH5dedZ2893s diff --git a/compiler/frontend/builtins/jet/DoubleRange.object.kotlin_class b/compiler/frontend/builtins/jet/DoubleRange.object.kotlin_class index 604edababd5..31d3aeed766 100644 --- a/compiler/frontend/builtins/jet/DoubleRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/DoubleRange.object.kotlin_class @@ -1,4 +1,4 @@ † a2 R Â0B -*Z Æ0IB +*Z Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/FloatArray.kotlin_class b/compiler/frontend/builtins/jet/FloatArray.kotlin_class index 3a71c7334607294ae86e932c8dd5ea9593a5ae3f..41221e29c767e2461e1e3d46a9ef9169a8b588b0 100644 GIT binary patch delta 21 ccmZo;Y-60@z^E|M(S}pOfX#`8i%Eb905+Qg(EtDd delta 21 ccmZo;Y-60@z$h@$(S}pNfX#`8i%Eb905vNEu>b%7 diff --git a/compiler/frontend/builtins/jet/FloatProgression.kotlin_class b/compiler/frontend/builtins/jet/FloatProgression.kotlin_class index 12d56179184fc8ad5e32e3ee3687da80ae869c30..c1990486a61575d223377261670a529cd53114d0 100644 GIT binary patch delta 52 qcmXRfpWvadVBqY;!o?&Y5XH@LO~Jqg%HiS=GvEWWbs-W?5D5SbWC+>- delta 52 qcmXRfpWvY{VBqY;!o?&Y5XH@LO~Akf%HiS=GvEWWbs-W?5D5SV#0aVY diff --git a/compiler/frontend/builtins/jet/FloatRange.kotlin_class b/compiler/frontend/builtins/jet/FloatRange.kotlin_class index 482a7c5112c3dd81c758cb07df21a9e500c32160..ea313686031cddb3a92474d33fbeb360ca454517 100644 GIT binary patch delta 34 lcmbQlIEisWGM|Ehvl9y!lYl@JH^()FiG>oJ3IoJ0tQYH5dedt28RFu diff --git a/compiler/frontend/builtins/jet/FloatRange.object.kotlin_class b/compiler/frontend/builtins/jet/FloatRange.object.kotlin_class index 0bd839ff6c6..bbc3ccecd98 100644 --- a/compiler/frontend/builtins/jet/FloatRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/FloatRange.object.kotlin_class @@ -1,4 +1,4 @@ † ®2 R Â0B -/Z Æ0IB +/Z Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/IntArray.kotlin_class b/compiler/frontend/builtins/jet/IntArray.kotlin_class index f1d6018a1aafee605eb3615b2e1ef075f02f7fc7..3418b23de144f4a566ad0b166a7ad1b37434f7dc 100644 GIT binary patch delta 21 ccmZo;Y-60@z^E|M(S}pOfX#`8i%Eb905+Qg(EtDd delta 21 ccmZo;Y-60@z$h@$(S}pNfX#`8i%Eb905vNEu>b%7 diff --git a/compiler/frontend/builtins/jet/IntProgression.kotlin_class b/compiler/frontend/builtins/jet/IntProgression.kotlin_class index 02d9b7719e100bbd70f5217cf482d678b4bad10d..197918f729b000f53503ed7352c27b46607aee10 100644 GIT binary patch delta 52 qcmXRfpWvadVBqY;!o?)O6vfSPO~Jqg%HiS=GvEWW4IvUv5D5SY00^`I delta 52 qcmXRfpWvY{VBqY;!o?)O6vfSPO~Akf%HiS=GvEWW4IvUv5D5SSUoJ3IoJ0tQYH5deaU25SHS diff --git a/compiler/frontend/builtins/jet/IntRange.object.kotlin_class b/compiler/frontend/builtins/jet/IntRange.object.kotlin_class index c422d0b6ef9..643cbc2d971 100644 --- a/compiler/frontend/builtins/jet/IntRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/IntRange.object.kotlin_class @@ -1,4 +1,4 @@ † Î2 R Â0B -3Z Æ0IB +3Z Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/LongArray.kotlin_class b/compiler/frontend/builtins/jet/LongArray.kotlin_class index 4ddc7e141ed554810b21d63c5e7c136e5d185ec2..9f12c54b0e81c45b9285df487f4651d42aaea368 100644 GIT binary patch delta 21 ccmZo;Y-60@z^E|M(S}pOfX#`8i%Eb905+Qg(EtDd delta 21 ccmZo;Y-60@z$h@$(S}pNfX#`8i%Eb905vNEu>b%7 diff --git a/compiler/frontend/builtins/jet/LongProgression.kotlin_class b/compiler/frontend/builtins/jet/LongProgression.kotlin_class index caa9ff3a8576c0de793ca1a9d5072efc58eab767..289cef019e3293917515490bfc1cf9eb87efa74a 100644 GIT binary patch delta 52 qcmXRfpWvadVBqY;!o?&Y7{$$TO~Jqg%HiS=GvEWWQy>yf5D5Ses0kDR delta 52 qcmXRfpWvY{VBqY;!o?&Y7{$$TO~Akf%HiS=GvEWWQy>yf5D5SZ2ngf= diff --git a/compiler/frontend/builtins/jet/LongRange.kotlin_class b/compiler/frontend/builtins/jet/LongRange.kotlin_class index acb0491bb42fc67b28129d71c962e8804af57a45..d6ff235851ed0fd09996e79b6289359111539814 100644 GIT binary patch delta 34 lcmbQlIEisWGM|Ehvl9y!lYn3pH^()FiG>oJ3IoJ0tQYH5ded>28jRw diff --git a/compiler/frontend/builtins/jet/LongRange.object.kotlin_class b/compiler/frontend/builtins/jet/LongRange.object.kotlin_class index feab5fccf57..7bf7f941072 100644 --- a/compiler/frontend/builtins/jet/LongRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/LongRange.object.kotlin_class @@ -1,4 +1,4 @@ † ¥2 R Â0B -fZ Æ0IB +fZ Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/Progression.kotlin_class b/compiler/frontend/builtins/jet/Progression.kotlin_class index 1b5329373abdc15a8677d48d2e5eb3dd8b5173e4..88dd2abcc346bf1ada583dd7ae0b2ff1a7b04266 100644 GIT binary patch delta 44 rcmebAnV_n!VBqY;#>K+HD8LZK&GAgZz{QD$i%EbxiWkIjg2@2@vzrGY delta 44 rcmebAnV_mJVBqY;#>K+HD8LZK&GAgYz{QD$i%EbxiWkIjg2@2@uKNb@ diff --git a/compiler/frontend/builtins/jet/PropertyMetadata.kotlin_class b/compiler/frontend/builtins/jet/PropertyMetadata.kotlin_class index f29fe2e81a5..47294ffc9ea 100644 --- a/compiler/frontend/builtins/jet/PropertyMetadata.kotlin_class +++ b/compiler/frontend/builtins/jet/PropertyMetadata.kotlin_class @@ -1,3 +1,3 @@ f É2 -Z æ0cB +Z æ 0cB # \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/PropertyMetadataImpl.kotlin_class b/compiler/frontend/builtins/jet/PropertyMetadataImpl.kotlin_class index 27ec7e0024fc0b8916d272cef3174c229d05e92e..fb65a697b9d89dbfdc59c1c4d44da5dfe0b2b592 100644 GIT binary patch delta 14 VcmXpsoS?y}V36#@!o?(@3;-2z0$cz9 delta 14 VcmXpsoS?xeV36#@!o?(@3;-120!#n^ diff --git a/compiler/frontend/builtins/jet/Range.kotlin_class b/compiler/frontend/builtins/jet/Range.kotlin_class index 35221e18fd85baae978401dcaf4c96fa9648c751..980018870886b099ee89e5a314746b9f744e4a0b 100644 GIT binary patch delta 31 gcma!wn&2R%VBqY;#>K+HD8LZK%kfOXzzN0$0AR2L_W%F@ delta 31 gcma!wn&2QMVBqY;#>K+HD8LZK%kfOWzzN0$0A64O*8l(j diff --git a/compiler/frontend/builtins/jet/ShortArray.kotlin_class b/compiler/frontend/builtins/jet/ShortArray.kotlin_class index a7c5cd23081ab97b16d2da979ffd140e9121dfdf..4f7b12c5482e771ad5bfde17be451f61452c5707 100644 GIT binary patch delta 21 ccmZo;Y-60@z^E|M(S}pOfX#`8i%Eb905+Qg(EtDd delta 21 ccmZo;Y-60@z$h@$(S}pNfX#`8i%Eb905vNEu>b%7 diff --git a/compiler/frontend/builtins/jet/ShortProgression.kotlin_class b/compiler/frontend/builtins/jet/ShortProgression.kotlin_class index 1b206b8e955a09bbfc7abf0f0b5a3332bac6833c..7cfec3a21bc2120c160a3d11e7013068efcbed9d 100644 GIT binary patch delta 52 scmXRfpWvadVBqY;!o?&Y6vfSPO~Jqg%wdY+;t(_71GCE@5>60R01rk982|tP delta 52 scmXRfpWvY{VBqY;!o?&Y6vfSPO~Akf%wdY+;t(_71GCE@5>60R012iD=>Px# diff --git a/compiler/frontend/builtins/jet/ShortRange.kotlin_class b/compiler/frontend/builtins/jet/ShortRange.kotlin_class index 1d919787b56c9b9f8b225c1b3fc44b38ddf96e56..a21d245816e69abd98320bf6b1f7be6944f2d32e 100644 GIT binary patch delta 34 lcmbQlIEisWGM|Ehvl9y!lYmeZH^()FiG>oJ3IoJ0tQYH5deeA28#dy diff --git a/compiler/frontend/builtins/jet/ShortRange.object.kotlin_class b/compiler/frontend/builtins/jet/ShortRange.object.kotlin_class index c8464866ee7..88df0526c84 100644 --- a/compiler/frontend/builtins/jet/ShortRange.object.kotlin_class +++ b/compiler/frontend/builtins/jet/ShortRange.object.kotlin_class @@ -1,4 +1,4 @@ † Ï2 R Â0B -xZ Æ0IB +xZ Æ 0IB  \ No newline at end of file diff --git a/compiler/frontend/builtins/jet/String.kotlin_class b/compiler/frontend/builtins/jet/String.kotlin_class index 7fd163631aa9822c03ebbf2de58a7f32dd6bde4e..dc5712a1057b7429fdfbc4eddc18b4a3f8e1f649 100644 GIT binary patch delta 11 ScmZ3?xR`N538TWqQau0`(F39Y delta 11 ScmZ3?xR`N538TQoQau0`kpq$d diff --git a/compiler/frontend/builtins/jet/Unit.object.kotlin_class b/compiler/frontend/builtins/jet/Unit.object.kotlin_class index 3a9b86d6fb1..e82ca791691 100644 --- a/compiler/frontend/builtins/jet/Unit.object.kotlin_class +++ b/compiler/frontend/builtins/jet/Unit.object.kotlin_class @@ -1,4 +1,4 @@ † ×2 R Â0B -{Z Æ0ØB +{Z Æ 0ØB  \ No newline at end of file diff --git a/compiler/frontend/serialization/src/descriptors.proto b/compiler/frontend/serialization/src/descriptors.proto index b26816b4bdd..fa4bba55af6 100644 --- a/compiler/frontend/serialization/src/descriptors.proto +++ b/compiler/frontend/serialization/src/descriptors.proto @@ -144,11 +144,12 @@ message Callable { } enum CallableKind { - // 2 bits + // 3 bits FUN = 0; VAL = 1; VAR = 2; CONSTRUCTOR = 3; + OBJECT_PROPERTY = 4; } /* diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ClassId.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ClassId.java index 45c5adc8c59..e46fdc27186 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ClassId.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ClassId.java @@ -1,7 +1,5 @@ package org.jetbrains.jet.descriptors.serialization; -import com.intellij.util.Function; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; @@ -20,23 +18,23 @@ public final class ClassId { public static ClassId fromFqNameAndContainingDeclaration( @NotNull FqName fqName, @NotNull ClassOrNamespaceDescriptor containingDeclaration + ) { + return fromFqNameAndContainingDeclaration(fqName.toUnsafe(), containingDeclaration); + } + + @NotNull + public static ClassId fromFqNameAndContainingDeclaration( + @NotNull FqNameUnsafe fqName, + @NotNull ClassOrNamespaceDescriptor containingDeclaration ) { NamespaceDescriptor containingNamespace = DescriptorUtils.getParentOfType(containingDeclaration, NamespaceDescriptor.class, false); assert containingNamespace != null; List fullNameSegments = fqName.pathSegments(); FqName namespaceFqName = DescriptorUtils.getFQName(containingNamespace).toSafe(); List namespaceNameSegments = namespaceFqName.pathSegments(); - for (int i = 0; i < namespaceNameSegments.size(); ++i) { - assert fullNameSegments.get(i).equals(namespaceNameSegments.get(i)); - } + assert fullNameSegments.subList(0, namespaceNameSegments.size()).equals(namespaceNameSegments); List relativeNameSegments = fullNameSegments.subList(namespaceNameSegments.size(), fullNameSegments.size()); - FqName relativeFqName = FqName.fromSegments(ContainerUtil.map2List(relativeNameSegments, new Function() { - @Override - public String fun(Name name) { - return name.asString(); - } - })); - return new ClassId(namespaceFqName, relativeFqName.toUnsafe()); + return new ClassId(namespaceFqName, FqNameUnsafe.fromSegments(relativeNameSegments)); } public ClassId(@NotNull FqName packageFqName, @NotNull FqNameUnsafe relativeClassName) { diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java index f9ed665d7a8..7f980a492cb 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java @@ -24,7 +24,10 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.impl.*; import org.jetbrains.jet.lang.resolve.DescriptorResolver; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager; +import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; +import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.Variance; import java.util.ArrayList; @@ -121,6 +124,7 @@ public class DescriptorDeserializer { return loadFunction(proto); case VAL: case VAR: + case OBJECT_PROPERTY: return loadProperty(proto); case CONSTRUCTOR: return loadConstructor(proto); @@ -130,16 +134,8 @@ public class DescriptorDeserializer { @NotNull private PropertyDescriptor loadProperty(@NotNull Callable proto) { - int flags = proto.getFlags(); - PropertyDescriptorImpl property = new PropertyDescriptorImpl( - containingDeclaration, - getAnnotations(proto), - modality(Flags.MODALITY.get(flags)), - visibility(Flags.VISIBILITY.get(flags)), - Flags.CALLABLE_KIND.get(flags) == Callable.CallableKind.VAR, - nameResolver.getName(proto.getName()), - memberKind(Flags.MEMBER_KIND.get(flags)) - ); + PropertyDescriptorImpl property = createPropertyDescriptor(proto); + List typeParameters = new ArrayList(proto.getTypeParameterCount()); DescriptorDeserializer local = createChildDeserializer(property, proto.getTypeParameterList(), typeParameters); property.setType( @@ -152,7 +148,7 @@ public class DescriptorDeserializer { PropertyGetterDescriptorImpl getter = null; PropertySetterDescriptorImpl setter = null; - if (Flags.HAS_GETTER.get(flags)) { + if (Flags.HAS_GETTER.get(proto.getFlags())) { int getterFlags = proto.getGetterFlags(); boolean isNotDefault = proto.hasGetterFlags() && Flags.IS_NOT_DEFAULT.get(getterFlags); if (isNotDefault) { @@ -168,7 +164,7 @@ public class DescriptorDeserializer { getter.initialize(property.getReturnType()); } - if (Flags.HAS_SETTER.get(flags)) { + if (Flags.HAS_SETTER.get(proto.getFlags())) { int setterFlags = proto.getSetterFlags(); boolean isNotDefault = proto.hasSetterFlags() && Flags.IS_NOT_DEFAULT.get(setterFlags); if (isNotDefault) { @@ -192,6 +188,36 @@ public class DescriptorDeserializer { return property; } + @NotNull + private PropertyDescriptorImpl createPropertyDescriptor(@NotNull Callable proto) { + int flags = proto.getFlags(); + Name name = nameResolver.getName(proto.getName()); + List annotations = getAnnotations(proto); + Visibility visibility = visibility(Flags.VISIBILITY.get(flags)); + Callable.CallableKind callableKind = Flags.CALLABLE_KIND.get(flags); + + if (callableKind == Callable.CallableKind.OBJECT_PROPERTY) { + assert containingDeclaration instanceof ClassOrNamespaceDescriptor + : "Properties for objects can only exist in class or namespace: " + name; + FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration).child(name); + ClassId objectId = ClassId.fromFqNameAndContainingDeclaration(fqName, (ClassOrNamespaceDescriptor) containingDeclaration); + ClassDescriptor objectClass = typeDeserializer.getDescriptorFinder().findClass(objectId); + assert objectClass != null : "Object for property not found: " + name; + + return new PropertyDescriptorForObjectImpl(containingDeclaration, annotations, visibility, name, objectClass); + } + + return new PropertyDescriptorImpl( + containingDeclaration, + annotations, + modality(Flags.MODALITY.get(flags)), + visibility, + callableKind == Callable.CallableKind.VAR, + name, + memberKind(Flags.MEMBER_KIND.get(flags)) + ); + } + @NotNull private CallableMemberDescriptor loadFunction(@NotNull Callable proto) { int flags = proto.getFlags(); diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorSerializer.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorSerializer.java index aa9a6dfd318..ae4611f76cc 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorSerializer.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorSerializer.java @@ -256,7 +256,10 @@ public class DescriptorSerializer { } private static ProtoBuf.Callable.CallableKind callableKind(CallableMemberDescriptor descriptor) { - if (descriptor instanceof PropertyDescriptor) { + if (descriptor instanceof VariableDescriptorForObject) { + return ProtoBuf.Callable.CallableKind.OBJECT_PROPERTY; + } + else if (descriptor instanceof PropertyDescriptor) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor; return propertyDescriptor.isVar() ? ProtoBuf.Callable.CallableKind.VAR : ProtoBuf.Callable.CallableKind.VAL; } diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ProtoBuf.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ProtoBuf.java index b5dcc833d69..ea21b87889a 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ProtoBuf.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/ProtoBuf.java @@ -5380,12 +5380,14 @@ public final class ProtoBuf { VAL(1, 1), VAR(2, 2), CONSTRUCTOR(3, 3), + OBJECT_PROPERTY(4, 4), ; public static final int FUN_VALUE = 0; public static final int VAL_VALUE = 1; public static final int VAR_VALUE = 2; public static final int CONSTRUCTOR_VALUE = 3; + public static final int OBJECT_PROPERTY_VALUE = 4; public final int getNumber() { return value; } @@ -5396,6 +5398,7 @@ public final class ProtoBuf { case 1: return VAL; case 2: return VAR; case 3: return CONSTRUCTOR; + case 4: return OBJECT_PROPERTY; default: return null; } } diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/TypeDeserializer.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/TypeDeserializer.java index f3b11c03e31..2c01ff879c2 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/TypeDeserializer.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/TypeDeserializer.java @@ -100,6 +100,10 @@ public class TypeDeserializer { }, STRONG); } + /* package */ DescriptorFinder getDescriptorFinder() { + return descriptorFinder; + } + @Nullable public JetType typeOrNull(@Nullable ProtoBuf.Type proto) { if (proto == null) { diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/descriptors/DeserializedMemberScope.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/descriptors/DeserializedMemberScope.java index 2b312aa19a8..4e33a9101f6 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/descriptors/DeserializedMemberScope.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/descriptors/DeserializedMemberScope.java @@ -24,7 +24,9 @@ import org.jetbrains.jet.descriptors.serialization.DescriptorDeserializer; import org.jetbrains.jet.descriptors.serialization.Flags; import org.jetbrains.jet.descriptors.serialization.ProtoBuf; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.resolve.lazy.storage.*; +import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNotNull; +import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue; +import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager; import org.jetbrains.jet.lang.resolve.name.LabelName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; @@ -44,7 +46,9 @@ public abstract class DeserializedMemberScope implements JetScope { private static final Filter PROPERTY = new Filter() { @Override public boolean accept(ProtoBuf.Callable.CallableKind value) { - return value == ProtoBuf.Callable.CallableKind.VAL || value == ProtoBuf.Callable.CallableKind.VAR; + return value == ProtoBuf.Callable.CallableKind.VAL || + value == ProtoBuf.Callable.CallableKind.VAR || + value == ProtoBuf.Callable.CallableKind.OBJECT_PROPERTY; } }; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/name/FqNameUnsafe.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/name/FqNameUnsafe.java index 4f5a21a2408..cbb2c4441a4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/name/FqNameUnsafe.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/name/FqNameUnsafe.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.lang.resolve.name; import com.google.common.collect.Lists; +import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -250,6 +251,12 @@ public final class FqNameUnsafe extends FqNameBase { return shortName().equals(segment); } + @NotNull + public static FqNameUnsafe fromSegments(@NotNull List names) { + String fqName = StringUtil.join(names, "."); + return new FqNameUnsafe(fqName); + } + @NotNull