Deprecated reportFromPlugin way to report diagnostics from plugin

Originally reportFromPlugin method was introduced to address the problem
with loading of DefaultErrorMessages.Extension vis ServiceLoader.
For some cases this extension was not loaded by ServiceLoader because
classes was loaded via different class loader, common scenario here is
compiler plugins. Ideally we should load such extension point via
getService approach, but unfortunately to do that we need project and
DefaultErrorMessages.render is static method for now.
Also with reportFromPlugin approach is a problem -- all diagnostics
reported via this method has the same id: PLUGIN_[WARNING|ERROR|INFO]
and it isn't possible to suppress only one particular diagnostic.
To bypass this problem the new method
initializeFactoryNamesAndDefaultErrorMessages was introduced.
It basically store DiagnosticRenderer inside DiagnosticFactory.
It is not ideal, because one DiagnosticFactory could have different
renderers for different scenarios -- for compiler and for IDE, but
I think that it is better than reportByPlugin approach.
This commit is contained in:
Stanislav Erokhin
2020-02-07 22:18:25 +03:00
parent 84baa0b4c2
commit 453008e488
20 changed files with 104 additions and 106 deletions
@@ -6,5 +6,5 @@ import kotlinx.serialization.*
@Serializable
open class Parent(open val arg: Int)
<!PLUGIN_ERROR("Serializable class has duplicate serial name of property 'arg', either in the class itself or its supertypes")!>@Serializable<!>
<!DUPLICATE_SERIAL_NAME("arg")!>@Serializable<!>
class Derived(override val arg: Int): Parent(arg)
@@ -5,5 +5,5 @@ import kotlinx.serialization.*
open class NonSerializableParent(val arg: Int)
<!PLUGIN_ERROR("Impossible to make this class serializable because its parent is not serializable and does not have exactly one constructor without parameters")!>@Serializable<!>
<!NON_SERIALIZABLE_PARENT_MUST_HAVE_NOARG_CTOR!>@Serializable<!>
class Derived(val someData: String): NonSerializableParent(42)
@@ -6,12 +6,12 @@ import kotlinx.serialization.*
class NonSerializable
@Serializable
class Basic(val foo: <!PLUGIN_ERROR("Serializer has not been found for type 'NonSerializable'. To use context serializer as fallback, explicitly annotate type or property with @ContextualSerialization")!>NonSerializable<!>)
class Basic(val foo: <!SERIALIZER_NOT_FOUND("NonSerializable")!>NonSerializable<!>)
@Serializable
class Inside(val foo: List<<!PLUGIN_ERROR("Serializer has not been found for type 'NonSerializable'. To use context serializer as fallback, explicitly annotate type or property with @ContextualSerialization")!>NonSerializable<!>>)
class Inside(val foo: List<<!SERIALIZER_NOT_FOUND("NonSerializable")!>NonSerializable<!>>)
@Serializable
class WithImplicitType {
<!PLUGIN_ERROR("Serializer has not been found for type 'NonSerializable'. To use context serializer as fallback, explicitly annotate type or property with @ContextualSerialization")!>val foo = NonSerializable()<!>
<!SERIALIZER_NOT_FOUND("NonSerializable")!>val foo = NonSerializable()<!>
}
@@ -13,4 +13,4 @@ class NopeNullableSerializer: KSerializer<Nope?> {
}
@Serializable
class Foo(val foo: <!PLUGIN_ERROR("Type 'Nope' is non-nullable and therefore can not be serialized with serializer for nullable type 'NopeNullableSerializer'")!>Nope<!>)
class Foo(val foo: <!SERIALIZER_NULLABILITY_INCOMPATIBLE("NopeNullableSerializer", "Nope")!>Nope<!>)
@@ -3,5 +3,5 @@
// FILE: test.kt
import kotlinx.serialization.*
<!PLUGIN_ERROR("This class is not serializable automatically because it has primary constructor parameters of which are not properties")!>@Serializable<!>
<!PRIMARY_CONSTRUCTOR_PARAMETER_IS_NOT_A_PROPERTY!>@Serializable<!>
class Test(val someData: String, cantBeDeserialized: Int)
@@ -5,9 +5,9 @@ import kotlinx.serialization.*
enum class SimpleEnum { A, B }
<!PLUGIN_WARNING("Explicit @Serializable annotation on enum class is required when @SerialName or @SerialInfo annotations are used on its members.")!>enum<!> class MarkedNameEnum { @SerialName("a") A, B}
<!EXPLICIT_SERIALIZABLE_IS_REQUIRED!>enum<!> class MarkedNameEnum { @SerialName("a") A, B}
<!PLUGIN_WARNING("Explicit @Serializable annotation on enum class is required when @SerialName or @SerialInfo annotations are used on its members.")!>enum<!> class MarkedInfoEnum { @SerialId(10) A, B}
<!EXPLICIT_SERIALIZABLE_IS_REQUIRED!>enum<!> class MarkedInfoEnum { @SerialId(10) A, B}
@Serializable
enum class ExplicitlyMarkedEnum { @SerialId(10) A, B}
@@ -3,5 +3,5 @@
// FILE: test.kt
import kotlinx.serialization.*
<!PLUGIN_ERROR("@Serializable annotation is ignored because it is impossible to serialize automatically interfaces or enums. Provide serializer manually via e.g. companion object")!>@Serializable<!>
<!SERIALIZABLE_ANNOTATION_IGNORED!>@Serializable<!>
interface INonSerializable
@@ -4,8 +4,8 @@
import kotlinx.serialization.*
@Serializable
data class WithTransients(<!PLUGIN_ERROR("This property is marked as @Transient and therefore must have an initializing expression")!>@Transient val missing: Int<!>) {
<!PLUGIN_WARNING("Property does not have backing field which makes it non-serializable and therefore @Transient is redundant")!>@Transient<!> val redundant: Int get() = 42
data class WithTransients(<!TRANSIENT_MISSING_INITIALIZER!>@Transient val missing: Int<!>) {
<!TRANSIENT_IS_REDUNDANT!>@Transient<!> val redundant: Int get() = 42
@Transient
lateinit var allowTransientLateinitWithoutInitializer: String