[FE] Move diagnostic parameter renderers to common module
This commit is contained in:
committed by
TeamCityServer
parent
c32aecb7ae
commit
0260bf8767
+3
-5
@@ -5,12 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.LanguageFeatureMessageRenderer
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers.RENDER_POSITION_VARIANCE
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers.STRING
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers.commaSeparated
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.RENDER_POSITION_VARIANCE
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.commaSeparated
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.AMBIGUOUS_CALLS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.COLLECTION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.DECLARATION_NAME
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics.rendering
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
object CommonRenderers {
|
||||
@JvmField
|
||||
val EMPTY = Renderer<Any> { "" }
|
||||
|
||||
@JvmField
|
||||
val STRING = Renderer<String> { it }
|
||||
|
||||
@JvmField
|
||||
val THROWABLE = Renderer<Throwable> {
|
||||
val writer = StringWriter()
|
||||
it.printStackTrace(PrintWriter(writer))
|
||||
StringUtil.first(writer.toString(), 2048, true)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val RENDER_POSITION_VARIANCE = Renderer { variance: Variance ->
|
||||
when (variance) {
|
||||
Variance.INVARIANT -> "invariant"
|
||||
Variance.IN_VARIANCE -> "in"
|
||||
Variance.OUT_VARIANCE -> "out"
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun <T> commaSeparated(itemRenderer: DiagnosticParameterRenderer<T>) = ContextDependentRenderer<Collection<T>> { collection, context ->
|
||||
buildString {
|
||||
val iterator = collection.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
append(itemRenderer.render(next, context))
|
||||
if (iterator.hasNext()) {
|
||||
append(", ")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-14
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics.rendering
|
||||
@@ -65,4 +54,4 @@ class LanguageFeatureMessageRenderer @JvmOverloads constructor(
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -32,4 +32,7 @@ fun <O> Renderer(block: (O) -> String) = object : ContextIndependentParameterRen
|
||||
|
||||
fun <O> ContextDependentRenderer(block: (O, RenderingContext) -> String) = object : DiagnosticParameterRenderer<O> {
|
||||
override fun render(obj: O, renderingContext: RenderingContext): String = block(obj, renderingContext)
|
||||
}
|
||||
}
|
||||
|
||||
fun <P> renderParameter(parameter: P, renderer: DiagnosticParameterRenderer<P>?, context: RenderingContext): Any? =
|
||||
renderer?.render(parameter, context) ?: parameter
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
|
||||
import static kotlin.collections.CollectionsKt.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*;
|
||||
|
||||
public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.RenderingContext.of;
|
||||
|
||||
|
||||
-3
@@ -20,9 +20,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
|
||||
fun <P> renderParameter(parameter: P, renderer: DiagnosticParameterRenderer<P>?, context: RenderingContext): Any? =
|
||||
renderer?.render(parameter, context) ?: parameter
|
||||
|
||||
fun ClassifierDescriptorWithTypeParameters.renderKindWithName(): String =
|
||||
DescriptorRenderer.getClassifierKindPrefix(this) + " '" + name + "'"
|
||||
|
||||
|
||||
@@ -66,19 +66,6 @@ object Renderers {
|
||||
element.toString()
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val EMPTY = Renderer<Any> { "" }
|
||||
|
||||
@JvmField
|
||||
val STRING = Renderer<String> { it }
|
||||
|
||||
@JvmField
|
||||
val THROWABLE = Renderer<Throwable> {
|
||||
val writer = StringWriter()
|
||||
it.printStackTrace(PrintWriter(writer))
|
||||
StringUtil.first(writer.toString(), 2048, true)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val NAME = Renderer<Named> { it.name.asString() }
|
||||
|
||||
@@ -180,15 +167,6 @@ object Renderers {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val RENDER_POSITION_VARIANCE = Renderer { variance: Variance ->
|
||||
when (variance) {
|
||||
Variance.INVARIANT -> "invariant"
|
||||
Variance.IN_VARIANCE -> "in"
|
||||
Variance.OUT_VARIANCE -> "out"
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val AMBIGUOUS_CALLS = Renderer { calls: Collection<ResolvedCall<*>> ->
|
||||
val descriptors = calls.map { it.resultingDescriptor }
|
||||
@@ -214,20 +192,6 @@ object Renderers {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun <T> commaSeparated(itemRenderer: DiagnosticParameterRenderer<T>) = ContextDependentRenderer<Collection<T>> { collection, context ->
|
||||
buildString {
|
||||
val iterator = collection.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
append(itemRenderer.render(next, context))
|
||||
if (iterator.hasNext()) {
|
||||
append(", ")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER = Renderer<InferenceErrorData> {
|
||||
renderConflictingSubstitutionsInferenceError(it, TabledDescriptorRenderer.create()).toString()
|
||||
|
||||
+11
-10
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||
@@ -15,27 +16,27 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
|
||||
put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN,
|
||||
"Annotation ''{0}'' is allowed only on member functions of declaration annotated as ''kotlin.js.native'' or on toplevel extension functions", RENDER_TYPE)
|
||||
put(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER, "Native {0}''s first parameter type should be ''kotlin.String'' or subtype of ''kotlin.Number''", Renderers.STRING)
|
||||
put(ErrorsJs.NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS, "Native {0}''s parameter can not have default value", Renderers.STRING)
|
||||
put(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER, "Native {0}''s first parameter type should be ''kotlin.String'' or subtype of ''kotlin.Number''", STRING)
|
||||
put(ErrorsJs.NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS, "Native {0}''s parameter can not have default value", STRING)
|
||||
put(ErrorsJs.NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE, "Native getter's return type should be nullable")
|
||||
put(ErrorsJs.NATIVE_SETTER_WRONG_RETURN_TYPE, "Native setter's return type should be 'Unit' or a supertype of the second parameter's type")
|
||||
put(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT, "Expected {0} parameters for native {1}", Renderers.TO_STRING, Renderers.STRING)
|
||||
put(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT, "Expected {0} parameters for native {1}", Renderers.TO_STRING, STRING)
|
||||
put(ErrorsJs.JSCODE_ERROR, "JavaScript: {0}", JsCallDataTextRenderer)
|
||||
put(ErrorsJs.JSCODE_WARNING, "JavaScript: {0}", JsCallDataTextRenderer)
|
||||
put(ErrorsJs.JSCODE_ARGUMENT_SHOULD_BE_CONSTANT, "Argument must be string constant")
|
||||
put(ErrorsJs.NOT_SUPPORTED, "Cannot translate (not supported yet): ''{0}''", RenderFirstLineOfElementText)
|
||||
put(ErrorsJs.JSCODE_NO_JAVASCRIPT_PRODUCED, "Argument must be non-empty JavaScript code")
|
||||
put(ErrorsJs.NESTED_EXTERNAL_DECLARATION, "Non top-level `external` declaration")
|
||||
put(ErrorsJs.WRONG_EXTERNAL_DECLARATION, "Declaration of such kind ({0}) can''t be external", Renderers.STRING)
|
||||
put(ErrorsJs.WRONG_EXTERNAL_DECLARATION, "Declaration of such kind ({0}) can''t be external", STRING)
|
||||
put(ErrorsJs.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, "Function types with receiver are prohibited in external declarations")
|
||||
put(ErrorsJs.INLINE_CLASS_IN_EXTERNAL_DECLARATION, "Using inline classes as parameter type or return type of external declarations is not supported")
|
||||
|
||||
put(ErrorsJs.JS_NAME_CLASH, "JavaScript name ({0}) generated for this declaration clashes with another declaration: {1}",
|
||||
Renderers.STRING, Renderers.COMPACT)
|
||||
STRING, Renderers.COMPACT)
|
||||
put(ErrorsJs.JS_FAKE_NAME_CLASH, "JavaScript name {0} is generated for different inherited members: {1} and {2}",
|
||||
Renderers.STRING, Renderers.COMPACT, Renderers.COMPACT)
|
||||
STRING, Renderers.COMPACT, Renderers.COMPACT)
|
||||
put(ErrorsJs.JS_BUILTIN_NAME_CLASH, "JavaScript name generated for this declaration clashes with built-in declaration {1}",
|
||||
Renderers.STRING)
|
||||
STRING)
|
||||
put(ErrorsJs.JS_NAME_ON_PRIMARY_CONSTRUCTOR_PROHIBITED, "@JsName annotation is prohibited for primary constructors")
|
||||
put(ErrorsJs.JS_NAME_ON_ACCESSOR_AND_PROPERTY, "@JsName can be either on a property or its accessors, not both of them")
|
||||
put(ErrorsJs.JS_NAME_IS_NOT_ON_ALL_ACCESSORS, "@JsName should be on all of the property accessors")
|
||||
@@ -67,7 +68,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.EXTERNAL_INTERFACE_AS_CLASS_LITERAL, "Can't refer to external interface from class literal")
|
||||
put(ErrorsJs.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE, "External type extends non-external type")
|
||||
|
||||
put(ErrorsJs.WRONG_OPERATION_WITH_DYNAMIC, "Wrong operation with dynamic value: {0}", Renderers.STRING)
|
||||
put(ErrorsJs.WRONG_OPERATION_WITH_DYNAMIC, "Wrong operation with dynamic value: {0}", STRING)
|
||||
put(ErrorsJs.SPREAD_OPERATOR_IN_DYNAMIC_CALL, "Can't apply spread operator in dynamic call")
|
||||
put(ErrorsJs.DELEGATION_BY_DYNAMIC, "Can't delegate to dynamic value")
|
||||
put(ErrorsJs.PROPERTY_DELEGATION_BY_DYNAMIC, "Can't apply property delegation by dynamic handler")
|
||||
@@ -101,8 +102,8 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
Renderers.DECLARATION_NAME_WITH_KIND)
|
||||
|
||||
put(ErrorsJs.NESTED_JS_EXPORT, "@JsExport is only allowed on files and top-level declarations")
|
||||
put(ErrorsJs.WRONG_EXPORTED_DECLARATION, "Declaration of such kind ({0}) can''t be exported to JS", Renderers.STRING)
|
||||
put(ErrorsJs.NON_EXPORTABLE_TYPE, "Exported declaration uses non-exportable {0} type: {1}", Renderers.STRING, RENDER_TYPE)
|
||||
put(ErrorsJs.WRONG_EXPORTED_DECLARATION, "Declaration of such kind ({0}) can''t be exported to JS", STRING)
|
||||
put(ErrorsJs.NON_EXPORTABLE_TYPE, "Exported declaration uses non-exportable {0} type: {1}", STRING, RENDER_TYPE)
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
+3
-6
@@ -5,10 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.konan.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.*
|
||||
|
||||
private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
DiagnosticFactoryToRendererMap("Native").apply {
|
||||
@@ -19,7 +16,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
)
|
||||
put(
|
||||
ErrorsNative.INCOMPATIBLE_THROWS_INHERITED, "Member inherits different @Throws filters from {0}",
|
||||
Renderers.commaSeparated(Renderers.NAME)
|
||||
CommonRenderers.commaSeparated(Renderers.NAME)
|
||||
)
|
||||
put(
|
||||
ErrorsNative.MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND,
|
||||
@@ -41,7 +38,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
"@ThreadLocal is applicable only to property with backing field, to property with delegation or to objects"
|
||||
)
|
||||
put(ErrorsNative.INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL, "@ThreadLocal is applicable only to top level declarations")
|
||||
put(ErrorsNative.INVALID_CHARACTERS_NATIVE, "Name {0}", Renderers.STRING);
|
||||
put(ErrorsNative.INVALID_CHARACTERS_NATIVE, "Name {0}", CommonRenderers.STRING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlinx.serialization.compiler.diagnostic
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||
@@ -17,8 +18,8 @@ object SerializationPluginErrorsRendering : DefaultErrorMessages.Extension {
|
||||
MAP.put(
|
||||
SerializationErrors.INLINE_CLASSES_NOT_SUPPORTED,
|
||||
"Inline classes require runtime serialization library version at least {0}, while your classpath has {1}.",
|
||||
Renderers.STRING,
|
||||
Renderers.STRING,
|
||||
CommonRenderers.STRING,
|
||||
CommonRenderers.STRING,
|
||||
)
|
||||
MAP.put(
|
||||
SerializationErrors.PLUGIN_IS_NOT_ENABLED,
|
||||
@@ -53,7 +54,7 @@ object SerializationPluginErrorsRendering : DefaultErrorMessages.Extension {
|
||||
MAP.put(
|
||||
SerializationErrors.DUPLICATE_SERIAL_NAME,
|
||||
"Serializable class has duplicate serial name of property ''{0}'', either in the class itself or its supertypes",
|
||||
Renderers.STRING
|
||||
CommonRenderers.STRING
|
||||
)
|
||||
MAP.put(
|
||||
SerializationErrors.SERIALIZER_NOT_FOUND,
|
||||
@@ -103,18 +104,18 @@ object SerializationPluginErrorsRendering : DefaultErrorMessages.Extension {
|
||||
SerializationErrors.REQUIRED_KOTLIN_TOO_HIGH,
|
||||
"Your current Kotlin version is {0}, while kotlinx.serialization core runtime {1} requires at least Kotlin {2}. " +
|
||||
"Please update your Kotlin compiler and IDE plugin.",
|
||||
Renderers.STRING,
|
||||
Renderers.STRING,
|
||||
Renderers.STRING
|
||||
CommonRenderers.STRING,
|
||||
CommonRenderers.STRING,
|
||||
CommonRenderers.STRING
|
||||
)
|
||||
|
||||
MAP.put(
|
||||
SerializationErrors.PROVIDED_RUNTIME_TOO_LOW,
|
||||
"Your current kotlinx.serialization core version is {0}, while current Kotlin compiler plugin {1} requires at least {2}. " +
|
||||
"Please update your kotlinx.serialization runtime dependency.",
|
||||
Renderers.STRING,
|
||||
Renderers.STRING,
|
||||
Renderers.STRING
|
||||
CommonRenderers.STRING,
|
||||
CommonRenderers.STRING,
|
||||
CommonRenderers.STRING
|
||||
)
|
||||
|
||||
MAP.put(
|
||||
|
||||
Reference in New Issue
Block a user