Parcelable: Add declaration checker

This commit is contained in:
Yan Zhulanow
2017-06-27 16:51:39 +03:00
parent c23bca6afe
commit 4197380621
14 changed files with 421 additions and 0 deletions
@@ -0,0 +1,28 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
class A : Parcelable
@MagicParcel
class B(val firstName: String, val secondName: String) : Parcelable
@MagicParcel
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
@MagicParcel
class D(val firstName: String, vararg val secondName: String) : Parcelable
@MagicParcel
class E(val firstName: String, val secondName: String) : Parcelable {
constructor() : this("", "")
}
@MagicParcel
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,31 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
open class Open(val foo: String) : Parcelable
@MagicParcel
class Final(val foo: String) : Parcelable
@MagicParcel
<error descr="[PARCELABLE_SHOULD_BE_INSTANTIABLE] 'Parcelable' should not be a 'sealed' or 'abstract' class">abstract</error> class Abstract(val foo: String) : Parcelable
@MagicParcel
<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 {
@MagicParcel
<error descr="[PARCELABLE_CANT_BE_INNER_CLASS] 'Parcelable' can't be an inner class">inner</error> class Inner(val foo: String) : Parcelable
}
fun foo() {
@MagicParcel
<error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">object</error> : Parcelable {}
@MagicParcel
class <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype"><error descr="[PARCELABLE_CANT_BE_LOCAL_CLASS] 'Parcelable' can't be a local class">Local</error></error> {}
}
@@ -0,0 +1,11 @@
package test
import kotlinx.android.parcel.MagicParcel
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,20 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
class A(val firstName: String) : Parcelable {
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to it">secondName</warning>: String = ""
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to it">delegated</warning> by lazy { "" }
lateinit var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to it">lateinit</warning>: String
val customGetter: String
get() = ""
var customSetter: String
get() = ""
set(v) {}
}
@@ -0,0 +1,7 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
class User(val firstName: String, val secondName: String, val age: Int) : Parcelable
@@ -0,0 +1,20 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
class <error descr="[NO_PARCELABLE_SUPERTYPE] No 'Parcelable' supertype">Without</error>(val firstName: String, val secondName: String, val age: Int)
@MagicParcel
class With(val firstName: String, val secondName: String, val age: Int) : Parcelable
interface MyParcelableIntf : Parcelable
abstract class MyParcelableCl : Parcelable
@MagicParcel
class WithIntfSubtype(val firstName: String, val secondName: String, val age: Int) : MyParcelableIntf
@MagicParcel
class WithClSubtype(val firstName: String, val secondName: String, val age: Int) : MyParcelableCl()
@@ -0,0 +1,25 @@
package test
import kotlinx.android.parcel.MagicParcel
import android.os.Parcelable
@MagicParcel
interface <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Intf</error> : Parcelable
@MagicParcel
object <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Obj</error>
class A {
@MagicParcel
companion <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">object</error> {
fun foo() {}
}
}
@MagicParcel
enum class <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Enum</error> {
WHITE, BLACK
}
@MagicParcel
annotation class <error descr="[PARCELABLE_SHOULD_BE_CLASS] 'Parcelable' should be a class">Anno</error>