Support arrays in ResourceInspectionProcessor
Test: ResourceInspectionProcessorTest
Fix: 184560037
Change-Id: If9a01baff3445cac36acf74772376dfa1296353c
diff --git a/resourceinspection/resourceinspection-processor/src/main/kotlin/androidx/resourceinspection/processor/LayoutInspectionStep.kt b/resourceinspection/resourceinspection-processor/src/main/kotlin/androidx/resourceinspection/processor/LayoutInspectionStep.kt
index 3130653..6038e6e 100644
--- a/resourceinspection/resourceinspection-processor/src/main/kotlin/androidx/resourceinspection/processor/LayoutInspectionStep.kt
+++ b/resourceinspection/resourceinspection-processor/src/main/kotlin/androidx/resourceinspection/processor/LayoutInspectionStep.kt
@@ -188,7 +188,7 @@
} else {
AttributeTypeIR.LONG
}
- TypeKind.DECLARED ->
+ TypeKind.DECLARED, TypeKind.ARRAY ->
if (getter.returnType.isAssignableTo("android.graphics.Color")) {
AttributeTypeIR.COLOR
} else {
diff --git a/resourceinspection/resourceinspection-processor/src/test/kotlin/androidx/resourceinspection/processor/ResourceInspectionProcessorTest.kt b/resourceinspection/resourceinspection-processor/src/test/kotlin/androidx/resourceinspection/processor/ResourceInspectionProcessorTest.kt
index dc24799..4a62ea9 100644
--- a/resourceinspection/resourceinspection-processor/src/test/kotlin/androidx/resourceinspection/processor/ResourceInspectionProcessorTest.kt
+++ b/resourceinspection/resourceinspection-processor/src/test/kotlin/androidx/resourceinspection/processor/ResourceInspectionProcessorTest.kt
@@ -201,7 +201,7 @@
"androidx.pkg", "testBoolean", "testByte", "testCharacter", "testDouble",
"testFloat", "testInt", "testLong", "testShort", "testString",
"colorInt", "colorLong", "colorObject", "layoutResourceId", "anyResourceId",
- "gravityInt"
+ "gravityInt", "intArray"
),
java(
"androidx.pkg.SimpleTypesTestView",
@@ -306,6 +306,12 @@
public int getGravityInt() {
return 14;
}
+
+ @NonNull
+ @Attribute("androidx.pkg:intArray")
+ public int[] getIntArray() {
+ return new int[15];
+ }
}
"""
)
@@ -336,6 +342,7 @@
private int mColorLongId;
private int mColorObjectId;
private int mGravityIntId;
+ private int mIntArrayId;
private int mLayoutResourceIdId;
private int mTestBooleanId;
private int mTestByteId;
@@ -359,6 +366,8 @@
.mapColor("colorObject", R.attr.colorObject);
mGravityIntId = propertyMapper
.mapGravity("gravityInt", R.attr.gravityInt)
+ mIntArrayId = propertyMapper
+ .mapObject("intArray", R.attr.intArray)
mLayoutResourceIdId = propertyMapper
.mapResourceId("layoutResourceId", R.attr.layoutResourceId);
mTestBooleanId = propertyMapper
@@ -404,6 +413,9 @@
propertyReader.readGravity(
mGravityIntId,
simpleTypesTestView.getGravityInt());
+ propertyReader.readObject(
+ mIntArrayId,
+ simpleTypesTestView.getIntArray());
propertyReader.readResourceId(
mLayoutResourceIdId,
simpleTypesTestView.getLayoutResourceId());