Report full package FQ name in compilation errors related to visibility
#KT-18966 Fixed
This commit is contained in:
+4
-3
@@ -90,8 +90,8 @@ public class DefaultErrorMessages {
|
||||
static {
|
||||
MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", ELEMENT_TEXT);
|
||||
|
||||
MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is {1} in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE);
|
||||
MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is {1} in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE);
|
||||
MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is {1} in {2}", NAME, VISIBILITY, NAME_OF_CONTAINING_DECLARATION_OR_FILE);
|
||||
MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is {1} in {2}", NAME, VISIBILITY, NAME_OF_CONTAINING_DECLARATION_OR_FILE);
|
||||
|
||||
MAP.put(PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL, "Protected constructor ''{0}'' from other classes can only be used in super-call", Renderers.SHORT_NAMES_IN_TYPES);
|
||||
|
||||
@@ -306,7 +306,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(CAPTURED_VAL_INITIALIZATION, "Captured values initialization is forbidden due to possible reassignment", NAME);
|
||||
MAP.put(CAPTURED_MEMBER_VAL_INITIALIZATION, "Captured member values initialization is forbidden due to possible reassignment", NAME);
|
||||
MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME);
|
||||
MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is {1} in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE);
|
||||
MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is {1} in {2}", NAME, VISIBILITY,
|
||||
NAME_OF_CONTAINING_DECLARATION_OR_FILE);
|
||||
MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME);
|
||||
MAP.put(VARIABLE_EXPECTED, "Variable expected");
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
@@ -107,12 +108,18 @@ object Renderers {
|
||||
"$declarationKindWithSpace'${it.name.asString()}'"
|
||||
}
|
||||
|
||||
@JvmField val NAME_OF_PARENT_OR_FILE = Renderer<DeclarationDescriptor> {
|
||||
@JvmField val NAME_OF_CONTAINING_DECLARATION_OR_FILE = Renderer<DeclarationDescriptor> {
|
||||
if (DescriptorUtils.isTopLevelDeclaration(it) && it is DeclarationDescriptorWithVisibility && it.visibility == Visibilities.PRIVATE) {
|
||||
"file"
|
||||
}
|
||||
else {
|
||||
"'" + it.containingDeclaration!!.name + "'"
|
||||
val containingDeclaration = it.containingDeclaration
|
||||
if (containingDeclaration is PackageFragmentDescriptor) {
|
||||
containingDeclaration.fqName.asString().wrapIntoQuotes()
|
||||
}
|
||||
else {
|
||||
containingDeclaration!!.name.asString().wrapIntoQuotes()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +129,7 @@ object Renderers {
|
||||
|
||||
@JvmField val RENDER_CLASS_OR_OBJECT = Renderer {
|
||||
classOrObject: KtClassOrObject ->
|
||||
val name = if (classOrObject.name != null) " '" + classOrObject.name + "'" else ""
|
||||
val name = classOrObject.name?.let { " ${it.wrapIntoQuotes()}" } ?: ""
|
||||
if (classOrObject is KtClass) "Class" + name else "Object" + name
|
||||
}
|
||||
|
||||
@@ -413,13 +420,13 @@ object Renderers {
|
||||
}
|
||||
|
||||
val explanation =
|
||||
"Type parameter has an upper bound '" + result.typeRenderer.render(upperBound, RenderingContext.of(upperBound)) + "'" +
|
||||
"Type parameter has an upper bound ${result.typeRenderer.render(upperBound, RenderingContext.of(upperBound)).wrapIntoQuotes()}" +
|
||||
" that cannot be satisfied capturing 'in' projection"
|
||||
|
||||
result.text(newText().normal(
|
||||
"'" + typeParameter.name + "'" +
|
||||
typeParameter.name.wrapIntoQuotes() +
|
||||
" cannot capture " +
|
||||
"'" + capturedTypeConstructor.typeProjection + "'. " +
|
||||
"${capturedTypeConstructor.typeProjection.toString().wrapIntoQuotes()}. " +
|
||||
explanation
|
||||
))
|
||||
return result
|
||||
@@ -496,6 +503,9 @@ object Renderers {
|
||||
append("(").append(renderTypes(inferenceErrorData.valueArgumentsTypes, context)).append(")")
|
||||
}
|
||||
|
||||
private fun String.wrapIntoQuotes(): String = "'$this'"
|
||||
private fun Name.wrapIntoQuotes(): String = "'${this.asString()}'"
|
||||
|
||||
private val WHEN_MISSING_LIMIT = 7
|
||||
|
||||
@JvmField val RENDER_WHEN_MISSING_CASES = Renderer<List<WhenMissingCase>> {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
package a.b
|
||||
|
||||
@<error descr="[INVISIBLE_MEMBER] Cannot access 'InlineOnly': it is internal in 'kotlin.internal'">kotlin.internal.<error descr="[INVISIBLE_REFERENCE] Cannot access 'InlineOnly': it is internal in 'kotlin.internal'">InlineOnly</error></error>
|
||||
inline fun foo() {}
|
||||
@@ -15,7 +15,7 @@ fun access() {
|
||||
publicInM1()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM1Test': it is private in file">privateInM1Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM1Test': it is internal in 'test'">internalInM1Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM1Test': it is internal in 'shared.test'">internalInM1Test</error>()
|
||||
publicInM1Test()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM2': it is private in file">privateInM2</error>()
|
||||
|
||||
@@ -15,7 +15,7 @@ fun access() {
|
||||
publicInM1()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM1Test': it is private in file">privateInM1Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM1Test': it is internal in 'test'">internalInM1Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM1Test': it is internal in 'shared.test'">internalInM1Test</error>()
|
||||
publicInM1Test()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM2': it is private in file">privateInM2</error>()
|
||||
@@ -23,7 +23,7 @@ fun access() {
|
||||
publicInM2()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM2Test': it is private in file">privateInM2Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM2Test': it is internal in 'test'">internalInM2Test</error>()
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'internalInM2Test': it is internal in 'shared.test'">internalInM2Test</error>()
|
||||
publicInM2Test()
|
||||
|
||||
<error descr="[INVISIBLE_MEMBER] Cannot access 'privateInM3': it is private in file">privateInM3</error>()
|
||||
|
||||
@@ -986,6 +986,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/checker/diagnosticsMessage"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("fullPackageFQNameOnVisiblityError.kt")
|
||||
public void testFullPackageFQNameOnVisiblityError() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/fullPackageFQNameOnVisiblityError.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("incompleteTypeArgumentList.kt")
|
||||
public void testIncompleteTypeArgumentList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/incompleteTypeArgumentList.kt");
|
||||
|
||||
Reference in New Issue
Block a user