Clearify diagnostic messages that involve internal visibilities
KT-7354 Fixed Visibility.displayText is deprecated with warning. Diagnostics for java visibilities changed.
This commit is contained in:
+2
-2
@@ -101,7 +101,7 @@ class SignatureDumpingBuilderFactory(
|
||||
origin.descriptor?.let {
|
||||
outputStream.append("\t\t").appendNameValue("declaration", TYPE_RENDERER.render(it)).append(",\n")
|
||||
(it as? DeclarationDescriptorWithVisibility)?.visibility?.let {
|
||||
outputStream.append("\t\t").appendNameValue("visibility", it.displayName).append(",\n")
|
||||
outputStream.append("\t\t").appendNameValue("visibility", it.internalDisplayName).append(",\n")
|
||||
}
|
||||
}
|
||||
outputStream.append("\t\t").appendNameValue("class", javaClassName).append(",\n")
|
||||
@@ -112,7 +112,7 @@ class SignatureDumpingBuilderFactory(
|
||||
append("\t\t\t{")
|
||||
descriptor?.let {
|
||||
(it as? DeclarationDescriptorWithVisibility)?.visibility?.let {
|
||||
appendNameValue("visibility", it.displayName).append(",\t")
|
||||
appendNameValue("visibility", it.internalDisplayName).append(",\t")
|
||||
}
|
||||
appendNameValue("declaration", MEMBER_RENDERER.render(it)).append(", ")
|
||||
|
||||
|
||||
+5
@@ -9062,6 +9062,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckJavaVisibility2.kt")
|
||||
public void testCheckJavaVisibility2() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckVisibility.kt")
|
||||
public void testCheckVisibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckVisibility.kt");
|
||||
|
||||
+2
-2
@@ -53,8 +53,8 @@ fun syntheticVisibility(originalDescriptor: DeclarationDescriptorWithVisibility,
|
||||
override fun normalize()
|
||||
= originalVisibility.normalize()
|
||||
|
||||
override val displayName: String
|
||||
get() = originalVisibility.displayName + " for synthetic extension"
|
||||
override val internalDisplayName: String
|
||||
get() = originalVisibility.internalDisplayName + " for synthetic extension"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,12 @@ import com.google.common.collect.Lists
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.analyzer.moduleInfo
|
||||
import org.jetbrains.kotlin.analyzer.unwrapPlatform
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.cfg.WhenMissingCase
|
||||
import org.jetbrains.kotlin.cfg.hasUnknown
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
||||
@@ -39,7 +36,6 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer.Companion.DEBUG_TEXT
|
||||
import org.jetbrains.kotlin.renderer.PropertyAccessorRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.LOWER_BOUND
|
||||
@@ -48,11 +44,8 @@ import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.Constrain
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.getValidityConstraintForConstituentType
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
@@ -97,9 +90,7 @@ object Renderers {
|
||||
|
||||
@JvmField
|
||||
val VISIBILITY = Renderer<Visibility> {
|
||||
if (it == Visibilities.INVISIBLE_FAKE)
|
||||
"invisible (private in a supertype)"
|
||||
else it.displayName
|
||||
it.externalDisplayName
|
||||
}
|
||||
|
||||
@JvmField
|
||||
|
||||
+2
-2
@@ -4,10 +4,10 @@ compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:7:9: error: cannot access
|
||||
compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:8:5: error: unresolved reference: C
|
||||
C().a()
|
||||
^
|
||||
compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:12:5: error: cannot access '<init>': it is public/*package*/ in 'PackageLocal1'
|
||||
compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:12:5: error: cannot access '<init>': it is package-private in 'PackageLocal1'
|
||||
PackageLocal1()
|
||||
^
|
||||
compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:13:5: error: cannot access '<init>': it is public/*package*/ in 'PackageLocal2'
|
||||
compiler/testData/cli/jvm/singleJavaFileRoots/test.kt:13:5: error: cannot access '<init>': it is package-private in 'PackageLocal2'
|
||||
PackageLocal2()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// FILE: j/JavaPackageLocal.java
|
||||
package j;
|
||||
|
||||
public class JavaPackageLocal {
|
||||
static void javaMPackage() {}
|
||||
static int javaPPackage = 4;
|
||||
}
|
||||
|
||||
// FILE: j/JavaProtected.java
|
||||
package j;
|
||||
|
||||
public class JavaProtected {
|
||||
protected static void javaMProtectedStatic() {}
|
||||
protected static int javaPProtectedStatic = 4;
|
||||
protected final int javaPProtectedPackage = 4;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
package k
|
||||
|
||||
import j.JavaProtected
|
||||
import j.JavaPackageLocal
|
||||
|
||||
class A {
|
||||
val p1 = JavaPackageLocal.<!INVISIBLE_MEMBER("javaPPackage", "package-private", "'JavaPackageLocal'")!>javaPPackage<!>
|
||||
val p2 = JavaProtected.<!INVISIBLE_MEMBER("javaPProtectedStatic", "protected", "'JavaProtected'")!>javaPProtectedStatic<!>
|
||||
val p3 = JavaProtected().<!INVISIBLE_MEMBER("javaPProtectedPackage", "protected", "'JavaProtected'")!>javaPProtectedPackage<!>
|
||||
|
||||
fun test() {
|
||||
JavaProtected.<!INVISIBLE_MEMBER("javaMProtectedStatic", "protected", "'JavaProtected'")!>javaMProtectedStatic<!>()
|
||||
JavaPackageLocal.<!INVISIBLE_MEMBER("javaMPackage", "package-private", "'JavaPackageLocal'")!>javaMPackage<!>()
|
||||
}
|
||||
}
|
||||
|
||||
class B : JavaProtected() {
|
||||
val p1 = JavaPackageLocal.<!INVISIBLE_MEMBER("javaPPackage", "package-private", "'JavaPackageLocal'")!>javaPPackage<!>
|
||||
val p2 = JavaProtected.javaPProtectedStatic
|
||||
val p3 = javaPProtectedPackage
|
||||
|
||||
fun test() {
|
||||
JavaProtected.javaMProtectedStatic()
|
||||
JavaPackageLocal.<!INVISIBLE_MEMBER("javaMPackage", "package-private", "'JavaPackageLocal'")!>javaMPackage<!>()
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: j.kt
|
||||
package j
|
||||
|
||||
import j.JavaProtected
|
||||
import j.JavaPackageLocal
|
||||
|
||||
class C {
|
||||
val p1 = JavaPackageLocal.javaPPackage
|
||||
val p2 = JavaProtected.javaPProtectedStatic
|
||||
val p3 = JavaProtected().javaPProtectedPackage
|
||||
|
||||
fun test() {
|
||||
JavaProtected.javaMProtectedStatic()
|
||||
JavaProtected.javaMProtectedStatic()
|
||||
JavaPackageLocal.javaMPackage()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package
|
||||
|
||||
package j {
|
||||
|
||||
public final class C {
|
||||
public constructor C()
|
||||
public final val p1: kotlin.Int
|
||||
public final val p2: kotlin.Int
|
||||
public final val p3: kotlin.Int = 4
|
||||
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 final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class JavaPackageLocal {
|
||||
public constructor JavaPackageLocal()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ final var javaPPackage: kotlin.Int
|
||||
public/*package*/ open fun javaMPackage(): kotlin.Unit
|
||||
}
|
||||
|
||||
public open class JavaProtected {
|
||||
public constructor JavaProtected()
|
||||
protected/*protected and package*/ final val javaPProtectedPackage: kotlin.Int = 4
|
||||
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
|
||||
|
||||
// Static members
|
||||
protected/*protected static*/ final var javaPProtectedStatic: kotlin.Int
|
||||
protected/*protected static*/ open fun javaMProtectedStatic(): kotlin.Unit
|
||||
}
|
||||
}
|
||||
|
||||
package k {
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final val p1: kotlin.Int
|
||||
public final val p2: kotlin.Int
|
||||
public final val p3: kotlin.Int = 4
|
||||
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 final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B : j.JavaProtected {
|
||||
public constructor B()
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ val javaPProtectedPackage: kotlin.Int
|
||||
public final val p1: kotlin.Int
|
||||
public final val p2: kotlin.Int
|
||||
public final val p3: kotlin.Int
|
||||
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 final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -9069,6 +9069,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckJavaVisibility2.kt")
|
||||
public void testCheckJavaVisibility2() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckVisibility.kt")
|
||||
public void testCheckVisibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckVisibility.kt");
|
||||
|
||||
Generated
+5
@@ -9064,6 +9064,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckJavaVisibility2.kt")
|
||||
public void testCheckJavaVisibility2() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CheckVisibility.kt")
|
||||
public void testCheckVisibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/CheckVisibility.kt");
|
||||
|
||||
@@ -47,10 +47,16 @@ public class JavaVisibilities {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
public String getInternalDisplayName() {
|
||||
return "public/*package*/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getExternalDisplayName() {
|
||||
return "package-private";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility normalize() {
|
||||
@@ -78,10 +84,16 @@ public class JavaVisibilities {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
public String getInternalDisplayName() {
|
||||
return "protected/*protected static*/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getExternalDisplayName() {
|
||||
return "protected";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility normalize() {
|
||||
@@ -111,10 +123,16 @@ public class JavaVisibilities {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
public String getInternalDisplayName() {
|
||||
return "protected/*protected and package*/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getExternalDisplayName() {
|
||||
return "protected";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility normalize() {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class Visibilities {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
public String getInternalDisplayName() {
|
||||
return "private/*private to this*/";
|
||||
}
|
||||
};
|
||||
@@ -270,6 +270,12 @@ public class Visibilities {
|
||||
public boolean isVisible(@Nullable ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getExternalDisplayName() {
|
||||
return "invisible (private in a supertype)";
|
||||
}
|
||||
};
|
||||
|
||||
// Currently used as default visibility of FunctionDescriptor
|
||||
|
||||
@@ -56,10 +56,23 @@ abstract class Visibility protected constructor(
|
||||
return Visibilities.compareLocal(this, visibility)
|
||||
}
|
||||
|
||||
open val displayName: String
|
||||
// internal representation for descriptors
|
||||
open val internalDisplayName: String
|
||||
get() = name
|
||||
|
||||
override final fun toString() = displayName
|
||||
// external representation for diagnostics
|
||||
open val externalDisplayName: String
|
||||
get() = internalDisplayName
|
||||
|
||||
@Deprecated(
|
||||
"Visibility.displayName is deprecated, use internalDisplayName instead",
|
||||
ReplaceWith("internalDisplayName"),
|
||||
level = DeprecationLevel.WARNING
|
||||
)
|
||||
open val displayName: String
|
||||
get() = internalDisplayName
|
||||
|
||||
override final fun toString() = internalDisplayName
|
||||
|
||||
open fun normalize(): Visibility = this
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ internal class DescriptorRendererImpl(
|
||||
visibility = visibility.normalize()
|
||||
}
|
||||
if (!renderDefaultVisibility && visibility == Visibilities.DEFAULT_VISIBILITY) return false
|
||||
builder.append(renderKeyword(visibility.displayName)).append(" ")
|
||||
builder.append(renderKeyword(visibility.internalDisplayName)).append(" ")
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -18,4 +18,4 @@ End of files
|
||||
Exit code: ABORT
|
||||
------------------------------------------
|
||||
COMPILATION FAILED
|
||||
Cannot access 'foo': it is public/*package*/ in 'JavaClass'
|
||||
Cannot access 'foo': it is package-private in 'JavaClass'
|
||||
Reference in New Issue
Block a user