From 86f5114b7da30f8227dd29fd58ba029b46bfd3e3 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 13 Mar 2013 11:47:07 +0400 Subject: [PATCH] Properly resolve descriptors from compiled kotlin Added protected flag for annotation --- .../jetbrains/jet/codegen/CodegenUtil.java | 3 ++ .../resolve/java/DescriptorResolverUtils.java | 3 ++ .../jet/lang/resolve/java/JvmAbi.java | 2 +- .../jet/lang/resolve/java/JvmStdlibNames.java | 17 ++++++----- .../java/kt/PsiAnnotationWithFlags.java | 6 +++- .../resolve/java/provider/MembersCache.java | 4 ++- .../java/resolver/JavaPropertyResolver.java | 28 ++++++++++-------- compiler/testData/cli/wrongAbiVersion.out | 4 +-- .../duplicateLibraries/DuplicateLibTest-1.jar | Bin 1145 -> 1146 bytes .../duplicateLibraries/DuplicateLibTest-2.jar | Bin 1145 -> 1146 bytes 10 files changed, 42 insertions(+), 25 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 68dcc7b67e5..331afb2ee1d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -114,6 +114,9 @@ public class CodegenUtil { else if (visibility == Visibilities.PRIVATE) { return JvmStdlibNames.FLAG_PRIVATE_BIT; } + else if (visibility == Visibilities.PROTECTED) { + return JvmStdlibNames.FLAG_PROTECTED_BIT; + } return 0; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/DescriptorResolverUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/DescriptorResolverUtils.java index 0e907bc8a67..0fca6080224 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/DescriptorResolverUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/DescriptorResolverUtils.java @@ -84,6 +84,9 @@ public final class DescriptorResolverUtils { else if (annotation.hasInternalFlag()) { return Visibilities.INTERNAL; } + else if (annotation.hasProtectedFlag()) { + return Visibilities.PROTECTED; + } } if (modifierListOwner.hasModifierProperty(PsiModifier.PUBLIC)) { diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java index 2dad9b6317c..447c8696a6a 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java @@ -27,7 +27,7 @@ public 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 */ - public static final int VERSION = 3; + public static final int VERSION = 4; public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl"; public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java index 9f542559369..b4bab103ef0 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java @@ -47,17 +47,18 @@ public class JvmStdlibNames { public static final int FLAG_FORCE_FINAL_BIT = 1 << 2; public static final int FLAG_PRIVATE_BIT = 1 << 3; public static final int FLAG_INTERNAL_BIT = 1 << 4; + public static final int FLAG_PROTECTED_BIT = 1 << 5; // for method, three bits (one reserved) - public static final int FLAG_METHOD_KIND_MASK = 7 << 5; - public static final int FLAG_METHOD_KIND_DECLARATION = 0 << 5; - public static final int FLAG_METHOD_KIND_FAKE_OVERRIDE = 1 << 5; - public static final int FLAG_METHOD_KIND_DELEGATION = 2 << 5; - public static final int FLAG_METHOD_KIND_SYNTHESIZED = 3 << 5; + public static final int FLAG_METHOD_KIND_MASK = 7 << 6; + public static final int FLAG_METHOD_KIND_DECLARATION = 0 << 6; + public static final int FLAG_METHOD_KIND_FAKE_OVERRIDE = 1 << 6; + public static final int FLAG_METHOD_KIND_DELEGATION = 2 << 6; + public static final int FLAG_METHOD_KIND_SYNTHESIZED = 3 << 6; - public static final int FLAG_CLASS_KIND_MASK = 7 << 5; - public static final int FLAG_CLASS_KIND_DEFAULT = 0 << 5; - public static final int FLAG_CLASS_KIND_OBJECT = 1 << 5; + public static final int FLAG_CLASS_KIND_MASK = 7 << 6; + public static final int FLAG_CLASS_KIND_DEFAULT = 0 << 6; + public static final int FLAG_CLASS_KIND_OBJECT = 1 << 6; public static final JvmClassName JET_CONSTRUCTOR = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetConstructor"); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java index 1eb7478d7fa..8b1387bec6e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java @@ -51,8 +51,12 @@ public abstract class PsiAnnotationWithFlags extends PsiAnnotationWrapper { public final boolean hasInternalFlag() { return (flags() & JvmStdlibNames.FLAG_INTERNAL_BIT) != 0; - } + + public final boolean hasProtectedFlag() { + return (flags() & JvmStdlibNames.FLAG_PROTECTED_BIT) != 0; + } + public final boolean hasPrivateFlag() { return (flags() & JvmStdlibNames.FLAG_PRIVATE_BIT) != 0; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java index 77ed6a2dcac..af415ebaae0 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java @@ -138,7 +138,9 @@ public final class MembersCache { return false; } - if (member.isPrivate()) { + //process private accessors + if (member.isPrivate() + && !(member instanceof PsiMethodWrapper && ((PsiMethodWrapper)member).getJetMethodAnnotation().hasPropertyFlag())) { return false; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java index 0a22af77cea..0d83a6affbc 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java @@ -33,10 +33,7 @@ import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation; import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers; import org.jetbrains.jet.lang.resolve.java.provider.PsiDeclarationProvider; -import org.jetbrains.jet.lang.resolve.java.wrapper.PropertyPsiData; -import org.jetbrains.jet.lang.resolve.java.wrapper.PropertyPsiDataElement; -import org.jetbrains.jet.lang.resolve.java.wrapper.PsiFieldWrapper; -import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper; +import org.jetbrains.jet.lang.resolve.java.wrapper.*; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.JetType; @@ -235,7 +232,7 @@ public final class JavaPropertyResolver { DescriptorUtils.getExpectedThisObjectIfNeeded(owner), receiverType ); - initializeSetterAndGetter(propertyDescriptor, getterDescriptor, setterDescriptor, propertyType); + initializeSetterAndGetter(propertyDescriptor, getterDescriptor, setterDescriptor, propertyType, psiData); if (kind == CallableMemberDescriptor.Kind.DECLARATION) { trace.record(BindingContext.VARIABLE, psiData.getCharacteristicPsi(), propertyDescriptor); @@ -274,20 +271,27 @@ public final class JavaPropertyResolver { } private static void initializeSetterAndGetter( - PropertyDescriptor propertyDescriptor, - PropertyGetterDescriptorImpl getterDescriptor, - PropertySetterDescriptorImpl setterDescriptor, - JetType propertyType + @NotNull PropertyDescriptor propertyDescriptor, + @Nullable PropertyGetterDescriptorImpl getterDescriptor, + @Nullable PropertySetterDescriptorImpl setterDescriptor, + @NotNull JetType propertyType, + @NotNull PropertyPsiData data ) { if (getterDescriptor != null) { getterDescriptor.initialize(propertyType); } if (setterDescriptor != null) { + PropertyPsiDataElement setter = data.getSetter(); + assert setter != null; + List parameters = ((PsiMethodWrapper) setter.getMember()).getParameters(); + assert parameters.size() != 0; + int valueIndex = parameters.size() - 1; + PsiParameterWrapper valueParameter = parameters.get(valueIndex); setterDescriptor.initialize(new ValueParameterDescriptorImpl( setterDescriptor, 0, Collections.emptyList(), - Name.identifier("p0") /*TODO*/, + Name.identifierNoValidate(valueParameter.getJetValueParameter().name()), propertyDescriptor.getType(), false, null)); @@ -325,7 +329,7 @@ public final class JavaPropertyResolver { return new PropertyGetterDescriptorImpl( propertyDescriptor, annotationResolver.resolveAnnotations(getter.getMember().getPsiMember()), - Modality.OPEN, + propertyDescriptor.getModality(), visibility, true, false, @@ -352,7 +356,7 @@ public final class JavaPropertyResolver { return new PropertySetterDescriptorImpl( propertyDescriptor, annotationResolver.resolveAnnotations(setter.getMember().getPsiMember()), - Modality.OPEN, + propertyDescriptor.getModality(), setterVisibility, true, false, diff --git a/compiler/testData/cli/wrongAbiVersion.out b/compiler/testData/cli/wrongAbiVersion.out index dda27e8dff4..1393afbcf3f 100644 --- a/compiler/testData/cli/wrongAbiVersion.out +++ b/compiler/testData/cli/wrongAbiVersion.out @@ -1,4 +1,4 @@ WARNING: $TESTDATA_DIR$/wrongAbiVersion.kt: (3, 9) Parameter 'x' is never used -ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 3 -ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 3 +ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 4 +ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 4 COMPILATION_ERROR diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-1.jar b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-1.jar index 2353cb12a61ffb469cba10cb53d2a01914d6dc4d..747450d16a2656636db379f085c882144bc5e79d 100644 GIT binary patch delta 455 zcmV;&0XY8o2>J*OP)h>@6aWYS2mr~NbFmHE0Ryy~bCc@e z=SD$YIOw)TkcvV_!w7Ap8awyF)D<(~Uk@k3GdVDZ%7o9j<8!)Qb}feTL>T8vm}M)&kiCee$4`b~ z*Nrd3NE!Jo9P=_2QjLNb-GB4B)*S|0%dz4n3I#*W{VhO%%*f|sZIQnlh5{eTfe5t> zRNNtTTPkh1^28oP%l+Ftv1GeaNpr?v9UKlA_W$=45MLO1CI~yRM81S7Y6YZGXUKOw zKjA4Lg?b6AsMwUX8PdJrkzUZgT~H3BmP22hD-{@S$gL*tcR>_-;(t>50w*+;2HB!$ z$26prqMW4Y+@z{X6{9nAG)LnV@!Fy&Qge->*vC3-GzrfVe3RzlRs2BeVUE@tHWpJU zY$tmznXeN(4~xDXg_xv-avv){P)i30kJ1J~S^)q60RjL3P)h*<6aW+e2mlBG$(nOQ x6}nG!q5%K^rw0H43X{YGD+9EfbCdD|GYQO^b3%{O20>brE(Aper~?21002f$yH@}J delta 426 zcmV;b0agC`2>A#NP)h>@6aWYS2mmr*WU&p~0RtjoWRvRwBLg&GWRnpBH-G)mw%V7^ zje@#x)NP9(6`@iPR0=NBF)gWMrc5#gKTBK`6#M``O1zoUjcDK|_uiay?n%DB-#-DI zVTYk^gf>!*-TPqL7c=4C3@5@f88C+OgwMF^bGlu29fs0G824J3Wh=#yzKo{FPljQ) zZ!g108Tl++^D-4ujRK4A`hQ&OHbYL!vEn8Q1w*y}djJ7aBcG48L;g+}@_Z-12SM_leYso10rE$lk)>J2{d42 ULetDdxLK1g1Vsj?0{{R30AH)WsQ>@~ diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-2.jar b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-2.jar index 2353cb12a61ffb469cba10cb53d2a01914d6dc4d..5baf91e9a0a46d9038af123bee22d5cbaa91cfac 100644 GIT binary patch delta 455 zcmV;&0XY8o2>J*OP)h>@6aWYS2mr~NbFmHE0Ryp{bCc@e z=SD$YIOw)TkcvV_!w7Ap8awyF)D<(~Uk@k3GdVDZ%7o9j<8!)Qb}feTL>T8vm}M)&kiCee$4`b~ z*Nrd3NE!Jo9P=_2QjLNb-GB4B)*S|0%dz4n3I#*W{VhO%%*f|sZIQnlh5{eTfe5t> zRNNtTTPkh1^28oP%l+Ftv1GeaNpr?v9UKlA_W$=45MLO1CI~yRM81S7Y6YZGXUKOw zKjA4Lg?b6AsMwUX8PdJrkzUZgT~H3BmP22hD-{@S$gL*tcR>_-;(t>50w*+;2HB!$ z$26prqMW4Y+@z{X6{9nAG)LnV@!Fy&Qge->*vC3-GzrfVe3RzlRs2BeVUE@tHWpJU zY$tmznXeN(4~xDXg_xv-avv){P)i30kJ1J~S^)q60RjL3P)h*<6aW+e2mlBG$(nOQ x6}nG!q5%K^rw0H43X{YGD+95cbCdD|GYQO^b3%{O20>brE(Aper~?21002PiyHNlD delta 426 zcmV;b0agC`2>A#NP)h>@6aWYS2mmr*WU&p~0RtjoWRvRwBLg&GWRnpBH-G)mw%V7^ zje@#x)NP9(6`@iPR0=NBF)gWMrc5#gKTBK`6#M``O1zoUjcDK|_uiay?n%DB-#-DI zVTYk^gf>!*-TPqL7c=4C3@5@f88C+OgwMF^bGlu29fs0G824J3Wh=#yzKo{FPljQ) zZ!g108Tl++^D-4ujRK4A`hQ&OHbYL!vEn8Q1w*y}djJ7aBcG48L;g+}@_Z-12SM_leYso10rE$lk)>J2{d42 ULetDdxLK1g1Vsj?0{{R30AH)WsQ>@~