Add compiler diagnostic tests for parcelize checkers

This commit is contained in:
Dmitriy Novozhilov
2021-10-26 11:17:59 +03:00
committed by teamcityserver
parent b84ee64994
commit 40d8451698
16 changed files with 220 additions and 48 deletions
@@ -11,7 +11,7 @@ class A : Parcelable
class B(val firstName: String, val secondName: String) : Parcelable
@Parcelize
class C(val firstName: String, <error descr="[PARCELABLE_CONSTRUCTOR_PARAMETER_SHOULD_BE_VAL_OR_VAR] 'Parcelable' constructor parameter should be 'val' or 'var'">secondName</error>: String) : Parcelable
class C(val firstName: String, <!PARCELABLE_CONSTRUCTOR_PARAMETER_SHOULD_BE_VAL_OR_VAR!>secondName<!>: String) : Parcelable
@Parcelize
class D(val firstName: String, vararg val secondName: String) : Parcelable
@@ -22,7 +22,7 @@ class E(val firstName: String, val secondName: String) : Parcelable {
}
@Parcelize
class <error descr="[PARCELABLE_SHOULD_HAVE_PRIMARY_CONSTRUCTOR] 'Parcelable' should have a primary constructor">F</error> : Parcelable {
class <!PARCELABLE_SHOULD_HAVE_PRIMARY_CONSTRUCTOR!>F<!> : Parcelable {
constructor(a: String) {
println(a)
}
@@ -9,7 +9,7 @@ import android.os.Parcel
class A(val a: String) : Parcelable {
companion object {
@JvmField
val <error descr="[CREATOR_DEFINITION_IS_NOT_ALLOWED] 'CREATOR' definition is not allowed. Use 'Parceler' companion object instead">CREATOR</error> = object : Parcelable.Creator<A> {
val <!CREATOR_DEFINITION_IS_NOT_ALLOWED!>CREATOR<!> = object : Parcelable.Creator<A> {
override fun createFromParcel(source: Parcel): A = A("")
override fun newArray(size: Int) = arrayOfNulls<A>(size)
}
@@ -18,7 +18,7 @@ class A(val a: String) : Parcelable {
@Parcelize
class B(val b: String) : Parcelable {
companion object <error descr="[CREATOR_DEFINITION_IS_NOT_ALLOWED] 'CREATOR' definition is not allowed. Use 'Parceler' companion object instead">CREATOR</error> : Parcelable.Creator<B> {
companion object <!CREATOR_DEFINITION_IS_NOT_ALLOWED!>CREATOR<!> : Parcelable.Creator<B> {
override fun createFromParcel(source: Parcel): B = B("")
override fun newArray(size: Int) = arrayOfNulls<B>(size)
}
@@ -19,27 +19,27 @@ class StringClassParceler : Parceler<String> {
override fun String.write(parcel: Parcel, flags: Int) = TODO()
}
@<error descr="[CLASS_SHOULD_BE_PARCELIZE] Class 'MissingParcelizeAnnotation' should be annotated with '@Parcelize'">TypeParceler</error><String, StringParceler>
class MissingParcelizeAnnotation(val a: @WriteWith<StringParceler> String)
@<!CLASS_SHOULD_BE_PARCELIZE!>TypeParceler<!><String, StringParceler>
class MissingParcelizeAnnotation(val a: @<!CLASS_SHOULD_BE_PARCELIZE!>WriteWith<!><StringParceler> String)
@Parcelize
@TypeParceler<String, StringClassParceler>
class ShouldBeClass(val a: @WriteWith<StringClassParceler> String) : Parcelable
class ShouldBeClass(val a: @WriteWith<<!PARCELER_SHOULD_BE_OBJECT!>StringClassParceler<!>> String) : Parcelable
@Parcelize
class Test(
val a: @WriteWith<StringParceler> Int,
val a: @WriteWith<<!PARCELER_TYPE_INCOMPATIBLE!>StringParceler<!>> Int,
val b: @WriteWith<StringParceler> String,
val c: @WriteWith<<error descr="[PARCELER_TYPE_INCOMPATIBLE] Parceler type String is incompatible with CharSequence">StringParceler</error>> CharSequence,
val c: @WriteWith<<!PARCELER_TYPE_INCOMPATIBLE!>StringParceler<!>> CharSequence,
val d: @WriteWith<CharSequenceParceler> String,
val e: @WriteWith<CharSequenceParceler> CharSequence
) : Parcelable
@Parcelize
@TypeParceler<String, StringParceler>
class Test2(@<warning descr="[REDUNDANT_TYPE_PARCELER] This 'TypeParceler' is already provided for Class 'Test2'">TypeParceler</warning><String, StringParceler> val a: String) : Parcelable
class Test2(@<!REDUNDANT_TYPE_PARCELER!>TypeParceler<!><String, StringParceler> val a: String) : Parcelable
@Parcelize
@TypeParceler<<error descr="[DUPLICATING_TYPE_PARCELERS] Duplicating ''TypeParceler'' annotations">String</error>, StringParceler>
@TypeParceler<<error descr="[DUPLICATING_TYPE_PARCELERS] Duplicating ''TypeParceler'' annotations">String</error>, CharSequenceParceler>
@TypeParceler<<!DUPLICATING_TYPE_PARCELERS!>String<!>, StringParceler>
@TypeParceler<<!DUPLICATING_TYPE_PARCELERS!>String<!>, CharSequenceParceler>
class Test3(val a: String) : Parcelable
@@ -6,16 +6,16 @@ import android.os.Parcel
@Parcelize
class A(val a: String) : Parcelable {
<error descr="[OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED] Overriding 'writeToParcel' is not allowed. Use 'Parceler' companion object instead">override</error> fun writeToParcel(p: Parcel?, flags: Int) {}
<!OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED!>override<!> fun writeToParcel(p: Parcel?, flags: Int) {}
override fun describeContents() = 0
}
@Parcelize
class B(val a: String) : Parcelable {
<error descr="[OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED] Overriding 'writeToParcel' is not allowed. Use 'Parceler' companion object instead">override</error> fun writeToParcel(p: Parcel?, flags: Int) {}
<!OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED!>override<!> fun writeToParcel(p: Parcel?, flags: Int) {}
}
@Parcelize
class C(val a: String) : Parcelable {
<error descr="[OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED] Overriding 'writeToParcel' is not allowed. Use 'Parceler' companion object instead">override</error> fun writeToParcel(p: Parcel, flags: Int) {}
<!OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED!>override<!> fun writeToParcel(p: Parcel, flags: Int) {}
}
@@ -10,4 +10,4 @@ open class Delegate : Parcelable {
}
@Parcelize
class Test : Parcelable <error descr="[PARCELABLE_DELEGATE_IS_NOT_ALLOWED] Delegating 'Parcelable' is not allowed">by</error> Delegate()
class Test : Parcelable <!PARCELABLE_DELEGATE_IS_NOT_ALLOWED!>by<!> Delegate()
@@ -21,26 +21,26 @@ object Parceler2 : Parceler<List<String>> {
}
}
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@Parcelize</warning>
<error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@TypeParceler<String, <error descr="[UPPER_BOUND_VIOLATED] Type argument is not within its bounds: should be subtype of 'Parceler<in String>'">Parceler2</error>></error>
<!DEPRECATED_ANNOTATION!>@Parcelize<!>
<!FORBIDDEN_DEPRECATED_ANNOTATION!>@TypeParceler<String, <!UPPER_BOUND_VIOLATED!>Parceler2<!>><!>
data class Test(
val a: String,
val b: <error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler1></error> String,
val c: <error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler2></error> List<<error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler1></error> String>
val b: <!FORBIDDEN_DEPRECATED_ANNOTATION!>@WriteWith<Parceler1><!> String,
val c: <!FORBIDDEN_DEPRECATED_ANNOTATION!>@WriteWith<Parceler2><!> List<<!FORBIDDEN_DEPRECATED_ANNOTATION!>@WriteWith<Parceler1><!> String>
) : Parcelable {
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@IgnoredOnParcel</warning>
<!DEPRECATED_ANNOTATION!>@IgnoredOnParcel<!>
val x by lazy { "foo" }
}
interface ParcelerForUser: Parceler<User>
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@Parcelize</warning>
<!DEPRECATED_ANNOTATION!>@Parcelize<!>
class User(val name: String) : Parcelable {
private companion <error descr="[DEPRECATED_PARCELER] 'kotlinx.android.parcel.Parceler' is deprecated. Use 'kotlinx.parcelize.Parceler' instead">object</error> : ParcelerForUser {
private companion <!DEPRECATED_PARCELER!>object<!> : ParcelerForUser {
override fun User.write(parcel: Parcel, flags: Int) {
parcel.writeString(name)
}
override fun create(parcel: Parcel) = User(parcel.readString()!!)
}
}
}
@@ -7,4 +7,4 @@ import android.os.Parcelable
class User : Parcelable
@Parcelize
class <warning descr="[PARCELABLE_PRIMARY_CONSTRUCTOR_IS_EMPTY] The primary constructor is empty, no data will be serialized to 'Parcel'">User2</warning>() : Parcelable
class <!PARCELABLE_PRIMARY_CONSTRUCTOR_IS_EMPTY!>User2<!>() : Parcelable
@@ -17,4 +17,4 @@ class Foo(val box: Box): Parcelable {
}
@Parcelize
class Foo2(val box: <error descr="[PARCELABLE_TYPE_NOT_SUPPORTED] Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'">Box</error>): Parcelable
class Foo2(val box: <!PARCELABLE_TYPE_NOT_SUPPORTED!>Box<!>): Parcelable
@@ -10,22 +10,22 @@ open class Open(val foo: String) : Parcelable
class Final(val foo: String) : Parcelable
@Parcelize
<error descr="[PARCELABLE_SHOULD_BE_INSTANTIABLE] 'Parcelable' should not be a 'sealed' or 'abstract' class">abstract</error> class Abstract(val foo: String) : Parcelable
<!PARCELABLE_SHOULD_BE_INSTANTIABLE!>abstract<!> class Abstract(val foo: String) : Parcelable
@Parcelize
<error descr="[PARCELABLE_SHOULD_BE_INSTANTIABLE] 'Parcelable' should not be a 'sealed' or 'abstract' class">sealed</error> class Sealed(val foo: String) : Parcelable {
sealed class Sealed(val foo: String) : Parcelable {
class X : Sealed("")
}
class Outer {
@Parcelize
<error descr="[PARCELABLE_CANT_BE_INNER_CLASS] 'Parcelable' can't be an inner class">inner</error> class Inner(val foo: String) : Parcelable
<!PARCELABLE_CANT_BE_INNER_CLASS!>inner<!> class Inner(val foo: String) : Parcelable
}
fun foo() {
@Parcelize
<error descr="[PARCELABLE_CANT_BE_LOCAL_CLASS] 'Parcelable' can't be a local class">object</error> : Parcelable {}
<!PARCELABLE_CANT_BE_LOCAL_CLASS!>object<!> : Parcelable {}
@Parcelize
class <error descr="[PARCELABLE_CANT_BE_LOCAL_CLASS] 'Parcelable' can't be a local class"><error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Local</error></error> {}
class <!NO_PARCELABLE_SUPERTYPE, PARCELABLE_CANT_BE_LOCAL_CLASS!>Local<!> {}
}
@@ -6,32 +6,32 @@ import android.os.Parcelable
@Parcelize
class A(val firstName: String) : Parcelable {
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">secondName</warning>: String = ""
val <!PROPERTY_WONT_BE_SERIALIZED!>secondName<!>: String = ""
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">delegated</warning> by lazy { "" }
val <!PROPERTY_WONT_BE_SERIALIZED!>delegated<!> by lazy { "" }
lateinit var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">lateinit</warning>: String
lateinit var <!PROPERTY_WONT_BE_SERIALIZED!>lateinit<!>: String
val customGetter: String
get() = ""
var customSetter: String
get() = ""
set(<warning descr="[UNUSED_PARAMETER] Parameter 'v' is never used">v</warning>) {}
set(v) {}
}
@Parcelize
@Suppress("WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET")
class B(<warning descr="[INAPPLICABLE_IGNORED_ON_PARCEL_CONSTRUCTOR_PROPERTY] '@IgnoredOnParcel' is inapplicable to properties declared in the primary constructor">@IgnoredOnParcel</warning> val firstName: String) : Parcelable {
class B(<!INAPPLICABLE_IGNORED_ON_PARCEL_CONSTRUCTOR_PROPERTY!>@IgnoredOnParcel<!> val firstName: String) : Parcelable {
@IgnoredOnParcel
var a: String = ""
@field:IgnoredOnParcel
var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">b</warning>: String = ""
var <!PROPERTY_WONT_BE_SERIALIZED!>b<!>: String = ""
@get:IgnoredOnParcel
var c: String = ""
@set:IgnoredOnParcel
var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">d</warning>: String = ""
}
var <!PROPERTY_WONT_BE_SERIALIZED!>d<!>: String = ""
}
@@ -7,9 +7,9 @@ import android.os.Parcelable
@Parcelize
class User(
val a: String,
val b: <error descr="[PARCELABLE_TYPE_NOT_SUPPORTED] Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'">Any</error>,
val c: <error descr="[PARCELABLE_TYPE_NOT_SUPPORTED] Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'">Any?</error>,
val d: <error descr="[PARCELABLE_TYPE_NOT_SUPPORTED] Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'">Map<Any, String></error>,
val b: <!PARCELABLE_TYPE_NOT_SUPPORTED!>Any<!>,
val c: <!PARCELABLE_TYPE_NOT_SUPPORTED!>Any?<!>,
val d: <!PARCELABLE_TYPE_NOT_SUPPORTED!>Map<Any, String><!>,
val e: @RawValue Any?,
val f: @RawValue Map<String, Any>,
val g: Map<String, @RawValue Any>,
@@ -4,7 +4,7 @@ import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
class <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Without</error>(val firstName: String, val secondName: String, val age: Int)
class <!NO_PARCELABLE_SUPERTYPE!>Without<!>(val firstName: String, val secondName: String, val age: Int)
@Parcelize
class With(val firstName: String, val secondName: String, val age: Int) : Parcelable
@@ -4,22 +4,22 @@ import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
interface <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Intf</error> : Parcelable
interface <!PARCELABLE_SHOULD_BE_CLASS!>Intf<!> : Parcelable
@Parcelize
object <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Obj</error>
object <!NO_PARCELABLE_SUPERTYPE!>Obj<!>
class A {
@Parcelize
companion <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">object</error> {
companion <!NO_PARCELABLE_SUPERTYPE!>object<!> {
fun foo() {}
}
}
@Parcelize
enum class <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Enum</error> {
enum class <!NO_PARCELABLE_SUPERTYPE!>Enum<!> {
WHITE, BLACK
}
@Parcelize
annotation class <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Anno</error>
annotation class <!PARCELABLE_SHOULD_BE_CLASS!>Anno<!>