Parcelize: Add IDE support for the Parcelize compiler plugin with sources extracted from Android Extensions plugin (KT-40030)

This commit is contained in:
Yan Zhulanow
2020-07-07 19:35:26 +09:00
parent b7796d63d8
commit 15b2850ee0
85 changed files with 2473 additions and 2 deletions
@@ -0,0 +1,29 @@
// WITH_RUNTIME
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
class A : Parcelable
@Parcelize
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
@Parcelize
class D(val firstName: String, vararg val secondName: String) : Parcelable
@Parcelize
class E(val firstName: String, val secondName: String) : Parcelable {
constructor() : this("", "")
}
@Parcelize
class <error descr="[PARCELABLE_SHOULD_HAVE_PRIMARY_CONSTRUCTOR] 'Parcelable' should have a primary constructor">F</error> : Parcelable {
constructor(a: String) {
println(a)
}
}
@@ -0,0 +1,25 @@
// WITH_RUNTIME
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
import android.os.Parcel
@Parcelize
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> {
override fun createFromParcel(source: Parcel): A = A("")
override fun newArray(size: Int) = arrayOfNulls<A>(size)
}
}
}
@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> {
override fun createFromParcel(source: Parcel): B = B("")
override fun newArray(size: Int) = arrayOfNulls<B>(size)
}
}
@@ -0,0 +1,45 @@
// WITH_RUNTIME
package test
import kotlinx.parcelize.*
import android.os.*
object StringParceler : Parceler<String> {
override fun create(parcel: Parcel) = TODO()
override fun String.write(parcel: Parcel, flags: Int) = TODO()
}
object CharSequenceParceler : Parceler<CharSequence> {
override fun create(parcel: Parcel) = TODO()
override fun CharSequence.write(parcel: Parcel, flags: Int) = TODO()
}
class StringClassParceler : Parceler<String> {
override fun create(parcel: Parcel) = TODO()
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)
@Parcelize
@TypeParceler<String, StringClassParceler>
class ShouldBeClass(val a: @WriteWith<StringClassParceler> String) : Parcelable
@Parcelize
class Test(
val a: @WriteWith<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 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
@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>
class Test3(val a: String) : Parcelable
@@ -0,0 +1,21 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
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) {}
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) {}
}
@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) {}
}
@@ -0,0 +1,13 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
import android.os.Parcel
open class Delegate : Parcelable {
override fun writeToParcel(dest: Parcel?, flags: Int) {}
override fun describeContents() = 0
}
@Parcelize
class Test : Parcelable <error descr="[PARCELABLE_DELEGATE_IS_NOT_ALLOWED] Delegating 'Parcelable' is not allowed">by</error> Delegate()
@@ -0,0 +1,10 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
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
@@ -0,0 +1,20 @@
package test
import kotlinx.parcelize.*
import android.os.*
class Box(val value: String)
@Parcelize
class Foo(val box: Box): Parcelable {
companion object : Parceler<Foo> {
override fun create(parcel: Parcel) = Foo(Box(parcel.readString()))
override fun Foo.write(parcel: Parcel, flags: Int) {
parcel.writeString(box.value)
}
}
}
@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
@@ -0,0 +1,31 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
open class Open(val foo: String) : Parcelable
@Parcelize
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
@Parcelize
<error descr="[PARCELABLE_SHOULD_BE_INSTANTIABLE] 'Parcelable' should not be a 'sealed' or 'abstract' class">sealed</error> 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
}
fun foo() {
@Parcelize
<error descr="[PARCELABLE_CANT_BE_LOCAL_CLASS] 'Parcelable' can't be a local class">object</error> : 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> {}
}
@@ -0,0 +1,11 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcel
import android.os.Parcelable
@Suppress("UNUSED_PARAMETER")
class User(firstName: String, secondName: String, val age: Int) : Parcelable {
override fun writeToParcel(p0: Parcel?, p1: Int) {}
override fun describeContents() = 0
}
@@ -0,0 +1,37 @@
// WITH_RUNTIME
package test
import kotlinx.parcelize.*
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 <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 { "" }
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
val customGetter: String
get() = ""
var customSetter: String
get() = ""
set(<warning descr="[UNUSED_PARAMETER] Parameter 'v' is never used">v</warning>) {}
}
@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 {
@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 = ""
@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 = ""
}
@@ -0,0 +1,7 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
class User(val firstName: String, val secondName: String, val age: Int) : Parcelable
@@ -0,0 +1,17 @@
package test
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue
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 e: @RawValue Any?,
val f: @RawValue Map<String, Any>,
val g: Map<String, @RawValue Any>,
val h: Map<@RawValue Any, List<@RawValue Any>>
) : Parcelable
@@ -0,0 +1,20 @@
package test
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)
@Parcelize
class With(val firstName: String, val secondName: String, val age: Int) : Parcelable
interface MyParcelableIntf : Parcelable
abstract class MyParcelableCl : Parcelable
@Parcelize
class WithIntfSubtype(val firstName: String, val secondName: String, val age: Int) : MyParcelableIntf
@Parcelize
class WithClSubtype(val firstName: String, val secondName: String, val age: Int) : MyParcelableCl()
@@ -0,0 +1,25 @@
package test
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
@Parcelize
interface <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Intf</error> : Parcelable
@Parcelize
object <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Obj</error>
class A {
@Parcelize
companion <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">object</error> {
fun foo() {}
}
}
@Parcelize
enum class <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Enum</error> {
WHITE, BLACK
}
@Parcelize
annotation class <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Anno</error>