Create PRIVATE_TO_THIS visibility
This commit is contained in:
@@ -88,6 +88,7 @@ public class AsmUtil {
|
||||
@NotNull
|
||||
private static final Map<Visibility, Integer> visibilityToAccessFlag = ImmutableMap.<Visibility, Integer>builder()
|
||||
.put(Visibilities.PRIVATE, ACC_PRIVATE)
|
||||
.put(Visibilities.PRIVATE_TO_THIS, ACC_PRIVATE)
|
||||
.put(Visibilities.PROTECTED, ACC_PROTECTED)
|
||||
.put(JavaVisibilities.PROTECTED_STATIC_VISIBILITY, ACC_PROTECTED)
|
||||
.put(JavaVisibilities.PROTECTED_AND_PACKAGE, ACC_PROTECTED)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class A<in I>(init_o: I, private val init_k: I) {
|
||||
private val o: I = init_o
|
||||
private fun k(): I = init_k
|
||||
|
||||
fun getOk() = o.toString() + k().toString()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A("O", "K")
|
||||
return a.getOk()
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package
|
||||
internal trait Test</*0*/ in I, /*1*/ out O> {
|
||||
internal abstract var interlan_private_set: O
|
||||
internal abstract val internal_val: I
|
||||
private abstract var private_private_set: O
|
||||
private abstract val private_val: I
|
||||
private/*private to this*/ abstract var private_private_set: O
|
||||
private/*private to this*/ abstract val private_val: I
|
||||
protected abstract var protected_private_set: O
|
||||
protected abstract val protected_val: I
|
||||
public abstract var public_private_set: O
|
||||
@@ -12,7 +12,7 @@ internal trait Test</*0*/ in I, /*1*/ out O> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal abstract fun internal_fun(/*0*/ i: O): I
|
||||
private abstract fun private_fun(/*0*/ i: O): I
|
||||
private/*private to this*/ abstract fun private_fun(/*0*/ i: O): I
|
||||
protected abstract fun protected_fun(/*0*/ i: O): I
|
||||
public abstract fun public_fun(/*0*/ i: O): I
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
@@ -1466,6 +1466,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateToThis.kt")
|
||||
public void testPrivateToThis() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/privateToThis.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyDelegation.kt")
|
||||
public void testPropertyDelegation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/propertyDelegation.kt");
|
||||
|
||||
@@ -20,6 +20,7 @@ import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
@@ -58,7 +59,24 @@ public class Visibilities {
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility PRIVATE_TO_THIS = PRIVATE;
|
||||
public static final Visibility PRIVATE_TO_THIS = new Visibility("private_to_this", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue thisObject, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
if (PRIVATE.isVisible(thisObject, what, from)) {
|
||||
DeclarationDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||
|
||||
if (classDescriptor != null && thisObject instanceof ClassReceiver) {
|
||||
return ((ClassReceiver) thisObject).getDeclarationDescriptor().getOriginal() == classDescriptor.getOriginal();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "private/*private to this*/";
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility PROTECTED = new Visibility("protected", true) {
|
||||
@Override
|
||||
@@ -116,7 +134,7 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Set<Visibility> INVISIBLE_FROM_OTHER_MODULES =
|
||||
Collections.unmodifiableSet(KotlinPackage.setOf(PRIVATE, INTERNAL, LOCAL));
|
||||
Collections.unmodifiableSet(KotlinPackage.setOf(PRIVATE, PRIVATE_TO_THIS, INTERNAL, LOCAL));
|
||||
|
||||
private Visibilities() {
|
||||
}
|
||||
@@ -154,6 +172,7 @@ public class Visibilities {
|
||||
|
||||
static {
|
||||
Map<Visibility, Integer> visibilities = UtilsPackage.newHashMapWithExpectedSize(4);
|
||||
visibilities.put(PRIVATE_TO_THIS, 0);
|
||||
visibilities.put(PRIVATE, 0);
|
||||
visibilities.put(INTERNAL, 1);
|
||||
visibilities.put(PROTECTED, 1);
|
||||
|
||||
Reference in New Issue
Block a user