Improve diagnostic message for UNSUPPORTED_FEATURE
Render lowercase words separated by spaces instead of CamelCase in the diagnostic message
This commit is contained in:
@@ -31,6 +31,10 @@ enum class LanguageFeature(val sinceVersion: LanguageVersion) {
|
||||
DestructuringLambdaParameters(KOTLIN_1_1),
|
||||
;
|
||||
|
||||
val presentableText: String
|
||||
// E.g. "DestructuringLambdaParameters" -> ["Destructuring", "Lambda", "Parameters"] -> "destructuring lambda parameters"
|
||||
get() = name.split("(?<!^)(?=[A-Z])".toRegex()).joinToString(separator = " ", transform = String::toLowerCase)
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(str: String) = values().find { it.name == str }
|
||||
|
||||
+8
-1
@@ -21,6 +21,7 @@ import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
@@ -505,7 +506,13 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNSAFE_IMPLICIT_INVOKE_CALL, "Reference has a nullable type ''{0}'', use explicit ''?.invoke()'' to make a function-like call instead", RENDER_TYPE);
|
||||
MAP.put(AMBIGUOUS_LABEL, "Ambiguous label");
|
||||
MAP.put(UNSUPPORTED, "Unsupported [{0}]", STRING);
|
||||
MAP.put(UNSUPPORTED_FEATURE, "{0} are unsupported at this language level", TO_STRING);
|
||||
MAP.put(UNSUPPORTED_FEATURE, "The feature is only available since Kotlin {0}", new DiagnosticParameterRenderer<LanguageFeature>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(LanguageFeature feature, @NotNull RenderingContext renderingContext) {
|
||||
return feature.getSinceVersion().getVersionString() + ": " + feature.getPresentableText();
|
||||
}
|
||||
});
|
||||
MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE);
|
||||
MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE);
|
||||
MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here");
|
||||
|
||||
Reference in New Issue
Block a user