Change DeserializedContainerSource.presentableFqName to String

To allow outputting something other than "Class 'XXX'" in the diagnostic
message for declarations deserialized from JS
This commit is contained in:
Alexander Udalov
2017-02-09 15:51:37 +03:00
parent f120865350
commit de8dd37e44
6 changed files with 14 additions and 16 deletions
@@ -99,8 +99,8 @@ public interface Errors {
DiagnosticFactory2<PsiElement, String, String> API_NOT_AVAILABLE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory1<PsiElement, FqName> MISSING_DEPENDENCY_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, FqName> PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, FqName, IncompatibleVersionErrorData<?>> INCOMPATIBLE_CLASS = DiagnosticFactory2.create(ERROR);
DiagnosticFactory1<PsiElement, String> PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, String, IncompatibleVersionErrorData<?>> INCOMPATIBLE_CLASS = DiagnosticFactory2.create(ERROR);
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
//"INVISIBLE_REFERENCE" is used for invisible classes references and references in import
@@ -358,9 +358,9 @@ public class DefaultErrorMessages {
MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING);
MAP.put(MISSING_DEPENDENCY_CLASS, "Cannot access class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(PRE_RELEASE_CLASS, "Class ''{0}'' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
MAP.put(INCOMPATIBLE_CLASS,
"Class ''{0}'' was compiled with an incompatible version of Kotlin. {1}",
"{0} was compiled with an incompatible version of Kotlin. {1}",
TO_STRING, new DiagnosticParameterRenderer<IncompatibleVersionErrorData<?>>() {
@NotNull
@Override
@@ -59,10 +59,10 @@ object MissingDependencyClassChecker : CallChecker {
if (source is DeserializedContainerSource) {
val incompatibility = source.incompatibility
if (incompatibility != null) {
return INCOMPATIBLE_CLASS.on(reportOn, source.presentableFqName, incompatibility)
return INCOMPATIBLE_CLASS.on(reportOn, source.presentableString, incompatibility)
}
if (source.isPreReleaseInvisible) {
return PRE_RELEASE_CLASS.on(reportOn, source.presentableFqName)
return PRE_RELEASE_CLASS.on(reportOn, source.presentableString)
}
}
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.descriptors.SourceFile
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
@@ -43,14 +42,14 @@ class JvmPackagePartSource(
isPreReleaseInvisible
)
override val presentableFqName: FqName
get() = classId.asSingleFqName()
override val presentableString: String
get() = "Class '${classId.asSingleFqName().asString()}'"
val simpleName: Name get() = Name.identifier(className.internalName.substringAfterLast('/'))
val classId: ClassId get() = ClassId(className.packageFqName, simpleName)
override fun toString() = "${javaClass.simpleName}: $className"
override fun toString() = "${this::class.java.simpleName}: $className"
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
}
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.descriptors.SourceFile
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
@@ -26,10 +25,10 @@ class KotlinJvmBinarySourceElement(
override val incompatibility: IncompatibleVersionErrorData<JvmMetadataVersion>? = null,
override val isPreReleaseInvisible: Boolean = false
) : DeserializedContainerSource {
override val presentableFqName: FqName
get() = binaryClass.classId.asSingleFqName()
override val presentableString: String
get() = "Class '${binaryClass.classId.asSingleFqName().asString()}'"
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
override fun toString() = "${javaClass.simpleName}: $binaryClass"
override fun toString() = "${this::class.java.simpleName}: $binaryClass"
}
@@ -55,8 +55,8 @@ interface DeserializedContainerSource : SourceElement {
// True iff this is container is "invisible" because it's loaded from a pre-release class and this compiler is a release
val isPreReleaseInvisible: Boolean
// This FQ name should only be used for error messages
val presentableFqName: FqName
// This string should only be used in error messages
val presentableString: String
}
interface DeserializedCallableMemberDescriptor : DeserializedMemberDescriptor, CallableMemberDescriptor