From 0cc861f00be75537e69582ee09af2c33779c709f Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 1 Oct 2015 21:10:50 +0300 Subject: [PATCH] Exposed visibility checking, a set of exposed visibility tests, some test fixes Effective visibility mechanism introduced. Local is considered as public, java protected as Kotlin protected, java package private as Kotlin private. --- .../jetbrains/kotlin/diagnostics/Errors.java | 10 ++ .../rendering/DefaultErrorMessages.java | 8 + .../kotlin/resolve/DeclarationsChecker.java | 111 +++++++++++++- .../nestedClassInPrivateClassObject.kt | 2 +- .../tests/enum/classObjectInEnumPrivate.kt | 2 +- .../testData/diagnostics/tests/enum/kt2834.kt | 2 +- .../diagnostics/tests/enum/kt2834.txt | 2 +- .../diagnostics/tests/exposed/delegate.kt | 6 + .../diagnostics/tests/exposed/delegate.txt | 21 +++ .../diagnostics/tests/exposed/functional.kt | 12 ++ .../diagnostics/tests/exposed/functional.txt | 19 +++ .../diagnostics/tests/exposed/implements.kt | 4 + .../diagnostics/tests/exposed/implements.txt | 14 ++ .../diagnostics/tests/exposed/internal.kt | 25 +++ .../diagnostics/tests/exposed/internal.txt | 54 +++++++ .../diagnostics/tests/exposed/local.kt | 22 +++ .../diagnostics/tests/exposed/local.txt | 13 ++ .../diagnostics/tests/exposed/nested.kt | 6 + .../diagnostics/tests/exposed/nested.txt | 22 +++ .../diagnostics/tests/exposed/protected.kt | 20 +++ .../diagnostics/tests/exposed/protected.txt | 46 ++++++ .../tests/exposed/protectedJava.kt | 16 ++ .../tests/exposed/protectedJava.txt | 38 +++++ .../tests/exposed/protectedSameWay.kt | 13 ++ .../tests/exposed/protectedSameWay.txt | 38 +++++ .../diagnostics/tests/exposed/simple.kt | 23 +++ .../diagnostics/tests/exposed/simple.txt | 34 +++++ .../diagnostics/tests/exposed/typeArgs.kt | 17 +++ .../diagnostics/tests/exposed/typeArgs.txt | 46 ++++++ .../tests/imports/ImportProtectedClass.kt | 6 +- .../tests/imports/ImportProtectedClass.txt | 6 +- .../PackageLocalClassReferencedError.kt | 2 +- .../PackageLocalClassReferencedError.txt | 2 +- .../imports/PrivateClassReferencedError.kt | 2 +- .../imports/PrivateClassReferencedError.txt | 2 +- .../j+k/canDeclareIfSamAdapterIsInherited.kt | 2 +- .../j+k/canDeclareIfSamAdapterIsInherited.txt | 4 +- .../tests/j+k/fieldOverridesNothing.kt | 2 +- .../tests/j+k/fieldOverridesNothing.txt | 4 +- .../tests/j+k/packageVisibility.kt | 12 +- .../tests/j+k/privateFieldOverridesNothing.kt | 2 +- .../j+k/privateFieldOverridesNothing.txt | 4 +- .../tests/j+k/recursiveRawUpperBound.kt | 4 +- .../tests/j+k/recursiveRawUpperBound.txt | 8 +- .../diagnostics/tests/j+k/types/arrayList.kt | 2 +- .../diagnostics/tests/j+k/types/arrayList.txt | 4 +- .../namedArguments/disallowForJavaMethods.kt | 2 +- .../namedArguments/disallowForJavaMethods.txt | 4 +- .../parameterNames/kotlinInheritsJava.kt | 2 +- .../parameterNames/kotlinInheritsJava.txt | 4 +- .../rawTypes/rawSupertypeOverride.kt | 4 +- .../rawTypes/rawSupertypeOverride.txt | 8 +- .../rawTypes/starProjectionToRaw.kt | 4 +- .../rawTypes/starProjectionToRaw.txt | 8 +- .../typeEnhancement/overriddenExtensions.kt | 2 +- .../typeEnhancement/overriddenExtensions.txt | 4 +- .../saveAnnotationAfterSubstitution.kt | 8 +- .../saveAnnotationAfterSubstitution.txt | 16 +- .../supertypeDifferentParameterNullability.kt | 4 +- ...supertypeDifferentParameterNullability.txt | 8 +- .../supertypeDifferentReturnNullability.kt | 4 +- .../supertypeDifferentReturnNullability.txt | 8 +- .../tests/privateInFile/visibility.kt | 4 +- .../tests/regressions/kt7585/java.kt | 4 +- .../tests/regressions/kt7585/java.txt | 6 +- .../diagnostics/tests/scopes/visibility2.kt | 4 +- .../diagnostics/tests/scopes/visibility3.kt | 4 +- .../testsWithStdLib/kt7585/delegate.kt | 8 +- .../testsWithStdLib/kt7585/delegate.txt | 10 +- .../checkers/JetDiagnosticsTestGenerated.java | 75 +++++++++ .../kotlin/load/java/JavaVisibilities.java | 7 + .../kotlin/descriptors/EffectiveVisibility.kt | 144 ++++++++++++++++++ .../kotlin/descriptors/Visibility.kt | 3 + 73 files changed, 965 insertions(+), 108 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/exposed/delegate.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/delegate.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/functional.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/functional.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/implements.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/implements.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/internal.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/internal.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/local.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/local.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/nested.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/nested.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/protected.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protected.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedJava.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedJava.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedSameWay.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedSameWay.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/simple.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/simple.txt create mode 100644 compiler/testData/diagnostics/tests/exposed/typeArgs.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/typeArgs.txt create mode 100644 core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 217130e6c53..d24053ec716 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.diagnostics; import com.google.common.collect.ImmutableSet; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiIdentifier; import com.intellij.psi.impl.source.tree.LeafPsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.*; @@ -72,6 +73,15 @@ public interface Errors { DiagnosticFactory3.create(ERROR); DiagnosticFactory3 INVISIBLE_MEMBER = DiagnosticFactory3.create(ERROR, CALL_ELEMENT); + // Exposed visibility group + DiagnosticFactory2 EXPOSED_PROPERTY_TYPE = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_FUNCTION_RETURN_TYPE = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_PARAMETER_TYPE = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_RECEIVER_TYPE = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_TYPE_PARAMETER_BOUND = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_SUPER_CLASS = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 EXPOSED_SUPER_INTERFACE = DiagnosticFactory2.create(WARNING); + DiagnosticFactory1> PLATFORM_CLASS_MAPPED_TO_KOTLIN = DiagnosticFactory1.create(WARNING); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index f6b4578d100..1cda341b04e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -112,6 +112,14 @@ public class DefaultErrorMessages { MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); + MAP.put(EXPOSED_PROPERTY_TYPE, "Deprecated: property effective visibility ''{0}'' should not be better than its type effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_FUNCTION_RETURN_TYPE, "Deprecated: function effective visibility ''{0}'' should not be better that its return type effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_PARAMETER_TYPE, "Deprecated: function effective visibility ''{0}'' should not be better than its parameter type effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_RECEIVER_TYPE, "Deprecated: member effective visibility ''{0}'' should not be better that its receiver type effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_TYPE_PARAMETER_BOUND, "Deprecated: generic effective visibility ''{0}'' should not be better than its type parameter bound effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_SUPER_CLASS, "Deprecated: subclass effective visibility ''{0}'' should not be better that its superclass effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(EXPOSED_SUPER_INTERFACE, "Deprecated: sub-interface effective visibility ''{0}'' should not be better that its super-interface effective visibility ''{1}''", TO_STRING, TO_STRING); + MAP.put(REDECLARATION, "Redeclaration: {0}", STRING); MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING); MAP.put(ACCESSOR_PARAMETER_NAME_SHADOWING, "Accessor parameter name 'field' is shadowed by backing field variable"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index cb27593a33a..b9e262b3e4c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -30,10 +30,7 @@ import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.JetTypeChecker; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.jetbrains.kotlin.diagnostics.Errors.*; import static org.jetbrains.kotlin.resolve.BindingContext.TYPE; @@ -86,6 +83,7 @@ public class DeclarationsChecker { checkPrimaryConstructor(classOrObject, classDescriptor); modifiersChecker.checkModifiersForDeclaration(classOrObject, classDescriptor); + checkClassExposedType(classOrObject, classDescriptor); } Map functions = bodiesResolveContext.getFunctions(); @@ -110,8 +108,8 @@ public class DeclarationsChecker { ConstructorDescriptor constructorDescriptor = entry.getValue(); JetSecondaryConstructor declaration = entry.getKey(); checkConstructorDeclaration(constructorDescriptor, declaration); + checkFunctionExposedType(declaration, constructorDescriptor); } - } private void checkConstructorDeclaration(ConstructorDescriptor constructorDescriptor, JetDeclaration declaration) { @@ -208,6 +206,57 @@ public class DeclarationsChecker { } } + private void checkClassExposedType(@NotNull JetClassOrObject klass, @NotNull ClassDescriptor classDescriptor) { + EffectiveVisibility classVisibility = EffectiveVisibility.Companion.forClass(classDescriptor); + boolean isInterface = classDescriptor.getKind() == ClassKind.INTERFACE; + List delegationList = klass.getDelegationSpecifiers(); + int i = -1; + // Encapsulate + for (JetType superType : classDescriptor.getTypeConstructor().getSupertypes()) { + i++; + if (i >= delegationList.size()) { + break; + } + ClassDescriptor superDescriptor = TypeUtils.getClassDescriptor(superType); + if (superDescriptor == null) { + continue; + } + boolean superIsInterface = superDescriptor.getKind() == ClassKind.INTERFACE; + if (superIsInterface != isInterface) { + continue; + } + EffectiveVisibility superTypeVisibility = EffectiveVisibility.Companion.forType(superType); + if (!superTypeVisibility.sameOrMorePermissive(classVisibility)) { + if (isInterface) { + trace.report(EXPOSED_SUPER_INTERFACE.on(delegationList.get(i), classVisibility, superTypeVisibility)); + } + else { + trace.report(EXPOSED_SUPER_CLASS.on(delegationList.get(i), classVisibility, superTypeVisibility)); + } + } + } + // Encapsulate + List typeParameterList = klass.getTypeParameters(); + int j = 0; + for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) { + if (j >= typeParameterList.size()) { + break; + } + for (JetType upperBound : typeParameterDescriptor.getUpperBounds()) { + EffectiveVisibility upperBoundVisibility = EffectiveVisibility.Companion.forType(upperBound); + if (!upperBoundVisibility.sameOrMorePermissive(classVisibility)) { + JetTypeParameter typeParameter = typeParameterList.get(i); + trace.report(EXPOSED_TYPE_PARAMETER_BOUND.on(typeParameter, classVisibility, upperBoundVisibility)); + break; + } + } + j++; + } + if (classDescriptor.getUnsubstitutedPrimaryConstructor() != null && klass.getPrimaryConstructor() != null) { + checkFunctionExposedType(klass.getPrimaryConstructor(), classDescriptor.getUnsubstitutedPrimaryConstructor()); + } + } + private static void removeDuplicateTypes(Set conflictingTypes) { for (Iterator iterator = conflictingTypes.iterator(); iterator.hasNext(); ) { JetType type = iterator.next(); @@ -241,6 +290,13 @@ public class DeclarationsChecker { else if (aClass instanceof JetEnumEntry) { checkEnumEntry((JetEnumEntry) aClass, classDescriptor); } + for (CallableMemberDescriptor memberDescriptor : classDescriptor.getDeclaredCallableMembers()) { + if (memberDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) continue; + JetNamedDeclaration member = (JetNamedDeclaration) DescriptorToSourceUtils.descriptorToDeclaration(memberDescriptor); + if (member instanceof JetFunction && memberDescriptor instanceof FunctionDescriptor) { + checkFunctionExposedType((JetFunction) member, (FunctionDescriptor) memberDescriptor); + } + } } private void checkPrimaryConstructor(JetClassOrObject classOrObject, ClassDescriptor classDescriptor) { @@ -321,6 +377,7 @@ public class DeclarationsChecker { checkPropertyLateInit(property, propertyDescriptor); checkPropertyInitializer(property, propertyDescriptor); checkAccessors(property, propertyDescriptor); + checkPropertyExposedType(property, propertyDescriptor); } private void checkPropertyLateInit(@NotNull JetCallableDeclaration property, @NotNull PropertyDescriptor propertyDescriptor) { @@ -488,6 +545,26 @@ public class DeclarationsChecker { } } + private void checkMemberReceiverExposedType(@Nullable JetTypeReference typeReference, @NotNull CallableMemberDescriptor memberDescriptor) { + if (typeReference == null) return; + ReceiverParameterDescriptor receiverParameterDescriptor = memberDescriptor.getExtensionReceiverParameter(); + if (receiverParameterDescriptor == null) return; + EffectiveVisibility memberVisibility = EffectiveVisibility.Companion.forMember(memberDescriptor); + EffectiveVisibility receiverTypeVisibility = EffectiveVisibility.Companion.forType(receiverParameterDescriptor.getType()); + if (!receiverTypeVisibility.sameOrMorePermissive(memberVisibility)) { + trace.report(EXPOSED_RECEIVER_TYPE.on(typeReference, memberVisibility, receiverTypeVisibility)); + } + } + + private void checkPropertyExposedType(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) { + EffectiveVisibility propertyVisibility = EffectiveVisibility.Companion.forMember(propertyDescriptor); + EffectiveVisibility typeVisibility = EffectiveVisibility.Companion.forType(propertyDescriptor.getType()); + if (!typeVisibility.sameOrMorePermissive(propertyVisibility)) { + trace.report(EXPOSED_PROPERTY_TYPE.on(property, propertyVisibility, typeVisibility)); + } + checkMemberReceiverExposedType(property.getReceiverTypeReference(), propertyDescriptor); + } + protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) { JetTypeParameterList typeParameterList = function.getTypeParameterList(); PsiElement nameIdentifier = function.getNameIdentifier(); @@ -527,6 +604,30 @@ public class DeclarationsChecker { if (!function.hasBody() && !hasAbstractModifier) { trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor)); } + checkFunctionExposedType(function, functionDescriptor); + } + + private void checkFunctionExposedType(@NotNull JetFunction function, @NotNull FunctionDescriptor functionDescriptor) { + EffectiveVisibility functionVisibility = EffectiveVisibility.Companion.forMember(functionDescriptor); + if (!(function instanceof JetConstructor)) { + EffectiveVisibility returnTypeVisibility = EffectiveVisibility.Companion.forType(functionDescriptor.getReturnType()); + if (!returnTypeVisibility.sameOrMorePermissive(functionVisibility)) { + PsiElement reportOn = function.getNameIdentifier(); + if (reportOn == null) { + reportOn = function; + } + trace.report(EXPOSED_FUNCTION_RETURN_TYPE.on(reportOn, functionVisibility, returnTypeVisibility)); + } + } + int i = 0; + for (ValueParameterDescriptor parameterDescriptor : functionDescriptor.getValueParameters()) { + EffectiveVisibility typeVisibility = EffectiveVisibility.Companion.forType(parameterDescriptor.getType()); + if (!typeVisibility.sameOrMorePermissive(functionVisibility) && i < function.getValueParameters().size()) { + trace.report(EXPOSED_PARAMETER_TYPE.on(function.getValueParameters().get(i), functionVisibility, typeVisibility)); + } + i++; + } + checkMemberReceiverExposedType(function.getReceiverTypeReference(), functionDescriptor); } private void checkAccessors(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) { diff --git a/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.kt b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.kt index 0674449e84c..cfc98fc83d2 100644 --- a/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.kt +++ b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.kt @@ -10,6 +10,6 @@ class A { } } -fun f1() = A.Companion.B.C +fun f1() = A.Companion.B.C fun f2() = A.Companion.B.C.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.kt b/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.kt index 7925a85afbd..c7c53eb48ef 100644 --- a/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.kt +++ b/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.kt @@ -7,4 +7,4 @@ enum class E { fun foo() = E.values() fun bar() = E.valueOf("ENTRY") fun baz() = E.ENTRY -fun quux() = E +fun quux() = E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/kt2834.kt b/compiler/testData/diagnostics/tests/enum/kt2834.kt index 44f26d5a35c..8144143dd11 100644 --- a/compiler/testData/diagnostics/tests/enum/kt2834.kt +++ b/compiler/testData/diagnostics/tests/enum/kt2834.kt @@ -3,4 +3,4 @@ private enum class MethodKind { STATIC } -fun MethodKind.hasThis() = this == MethodKind.INSTANCE +private fun MethodKind.hasThis() = this == MethodKind.INSTANCE diff --git a/compiler/testData/diagnostics/tests/enum/kt2834.txt b/compiler/testData/diagnostics/tests/enum/kt2834.txt index 77abc7c65d0..5e116a8eea1 100644 --- a/compiler/testData/diagnostics/tests/enum/kt2834.txt +++ b/compiler/testData/diagnostics/tests/enum/kt2834.txt @@ -1,6 +1,6 @@ package -public fun MethodKind.hasThis(): kotlin.Boolean +private fun MethodKind.hasThis(): kotlin.Boolean private final enum class MethodKind : kotlin.Enum { enum entry INSTANCE diff --git a/compiler/testData/diagnostics/tests/exposed/delegate.kt b/compiler/testData/diagnostics/tests/exposed/delegate.kt new file mode 100644 index 00000000000..e2e02550d2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/delegate.kt @@ -0,0 +1,6 @@ +interface My + +internal class Your: My + +// Code is valid, despite of delegate is internal +class His: My by Your() diff --git a/compiler/testData/diagnostics/tests/exposed/delegate.txt b/compiler/testData/diagnostics/tests/exposed/delegate.txt new file mode 100644 index 00000000000..969ae754ea6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/delegate.txt @@ -0,0 +1,21 @@ +package + +public final class His : My { + public constructor His() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface My { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Your : My { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/functional.kt b/compiler/testData/diagnostics/tests/exposed/functional.kt new file mode 100644 index 00000000000..deb98d95985 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/functional.kt @@ -0,0 +1,12 @@ +internal class My + +class Your + +// Both arguments should be exposed +fun foo(my: My, f: (My) -> Unit) = f(my) + +// Ok +fun bar(your: Your, f: (Your) -> Unit) = f(your) + +// Exposed, returns My +fun gav(f: () -> My) = f() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/functional.txt b/compiler/testData/diagnostics/tests/exposed/functional.txt new file mode 100644 index 00000000000..f50a591fff7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/functional.txt @@ -0,0 +1,19 @@ +package + +public fun bar(/*0*/ your: Your, /*1*/ f: (Your) -> kotlin.Unit): kotlin.Unit +public fun foo(/*0*/ my: My, /*1*/ f: (My) -> kotlin.Unit): kotlin.Unit +public fun gav(/*0*/ f: () -> My): My + +internal final class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Your { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/implements.kt b/compiler/testData/diagnostics/tests/exposed/implements.kt new file mode 100644 index 00000000000..8e26914c1fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/implements.kt @@ -0,0 +1,4 @@ +private interface My + +// valid, it's allowed to implement worse-visible interface +class Your: My \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/implements.txt b/compiler/testData/diagnostics/tests/exposed/implements.txt new file mode 100644 index 00000000000..f11dad2ed3d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/implements.txt @@ -0,0 +1,14 @@ +package + +private interface My { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Your : My { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/internal.kt b/compiler/testData/diagnostics/tests/exposed/internal.kt new file mode 100644 index 00000000000..255a3ad355d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internal.kt @@ -0,0 +1,25 @@ +internal open class My + +// valid, internal from internal +internal open class Your: My() { + // valid, effectively internal + fun foo() = My() +} + +// error, public from internal +open class His: Your() { + protected open class Nested + // error, public from internal + val x = My() + // valid, private from internal + private fun bar() = My() + // valid, internal from internal + internal var y: My? = null + // error, protected from internal + protected fun baz() = Your() +} + +internal class Their: His() { + // error, effectively internal from protected + class InnerDerived: His.Nested() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/internal.txt b/compiler/testData/diagnostics/tests/exposed/internal.txt new file mode 100644 index 00000000000..209ef78742a --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internal.txt @@ -0,0 +1,54 @@ +package + +public open class His : Your { + public constructor His() + public final val x: My + internal final var y: My? + private final fun bar(): My + protected final fun baz(): Your + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): My + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected open class Nested { + public constructor Nested() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +internal open class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Their : His { + public constructor Their() + public final override /*1*/ /*fake_override*/ val x: My + internal final override /*1*/ /*fake_override*/ var y: My? + invisible_fake final override /*1*/ /*fake_override*/ fun bar(): My + protected final override /*1*/ /*fake_override*/ fun baz(): Your + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): My + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class InnerDerived : His.Nested { + public constructor InnerDerived() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +internal open class Your : My { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): My + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/local.kt b/compiler/testData/diagnostics/tests/exposed/local.kt new file mode 100644 index 00000000000..27a29159e09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/local.kt @@ -0,0 +1,22 @@ +fun run(f: () -> T): T { + return f() +} + +// valid, A here is effectively Any +fun foo() = run { + class A + A() +} + +// valid, B here is also effectively Any +fun gav() = { + class B + B() +} + +abstract class My + +// valid, object literal here is also effectively Any +fun bar() = run { + object: My() {} +} diff --git a/compiler/testData/diagnostics/tests/exposed/local.txt b/compiler/testData/diagnostics/tests/exposed/local.txt new file mode 100644 index 00000000000..9940c7bbdeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/local.txt @@ -0,0 +1,13 @@ +package + +public fun bar(): My +public fun foo(): foo..A +public fun gav(): () -> gav..B +public fun run(/*0*/ f: () -> T): T + +public abstract class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/nested.kt b/compiler/testData/diagnostics/tests/exposed/nested.kt new file mode 100644 index 00000000000..57e35086ad8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/nested.kt @@ -0,0 +1,6 @@ +internal open class My + +internal class Outer { + // Ok, effectively internal from internal + class Your: My() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/nested.txt b/compiler/testData/diagnostics/tests/exposed/nested.txt new file mode 100644 index 00000000000..fc9d64764fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/nested.txt @@ -0,0 +1,22 @@ +package + +internal open class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Outer { + public constructor Outer() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class Your : My { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/protected.kt b/compiler/testData/diagnostics/tests/exposed/protected.kt new file mode 100644 index 00000000000..8c8b81c6504 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protected.kt @@ -0,0 +1,20 @@ +open class A { + // protected relative to A + protected open class B { + fun foo() {} + } + public open class C { + // protected relative to C, must be an error + protected open class D : B() + } +} + +class E : A.C() { + // F has invisible grandparent class B (E does not inherit from A) + class F : A.C.D() { + init { + // Invoke function from invisible grandparent + foo() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protected.txt b/compiler/testData/diagnostics/tests/exposed/protected.txt new file mode 100644 index 00000000000..77b38f5143d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protected.txt @@ -0,0 +1,46 @@ +package + +public open class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected open class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public open class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected open class D : A.B { + public constructor D() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} + +public final class E : A.C { + public constructor E() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class F : A.C.D { + public constructor F() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/protectedJava.kt b/compiler/testData/diagnostics/tests/exposed/protectedJava.kt new file mode 100644 index 00000000000..29096cf0d16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedJava.kt @@ -0,0 +1,16 @@ +// FILE: Outer.java + +public abstract class Outer { + protected static class My {} + protected static class Your extends My {} + abstract protected Your foo(My my); +} + +// FILE: OuterDerived.kt + +class OuterDerived: Outer() { + // valid, My has better visibility + protected class His: Outer.My() + // valid, My and Your have better visibility + override fun foo(my: Outer.My) = Outer.Your() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protectedJava.txt b/compiler/testData/diagnostics/tests/exposed/protectedJava.txt new file mode 100644 index 00000000000..2f2882f239e --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedJava.txt @@ -0,0 +1,38 @@ +package + +public abstract class Outer { + public constructor Outer() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ abstract fun foo(/*0*/ my: Outer.My!): Outer.Your! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected/*protected static*/ open class My { + protected/*protected and package*/ constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + protected/*protected static*/ open class Your : Outer.My { + protected/*protected and package*/ constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public final class OuterDerived : Outer { + public constructor OuterDerived() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected open override /*1*/ fun foo(/*0*/ my: Outer.My): Outer.Your + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected final class His : Outer.My { + public constructor His() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/protectedSameWay.kt b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.kt new file mode 100644 index 00000000000..9925008e88c --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.kt @@ -0,0 +1,13 @@ +abstract class Outer { + protected open class My + // Both valid: same way protected + protected class Your: My() + abstract protected fun foo(my: My): Your +} + +class OuterDerived: Outer() { + // valid, My has better visibility + protected class His: Outer.My() + // valid, My and Your have better visibility + override fun foo(my: Outer.My) = Outer.Your() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protectedSameWay.txt b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.txt new file mode 100644 index 00000000000..e5010fb456d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.txt @@ -0,0 +1,38 @@ +package + +public abstract class Outer { + public constructor Outer() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected abstract fun foo(/*0*/ my: Outer.My): Outer.Your + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected open class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + protected final class Your : Outer.My { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public final class OuterDerived : Outer { + public constructor OuterDerived() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected open override /*1*/ fun foo(/*0*/ my: Outer.My): Outer.Your + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + protected final class His : Outer.My { + public constructor His() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/simple.kt b/compiler/testData/diagnostics/tests/exposed/simple.kt new file mode 100644 index 00000000000..6c21a890bcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/simple.kt @@ -0,0 +1,23 @@ +private interface My + +private open class Base + +public interface Your: My { + fun foo(): T +} + +public class Derived<T: My>(val x: My): Base() { + + constructor(xx: My?, x: My): this(xx ?: x) + + val y: Base? = null + + val My.z: Int + get() = 42 + + fun foo(m: My): My = m + + fun My.bar(): My = this +} + + diff --git a/compiler/testData/diagnostics/tests/exposed/simple.txt b/compiler/testData/diagnostics/tests/exposed/simple.txt new file mode 100644 index 00000000000..c0b336d1280 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/simple.txt @@ -0,0 +1,34 @@ +package + +private open class Base { + public constructor Base() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Derived : Base { + public constructor Derived(/*0*/ x: My) + public constructor Derived(/*0*/ xx: My?, /*1*/ x: My) + public final val x: My + public final val y: Base? = null + public final val My.z: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ m: My): My + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public final fun My.bar(): My +} + +private interface My { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Your : My { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.kt b/compiler/testData/diagnostics/tests/exposed/typeArgs.kt new file mode 100644 index 00000000000..df59edbf9d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.kt @@ -0,0 +1,17 @@ +internal open class My + +abstract class Your { + // invalid, List is effectively internal + abstract fun give(): List +} + +// invalid, List is effectively internal +interface His: List + +// invalid, My is internal +interface Generic<E: My> + +interface Our { + // invalid, Generic is effectively internal + fun foo(): Generic<*> +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.txt b/compiler/testData/diagnostics/tests/exposed/typeArgs.txt new file mode 100644 index 00000000000..065a3b920d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.txt @@ -0,0 +1,46 @@ +package + +public interface Generic { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface His : kotlin.List { + public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun contains(/*0*/ o: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun containsAll(/*0*/ c: kotlin.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): My + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun indexOf(/*0*/ o: kotlin.Any?): kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun iterator(): kotlin.Iterator + public abstract override /*1*/ /*fake_override*/ fun lastIndexOf(/*0*/ o: kotlin.Any?): kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun listIterator(): kotlin.ListIterator + public abstract override /*1*/ /*fake_override*/ fun listIterator(/*0*/ index: kotlin.Int): kotlin.ListIterator + public abstract override /*1*/ /*fake_override*/ fun subList(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.List + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal open class My { + public constructor My() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Our { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): Generic<*> + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Your { + public constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun give(): kotlin.List + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.kt b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.kt index a23df5b740a..6bf844c4a54 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.kt +++ b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.kt @@ -7,8 +7,8 @@ open class Foo { } class Bar: Foo() { - fun foo(): Nested? = null + protected fun foo(): Nested? = null } -fun foo(): Nested? = null -fun bar(): p.Foo.Nested? = null \ No newline at end of file +private fun foo(): Nested? = null +private fun bar(): p.Foo.Nested? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.txt b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.txt index e7413b8be2c..788922b2e98 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.txt +++ b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.txt @@ -1,13 +1,13 @@ package package p { - public fun bar(): p.Foo.Nested? - public fun foo(): p.Foo.Nested? + private fun bar(): p.Foo.Nested? + private fun foo(): p.Foo.Nested? public final class Bar : p.Foo { public constructor Bar() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public final fun foo(): p.Foo.Nested? + protected final fun foo(): p.Foo.Nested? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.kt b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.kt index 44ae3b9cf9e..fd756a7e265 100644 --- a/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.kt +++ b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.kt @@ -8,4 +8,4 @@ package a import pack1.* -class X : SomeClass() \ No newline at end of file +private class X : SomeClass() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.txt b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.txt index f00763fff34..52672687bec 100644 --- a/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.txt +++ b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.txt @@ -2,7 +2,7 @@ package package a { - public final class X : pack1.SomeClass { + private final class X : pack1.SomeClass { public constructor X() invisible_fake open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean invisible_fake open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.kt b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.kt index 9a2e445528e..b8cf2d32a2f 100644 --- a/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.kt +++ b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.kt @@ -11,4 +11,4 @@ package a import pack1.SomeClass.* -class X : N() \ No newline at end of file +private class X : N() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.txt b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.txt index 63a655f64f6..4af7daf8a15 100644 --- a/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.txt +++ b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.txt @@ -2,7 +2,7 @@ package package a { - public final class X : pack1.SomeClass.N { + private final class X : pack1.SomeClass.N { public constructor X() invisible_fake open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean invisible_fake open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt index ada826483cd..be5480508d4 100644 --- a/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt +++ b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt @@ -1,5 +1,5 @@ // FILE: Super.java -class Super { +public class Super { void foo(Runnable r) { } } diff --git a/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.txt b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.txt index 97d748a814b..5994bb85cd4 100644 --- a/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.txt +++ b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.txt @@ -9,8 +9,8 @@ public final class Sub : Super { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ open class Super { - public/*package*/ constructor Super() +public open class Super { + public constructor Super() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public/*package*/ open fun foo(/*0*/ r: java.lang.Runnable!): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.kt b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.kt index 283dabc65d9..cd7dfa6e184 100644 --- a/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.kt +++ b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.kt @@ -1,6 +1,6 @@ // FILE: B.java -abstract class B implements A { +public abstract class B implements A { public int size = 1; } diff --git a/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.txt b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.txt index ad11dfc984d..0c4b5889e4b 100644 --- a/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.txt +++ b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.txt @@ -9,8 +9,8 @@ public interface A { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ abstract class B : A { - public/*package*/ constructor B() +public abstract class B : A { + public constructor B() public final var size: kotlin.Int public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/j+k/packageVisibility.kt b/compiler/testData/diagnostics/tests/j+k/packageVisibility.kt index 6fe2702aa13..f9c9689a978 100644 --- a/compiler/testData/diagnostics/tests/j+k/packageVisibility.kt +++ b/compiler/testData/diagnostics/tests/j+k/packageVisibility.kt @@ -16,29 +16,29 @@ class MyJavaClass { //FILE:a.kt package a -val mc = MyJavaClass() +val mc = MyJavaClass() val x = MyJavaClass.staticMethod() val y = MyJavaClass.NestedClass.staticMethodOfNested() -val z = MyJavaClass.NestedClass() +val z = MyJavaClass.NestedClass() //FILE: b.kt package b import a.MyJavaClass -val mc1 = MyJavaClass() +val mc1 = MyJavaClass() val x = MyJavaClass.staticMethod() val y = MyJavaClass.NestedClass.staticMethodOfNested() -val z = MyJavaClass.NestedClass() +val z = MyJavaClass.NestedClass() //FILE: c.kt package a.c import a.MyJavaClass -val mc1 = MyJavaClass() +val mc1 = MyJavaClass() val x = MyJavaClass.staticMethod() val y = MyJavaClass.NestedClass.staticMethodOfNested() -val z = MyJavaClass.NestedClass() +val z = MyJavaClass.NestedClass() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.kt b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.kt index 29b81383f80..56516cd67e4 100644 --- a/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.kt +++ b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.kt @@ -1,6 +1,6 @@ // FILE: B.java -abstract class B implements A { +public abstract class B implements A { private int size = 1; } diff --git a/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.txt b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.txt index 1a1c35f11aa..505d7936dd5 100644 --- a/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.txt +++ b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.txt @@ -9,8 +9,8 @@ public interface A { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ abstract class B : A { - public/*package*/ constructor B() +public abstract class B : A { + public constructor B() private final var size: kotlin.Int public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.kt b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.kt index afc8fc1e2eb..75a5c2333d8 100644 --- a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.kt +++ b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.kt @@ -1,10 +1,10 @@ // FILE: Bad.java -class Bad {} +public class Bad {} // FILE: X.java -class X { +public class X { Bad foo() {return null;} } diff --git a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.txt b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.txt index 22a82b1c65b..66b18369dd0 100644 --- a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.txt +++ b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.txt @@ -2,15 +2,15 @@ package public fun foo(/*0*/ p: X): Bad<(raw) Bad<*>!>! -public/*package*/ open class Bad>!> { - public/*package*/ constructor Bad>!>() +public open class Bad>!> { + public constructor Bad>!>() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ open class X { - public/*package*/ constructor X() +public open class X { + public constructor X() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public/*package*/ open fun foo(): Bad<(raw) Bad<*>!>! public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/j+k/types/arrayList.kt b/compiler/testData/diagnostics/tests/j+k/types/arrayList.kt index 6e405cc393e..68825e9c8d8 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/arrayList.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/arrayList.kt @@ -10,6 +10,6 @@ class K : J(), ML import java.util.*; -class J extends ML { +public class J extends ML { public List foo() { return null; } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/types/arrayList.txt b/compiler/testData/diagnostics/tests/j+k/types/arrayList.txt index 19e05a932b4..c28413e261b 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/arrayList.txt +++ b/compiler/testData/diagnostics/tests/j+k/types/arrayList.txt @@ -1,7 +1,7 @@ package -public/*package*/ open class J : ML { - public/*package*/ constructor J() +public open class J : ML { + public constructor J() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ fun foo(): kotlin.MutableList public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.kt index ed7c12716bf..64e32ae0524 100644 --- a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.kt +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.kt @@ -1,6 +1,6 @@ // FILE: JavaSuperClass.java -class JavaSuperClass { +public class JavaSuperClass { public void foo(int javaName) {} public void multipleParameters(int first, long second, String third) {} diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.txt b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.txt index 9c1fa2bb422..c6e986c171d 100644 --- a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.txt +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.txt @@ -6,8 +6,8 @@ public fun unresolvedParameter(): kotlin.Unit public fun viaFakeOverride(): kotlin.Unit public fun viaRealOverride(): kotlin.Unit -public/*package*/ open class JavaSuperClass { - public/*package*/ constructor JavaSuperClass() +public open class JavaSuperClass { + public constructor JavaSuperClass() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open fun foo(/*0*/ javaName: kotlin.Int): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.kt b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.kt index 46b4e945af2..1e7d997c393 100644 --- a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.kt +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.kt @@ -1,6 +1,6 @@ // FILE: JavaInterface.java -interface JavaInterface { +public interface JavaInterface { void foo(int javaName); } diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.txt b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.txt index b3b5bd3d541..bacefabb772 100644 --- a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.txt +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.txt @@ -1,8 +1,8 @@ package -public/*package*/ /*synthesized*/ fun JavaInterface(/*0*/ function: (kotlin.Int) -> kotlin.Unit): JavaInterface +public /*synthesized*/ fun JavaInterface(/*0*/ function: (kotlin.Int) -> kotlin.Unit): JavaInterface -public/*package*/ interface JavaInterface { +public interface JavaInterface { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(/*0*/ javaName: kotlin.Int): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.kt index 54353a9648e..afb0cc00c5f 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.kt @@ -3,7 +3,7 @@ import java.util.*; -class A { +public class A { A> foo(T x, Map> y, HashMap z) {} void bar(List[][] d) {} @@ -11,7 +11,7 @@ class A { // FILE: RawADerived.java -class RawADerived extends A { +public class RawADerived extends A { } // FILE: main.kt diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.txt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.txt index 91daba71ae6..3c45bfeed4b 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.txt @@ -1,7 +1,7 @@ package -public/*package*/ open class A { - public/*package*/ constructor A() +public open class A { + public constructor A() public/*package*/ open fun bar(/*0*/ d: kotlin.Array<(out) kotlin.Array<(out) kotlin.(Mutable)List!>!>!>!): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public/*package*/ open fun foo(/*0*/ x: T!, /*1*/ y: kotlin.(Mutable)Map!>!, /*2*/ z: java.util.HashMap!): A!>! @@ -47,8 +47,8 @@ public final class B4 : RawADerived { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String(raw) } -public/*package*/ open class RawADerived : A { - public/*package*/ constructor RawADerived() +public open class RawADerived : A { + public constructor RawADerived() public/*package*/ open override /*1*/ /*fake_override*/ fun bar(/*0*/ d: kotlin.Array<(out) kotlin.Array<(out) kotlin.(Mutable)List<(raw) kotlin.Any?>!>!>!): kotlin.Unit(raw) public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any(raw)?): kotlin.Boolean(raw) public/*package*/ open override /*1*/ /*fake_override*/ fun foo(/*0*/ x: kotlin.CharSequence(raw)!, /*1*/ y: kotlin.(Mutable)Map<(raw) kotlin.Any?, (raw) kotlin.Any?>!, /*2*/ z: java.util.HashMap<(raw) kotlin.Any!, (raw) kotlin.Any!>!): A<(raw) kotlin.CharSequence!>! diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.kt index 1d679597497..4a89c3ce777 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.kt @@ -3,13 +3,13 @@ import java.util.*; -class A {} +public class A {} // FILE: B.java import java.util.*; -class B {} +public class B {} // FILE: Test.java diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.txt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.txt index 0ad66bf17dc..72e81368c5b 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.txt @@ -2,15 +2,15 @@ package public fun main(/*0*/ x: B<*>): kotlin.Unit -public/*package*/ open class A { - public/*package*/ constructor A() +public open class A { + public constructor A() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ open class B!> { - public/*package*/ constructor B!>() +public open class B!> { + public constructor B!>() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.kt index de20c235879..0ce6240dbd4 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.kt @@ -33,7 +33,7 @@ class B extends A { import org.jetbrains.annotations.*; // Just inherit enhanced types (annotations without conflicts) -class B1 extends A { +public class B1 extends A { @Override public int foo(@NotNull String x, String y); @Override diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.txt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.txt index 4dcfa73f55d..a89416aa028 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.txt @@ -18,8 +18,8 @@ public/*package*/ open class B : A { @java.lang.Override() public/*package*/ open override /*1*/ fun kotlin.String.foo(/*0*/ y: kotlin.String?): kotlin.Int } -public/*package*/ open class B1 : A { - public/*package*/ constructor B1() +public open class B1 : A { + public constructor B1() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt index 33bdd9ca0f1..eec3e23f4a8 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt @@ -2,19 +2,19 @@ import org.jetbrains.annotations.*; -interface A { +public interface A { void foo(@NotNull T x, @Nullable T y); } // FILE: B1.java // contains fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) -interface B1 extends A {} +public interface B1 extends A {} // FILE: B2.java import org.jetbrains.annotations.*; -interface B2 extends A { +public interface B2 extends A { // Ok, consistent override // override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) void foo(@NotNull String x, @Nullable String y); @@ -23,7 +23,7 @@ interface B2 extends A { // FILE: B3.java import org.jetbrains.annotations.*; -interface B3 extends A { +public interface B3 extends A { // inconsistent override, second parameter type is platform // TODO: first one should be platform too, but it's not because when substituting T -> String!, // value parameter type becomes platform and it can be overridden with @NotNull String. diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.txt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.txt index d3944a86d36..bf1f673f3a5 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.txt @@ -1,32 +1,32 @@ package -public/*package*/ /*synthesized*/ fun A(/*0*/ function: (T!, T!) -> kotlin.Unit): A -public/*package*/ /*synthesized*/ fun B1(/*0*/ function: (kotlin.String!, kotlin.String?) -> kotlin.Unit): B1 -public/*package*/ /*synthesized*/ fun B2(/*0*/ function: (kotlin.String!, kotlin.String!) -> kotlin.Unit): B2 -public/*package*/ /*synthesized*/ fun B3(/*0*/ function: (kotlin.String!, kotlin.String!) -> kotlin.Unit): B3 +public /*synthesized*/ fun A(/*0*/ function: (T!, T!) -> kotlin.Unit): A +public /*synthesized*/ fun B1(/*0*/ function: (kotlin.String!, kotlin.String?) -> kotlin.Unit): B1 +public /*synthesized*/ fun B2(/*0*/ function: (kotlin.String!, kotlin.String!) -> kotlin.Unit): B2 +public /*synthesized*/ fun B3(/*0*/ function: (kotlin.String!, kotlin.String!) -> kotlin.Unit): B3 -public/*package*/ interface A { +public interface A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(/*0*/ @org.jetbrains.annotations.NotNull() x: T, /*1*/ @org.jetbrains.annotations.Nullable() y: T?): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface B1 : A { +public interface B1 : A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ @org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ @org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface B2 : A { +public interface B2 : A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract override /*1*/ fun foo(/*0*/ @org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ @org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface B3 : A { +public interface B3 : A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract override /*1*/ fun foo(/*0*/ @org.jetbrains.annotations.Nullable() x: kotlin.String?, /*1*/ @org.jetbrains.annotations.NotNull() y: kotlin.String!): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.kt index 1d50f6f48ce..f0f8092e51c 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.kt @@ -1,14 +1,14 @@ // FILE: A.java import org.jetbrains.annotations.*; -interface A { +public interface A { void foo(@Nullable String x); } // FILE: B.java import org.jetbrains.annotations.*; -interface B { +public interface B { void foo(@NotNull String x); } diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.txt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.txt index 42db3d4d35b..4bdf98d4c2e 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.txt @@ -1,16 +1,16 @@ package -public/*package*/ /*synthesized*/ fun A(/*0*/ function: (kotlin.String!) -> kotlin.Unit): A -public/*package*/ /*synthesized*/ fun B(/*0*/ function: (kotlin.String!) -> kotlin.Unit): B +public /*synthesized*/ fun A(/*0*/ function: (kotlin.String!) -> kotlin.Unit): A +public /*synthesized*/ fun B(/*0*/ function: (kotlin.String!) -> kotlin.Unit): B -public/*package*/ interface A { +public interface A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(/*0*/ @org.jetbrains.annotations.Nullable() x: kotlin.String?): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface B { +public interface B { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(/*0*/ @org.jetbrains.annotations.NotNull() x: kotlin.String): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.kt index fbc8c65470a..1ed1ab66af4 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.kt @@ -1,7 +1,7 @@ // FILE: A.java import org.jetbrains.annotations.*; -interface A { +public interface A { @Nullable String foo(); } @@ -9,7 +9,7 @@ interface A { // FILE: B.java import org.jetbrains.annotations.*; -interface B { +public interface B { @NotNull String foo(); } diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.txt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.txt index ca0249ed359..1b5d34c1d19 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.txt @@ -1,16 +1,16 @@ package -public/*package*/ /*synthesized*/ fun A(/*0*/ function: () -> kotlin.String!): A -public/*package*/ /*synthesized*/ fun B(/*0*/ function: () -> kotlin.String!): B +public /*synthesized*/ fun A(/*0*/ function: () -> kotlin.String!): A +public /*synthesized*/ fun B(/*0*/ function: () -> kotlin.String!): B -public/*package*/ interface A { +public interface A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @org.jetbrains.annotations.Nullable() public abstract fun foo(): kotlin.String? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface B { +public interface B { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/privateInFile/visibility.kt b/compiler/testData/diagnostics/tests/privateInFile/visibility.kt index cd4b2a5f24d..408af8ed52b 100644 --- a/compiler/testData/diagnostics/tests/privateInFile/visibility.kt +++ b/compiler/testData/diagnostics/tests/privateInFile/visibility.kt @@ -20,7 +20,7 @@ private fun bar() { xx = 30 } -fun makeA() = A() +fun makeA() = A() private object PO {} @@ -43,7 +43,7 @@ fun test() { xx = 40 } -class B : A() {} +class B : A() {} class Q { class W { diff --git a/compiler/testData/diagnostics/tests/regressions/kt7585/java.kt b/compiler/testData/diagnostics/tests/regressions/kt7585/java.kt index 78dfe7620b6..e81d97b1f80 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt7585/java.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt7585/java.kt @@ -1,10 +1,10 @@ // FILE: A.java -class A {} +public class A {} // FILE: Wrapper.java -abstract class Wrapper { +public abstract class Wrapper { protected T t; Wrapper(T t) { this.t = t; } diff --git a/compiler/testData/diagnostics/tests/regressions/kt7585/java.txt b/compiler/testData/diagnostics/tests/regressions/kt7585/java.txt index 2ab80c3d350..0ba058571ba 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt7585/java.txt +++ b/compiler/testData/diagnostics/tests/regressions/kt7585/java.txt @@ -2,8 +2,8 @@ package public fun foo(): kotlin.String -public/*package*/ open class A { - public/*package*/ constructor A() +public open class A { + public constructor A() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String @@ -44,7 +44,7 @@ public final class TheirWrapper : Wrapper { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ abstract class Wrapper { +public abstract class Wrapper { public/*package*/ constructor Wrapper(/*0*/ t: T!) protected/*protected and package*/ final var t: T! public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/scopes/visibility2.kt b/compiler/testData/diagnostics/tests/scopes/visibility2.kt index 63f5e9ba81f..62c31733a8d 100644 --- a/compiler/testData/diagnostics/tests/scopes/visibility2.kt +++ b/compiler/testData/diagnostics/tests/scopes/visibility2.kt @@ -9,7 +9,7 @@ private open class A { private fun foo() {} -fun makeA() = A() +fun makeA() = A() private object PO {} @@ -33,7 +33,7 @@ fun test() { val po = PO } -class B : A() {} +class B : A() {} class Q { class W { diff --git a/compiler/testData/diagnostics/tests/scopes/visibility3.kt b/compiler/testData/diagnostics/tests/scopes/visibility3.kt index 8a5790008f0..637a56d2103 100644 --- a/compiler/testData/diagnostics/tests/scopes/visibility3.kt +++ b/compiler/testData/diagnostics/tests/scopes/visibility3.kt @@ -16,7 +16,7 @@ private fun bar() { x = 20 } -fun makeA() = A() +fun makeA() = A() private object PO {} @@ -36,7 +36,7 @@ fun test() { val po = PO } -class B : A() {} +class B : A() {} class Q { class W { diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.kt b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.kt index 8d0195242ee..be39490e5a2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.kt @@ -1,18 +1,18 @@ // FILE: Base.java -interface Base {} +public interface Base {} // FILE: Other.java -interface Other {} +public interface Other {} // FILE: Derived.java -final class Derived implements Base, Other {} +public final class Derived implements Base, Other {} // FILE: Exotic.java -final class Exotic implements Base, Other { +public final class Exotic implements Base, Other { int x; diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.txt b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.txt index c833b849150..96957778aa1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.txt @@ -1,13 +1,13 @@ package -public/*package*/ interface Base { +public interface Base { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ final class Derived : Base, Other { - public/*package*/ constructor Derived() +public final class Derived : Base, Other { + public constructor Derived() public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String @@ -21,7 +21,7 @@ public final class DerivedWrapper : Wrapper> { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ final class Exotic : Base, Other { +public final class Exotic : Base, Other { public/*package*/ constructor Exotic(/*0*/ x: kotlin.Int) public/*package*/ final var x: kotlin.Int public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -57,7 +57,7 @@ public object MyBase { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public/*package*/ interface Other { +public interface Other { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 50ef2711694..dd4751b473a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -5734,6 +5734,81 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { } } + @TestMetadata("compiler/testData/diagnostics/tests/exposed") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Exposed extends AbstractJetDiagnosticsTest { + public void testAllFilesPresentInExposed() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/exposed"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("delegate.kt") + public void testDelegate() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/delegate.kt"); + doTest(fileName); + } + + @TestMetadata("functional.kt") + public void testFunctional() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/functional.kt"); + doTest(fileName); + } + + @TestMetadata("implements.kt") + public void testImplements() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/implements.kt"); + doTest(fileName); + } + + @TestMetadata("internal.kt") + public void testInternal() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/internal.kt"); + doTest(fileName); + } + + @TestMetadata("local.kt") + public void testLocal() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/local.kt"); + doTest(fileName); + } + + @TestMetadata("nested.kt") + public void testNested() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/nested.kt"); + doTest(fileName); + } + + @TestMetadata("protected.kt") + public void testProtected() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/protected.kt"); + doTest(fileName); + } + + @TestMetadata("protectedJava.kt") + public void testProtectedJava() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/protectedJava.kt"); + doTest(fileName); + } + + @TestMetadata("protectedSameWay.kt") + public void testProtectedSameWay() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/protectedSameWay.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/simple.kt"); + doTest(fileName); + } + + @TestMetadata("typeArgs.kt") + public void testTypeArgs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/typeArgs.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/tests/extensions") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JavaVisibilities.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JavaVisibilities.java index c0e6dcb91d9..5008e2703ff 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JavaVisibilities.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JavaVisibilities.java @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.load.java; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; @@ -54,6 +55,12 @@ public class JavaVisibilities { public Visibility normalize() { return Visibilities.PROTECTED; } + + @NotNull + @Override + public EffectiveVisibility effectiveVisibility(@Nullable ClassDescriptor classDescriptor) { + return EffectiveVisibility.Companion.effectiveVisibility(Visibilities.PRIVATE, classDescriptor); + } }; public static final Visibility PROTECTED_STATIC_VISIBILITY = new Visibility("protected_static", true) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt new file mode 100644 index 00000000000..0c92d9d5418 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt @@ -0,0 +1,144 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.descriptors + +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.types.TypeConstructor + +sealed class EffectiveVisibility(val name: String) { + + override fun toString() = name + + object Private : EffectiveVisibility("private") { + override fun relation(other: EffectiveVisibility) = + if (this == other) Permissiveness.SAME else Permissiveness.LESS + } + + object Public : EffectiveVisibility("public") { + override fun relation(other: EffectiveVisibility) = + if (this == other) Permissiveness.SAME else Permissiveness.MORE + } + + object Internal : EffectiveVisibility("internal") { + override fun relation(other: EffectiveVisibility) = when (other) { + Public -> Permissiveness.LESS + Private -> Permissiveness.MORE + is Protected -> Permissiveness.UNKNOWN + Internal -> Permissiveness.SAME + } + } + + class Protected(val container: ClassDescriptor?) : EffectiveVisibility("protected") { + + override fun equals(other: Any?) = (other is Protected && container == other.container) + + override fun hashCode() = container?.hashCode() ?: 0 + + override fun toString() = "${super.toString()}(${container?.name ?: '?'})" + + override fun relation(other: EffectiveVisibility) = when (other) { + Public -> Permissiveness.LESS + Private -> Permissiveness.MORE + is Protected -> { + if (container == null || other.container == null) { + Permissiveness.UNKNOWN + } + else if (container == other.container) { + Permissiveness.SAME + } + else if (DescriptorUtils.isSubclass(container, other.container)) { + Permissiveness.LESS + } + else if (DescriptorUtils.isSubclass(other.container, container)) { + Permissiveness.MORE + } + else { + Permissiveness.UNKNOWN + } + } + Internal -> Permissiveness.UNKNOWN + } + } + + private enum class Permissiveness { + LESS, + SAME, + MORE, + UNKNOWN + } + + abstract fun relation(other: EffectiveVisibility): Permissiveness + + fun sameOrMorePermissive(other: EffectiveVisibility) = when (relation(other)) { + Permissiveness.SAME, Permissiveness.MORE -> true + Permissiveness.LESS, Permissiveness.UNKNOWN -> false + } + + fun lowerBound(other: EffectiveVisibility) = when (relation(other)) { + Permissiveness.SAME, Permissiveness.LESS -> this + Permissiveness.MORE -> other + Permissiveness.UNKNOWN -> Private + } + + companion object { + + private fun lowerBound(first: EffectiveVisibility, second: EffectiveVisibility) = + first.lowerBound(second) + + private fun lowerBound(first: EffectiveVisibility, args: List) = + args.fold(first, { x, y -> x.lowerBound(y) }) + + private fun Visibility.forVisibility(descriptor: ClassDescriptor? = null): EffectiveVisibility = when (this) { + Visibilities.PRIVATE, Visibilities.PRIVATE_TO_THIS -> Private + Visibilities.PROTECTED -> Protected(descriptor) + Visibilities.INTERNAL -> Internal + Visibilities.PUBLIC -> Public + // Considered effectively public + Visibilities.LOCAL -> Public + else -> this.effectiveVisibility(descriptor) + } + + fun effectiveVisibility(visibility: Visibility, descriptor: ClassDescriptor?) = visibility.forVisibility(descriptor) + + private fun ClassifierDescriptor.forClassifier(): EffectiveVisibility = + lowerBound(if (this is ClassDescriptor) this.forClass() else Public, + (this.containingDeclaration as? ClassifierDescriptor)?.forClassifier() ?: Public) + + fun ClassDescriptor.forClass() = forClass(emptySet()) + + private fun ClassDescriptor.forClass(classes: Set): EffectiveVisibility = + if (this in classes) Public + else with(this.containingDeclaration as? ClassDescriptor) { + lowerBound(visibility.forVisibility(this), this?.forClass(classes + this@forClass) ?: Public) + } + + fun JetType.forType() = forType(emptySet()) + + private fun JetType.forType(types: Set): EffectiveVisibility = + if (this in types) Public + else lowerBound(constructor.forTypeConstructor(), + arguments.map { it.type.forType(types + this) } ) + + private fun TypeConstructor.forTypeConstructor() = + this.declarationDescriptor?.forClassifier() ?: Public + + fun MemberDescriptor.forMember() = + lowerBound(visibility.forVisibility(this.containingDeclaration as? ClassDescriptor), + (this.containingDeclaration as? ClassDescriptor)?.forClass() ?: Public) + } +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibility.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibility.kt index 4db61bd1756..a72a25a662d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibility.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibility.kt @@ -49,4 +49,7 @@ public abstract class Visibility protected constructor( override final fun toString() = displayName public open fun normalize(): Visibility = this + + // Should be overloaded in Java visibilities + public open fun effectiveVisibility(descriptor: ClassDescriptor?) = EffectiveVisibility.effectiveVisibility(normalize(), descriptor) }