Report full package FQ name in compilation errors related to visibility

#KT-18966 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-07-14 20:37:20 +03:00
parent 216ab1c6d1
commit 4d4c39939f
6 changed files with 35 additions and 12 deletions
@@ -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>> {