Skip to content

Commit 76fd11b

Browse files
authored
Don't reference CREATOR directly
1 parent 45977b5 commit 76fd11b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

compiler/src/main/java/nz/bradcampbell/paperparcel/model/properties/ParcelableProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public ParcelableProperty(boolean isNullable, TypeName typeName, boolean isInter
2222
protected CodeBlock readFromParcelInner(CodeBlock.Builder block, ParameterSpec in, @Nullable FieldSpec classLoader,
2323
Map<ClassName, CodeBlock> typeAdaptersMap, Set<String> scopedVariableNames) {
2424
TypeName rawTypeName = getRawTypeName(getTypeName());
25-
return CodeBlock.of("$T.CREATOR.createFromParcel($N)", rawTypeName, in);
25+
return CodeBlock.of("$N.readParcelable($T.class.getClassLoader())", in, rawTypeName);
2626
}
2727

2828
@Override
2929
protected void writeToParcelInner(
3030
CodeBlock.Builder block, ParameterSpec dest, ParameterSpec flags, CodeBlock sourceLiteral,
3131
Map<ClassName, CodeBlock> typeAdaptersMap, Set<String> scopedVariableNames) {
32-
block.addStatement("$L.writeToParcel($N, $N)", sourceLiteral, dest, flags);
32+
block.addStatement("$N.writeParcelable($L, $N)", dest, sourceLiteral, flags);
3333
}
3434

3535
private TypeName getRawTypeName(TypeName typeName) {

compiler/src/test/java/nz/bradcampbell/paperparcel/ArrayTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public class ArrayTests {
128128
"for (int childIndex = 0; childIndex < childSize; childIndex++) {",
129129
"Bitmap outChildComponent = null;",
130130
"if (in.readInt() == 0) {",
131-
"outChildComponent = Bitmap.CREATOR.createFromParcel(in);",
131+
"outChildComponent = in.readParcelable(Bitmap.class.getClassLoader());",
132132
"}",
133133
"child[childIndex] = outChildComponent;",
134134
"}",
@@ -162,7 +162,7 @@ public class ArrayTests {
162162
"dest.writeInt(1);",
163163
"} else {",
164164
"dest.writeInt(0);",
165-
"childItem.writeToParcel(dest, flags);",
165+
"dest.writeParcelable(childItem, flags);",
166166
"}",
167167
"}",
168168
"}",

compiler/src/test/java/nz/bradcampbell/paperparcel/ParcelableTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class ParcelableTests {
4444
"@Override public TestParcel createFromParcel(Parcel in) {",
4545
"Bitmap outChild = null;",
4646
"if (in.readInt() == 0) {",
47-
"outChild = Bitmap.CREATOR.createFromParcel(in);",
47+
"outChild = in.readParcelable(Bitmap.class.getClassLoader());",
4848
"}",
4949
"Test data = new Test(outChild);",
5050
"return new TestParcel(data);",
@@ -66,7 +66,7 @@ public class ParcelableTests {
6666
"dest.writeInt(1);",
6767
"} else {",
6868
"dest.writeInt(0);",
69-
"child.writeToParcel(dest, flags);",
69+
"dest.writeParcelable(child, flags);",
7070
"}",
7171
"}",
7272
"}"
@@ -146,7 +146,7 @@ public class ParcelableTests {
146146
"@Override public RootParcel createFromParcel(Parcel in) {",
147147
"Child outChild = null;",
148148
"if (in.readInt() == 0) {",
149-
"outChild = Child.CREATOR.createFromParcel(in);",
149+
"outChild = in.readParcelable(Child.class.getClassLoader())",
150150
"}",
151151
"Root data = new Root(outChild);",
152152
"return new RootParcel(data);",
@@ -168,7 +168,7 @@ public class ParcelableTests {
168168
"dest.writeInt(1);",
169169
"} else {",
170170
"dest.writeInt(0);",
171-
"child.writeToParcel(dest, flags);",
171+
"dest.writeParcelable(child, flags);",
172172
"}",
173173
"}",
174174
"}"

compiler/src/test/java/nz/bradcampbell/paperparcel/SerializableTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public class SerializableTests {
198198
"@Override public TestParcel createFromParcel(Parcel in) {",
199199
"Child outChild = null;",
200200
"if (in.readInt() == 0) {",
201-
"outChild = Child.CREATOR.createFromParcel(in);",
201+
"outChild = in.readParcelable(Child.class.getClassLoader());",
202202
"}",
203203
"Test data = new Test(outChild);",
204204
"return new TestParcel(data);",
@@ -220,7 +220,7 @@ public class SerializableTests {
220220
"dest.writeInt(1);",
221221
"} else {",
222222
"dest.writeInt(0);",
223-
"child.writeToParcel(dest, flags);",
223+
"dest.writeParcelable(child, flags);",
224224
"}",
225225
"}",
226226
"}"

0 commit comments

Comments
 (0)