Lint: Fix KT-11919 ("Missing Parcelable CREATOR field" rule is not accurate)

This commit is contained in:
Yan Zhulanow
2016-04-19 16:14:34 +03:00
parent 33434a3c5b
commit a2b1eb7ee8
6 changed files with 114 additions and 7 deletions
@@ -90,7 +90,18 @@ public class ParcelDetector extends Detector implements UastScanner {
String name = reference.getName();
if (name.equals("Parcelable")) {
UVariable field = UastUtils.findStaticMemberOfType(node, "CREATOR", UVariable.class);
if (field == null) {
boolean hasField = field != null && field.hasModifier(UastModifier.FIELD);
boolean hasNamedCompanionObject = false;
if (!hasField) {
for (UClass companion : node.getCompanions()) {
if (companion.getName().equals("CREATOR")) {
hasNamedCompanionObject = true;
break;
}
}
}
if (!hasField && !hasNamedCompanionObject) {
// Make doubly sure that we're really implementing
// android.os.Parcelable
UClass parcelable = reference.resolve(mContext);