Skip to content

Commit

Permalink
Properly resolve descriptors from compiled kotlin
Browse files Browse the repository at this point in the history
Added protected flag for annotation
  • Loading branch information
Mikhael Bogdanov committed Mar 20, 2013
1 parent 001a27f commit 86f5114
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static int getFlagsForVisibility(@NotNull Visibility visibility) {
else if (visibility == Visibilities.PRIVATE) {
return JvmStdlibNames.FLAG_PRIVATE_BIT;
}
else if (visibility == Visibilities.PROTECTED) {
return JvmStdlibNames.FLAG_PROTECTED_BIT;
}
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public static Visibility resolveVisibility(
else if (annotation.hasInternalFlag()) {
return Visibilities.INTERNAL;
}
else if (annotation.hasProtectedFlag()) {
return Visibilities.PROTECTED;
}
}

if (modifierListOwner.hasModifierProperty(PsiModifier.PUBLIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_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 << 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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public final boolean hasForceOpenFlag() {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ private boolean includeMember(PsiMemberWrapper member) {
return false;
}

if (member.isPrivate()) {
//process private accessors
if (member.isPrivate()
&& !(member instanceof PsiMethodWrapper && ((PsiMethodWrapper)member).getJetMethodAnnotation().hasPropertyFlag())) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
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;
Expand Down Expand Up @@ -235,7 +232,7 @@ private PropertyDescriptor resolveProperty(
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);
Expand Down Expand Up @@ -274,20 +271,27 @@ private JetType getAlternativeSignatureData(
}

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<PsiParameterWrapper> 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.<AnnotationDescriptor>emptyList(),
Name.identifier("p0") /*TODO*/,
Name.identifierNoValidate(valueParameter.getJetValueParameter().name()),
propertyDescriptor.getType(),
false,
null));
Expand Down Expand Up @@ -325,7 +329,7 @@ private PropertyGetterDescriptorImpl resolveGetter(
return new PropertyGetterDescriptorImpl(
propertyDescriptor,
annotationResolver.resolveAnnotations(getter.getMember().getPsiMember()),
Modality.OPEN,
propertyDescriptor.getModality(),
visibility,
true,
false,
Expand All @@ -352,7 +356,7 @@ private PropertySetterDescriptorImpl resolveSetter(
return new PropertySetterDescriptorImpl(
propertyDescriptor,
annotationResolver.resolveAnnotations(setter.getMember().getPsiMember()),
Modality.OPEN,
propertyDescriptor.getModality(),
setterVisibility,
true,
false,
Expand Down
4 changes: 2 additions & 2 deletions compiler/testData/cli/wrongAbiVersion.out
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Binary file not shown.

0 comments on commit 86f5114

Please sign in to comment.