1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.codegentest; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.ArrayMap; 23 import android.util.SparseArray; 24 import android.util.SparseIntArray; 25 26 import com.android.internal.util.AnnotationValidations; 27 import com.android.internal.util.DataClass; 28 29 import java.util.List; 30 import java.util.Map; 31 32 /** 33 * Additional test for various parcelling corner-cases. 34 */ 35 @DataClass( 36 genBuilder = true, 37 genAidl = false, 38 genToString = true) 39 public class ParcelAllTheThingsDataClass implements Parcelable { 40 41 @NonNull String[] mStringArray = null; 42 @NonNull int[] mIntArray = null; 43 @NonNull List<String> mStringList = null; 44 45 @NonNull Map<String, SampleWithCustomBuilder> mMap = null; 46 @NonNull Map<String, String> mStringMap = null; 47 48 @NonNull SparseArray<SampleWithCustomBuilder> mSparseArray = null; 49 @NonNull SparseIntArray mSparseIntArray = null; 50 51 @SuppressWarnings({"WeakerAccess"}) 52 @Nullable Boolean mNullableBoolean = null; 53 54 55 56 57 // Code below generated by codegen v1.0.15. 58 // 59 // DO NOT MODIFY! 60 // CHECKSTYLE:OFF Generated code 61 // 62 // To regenerate run: 63 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java 64 // 65 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 66 // Settings > Editor > Code Style > Formatter Control 67 //@formatter:off 68 69 70 @DataClass.Generated.Member ParcelAllTheThingsDataClass( @onNull String[] stringArray, @NonNull int[] intArray, @NonNull List<String> stringList, @NonNull Map<String,SampleWithCustomBuilder> map, @NonNull Map<String,String> stringMap, @NonNull SparseArray<SampleWithCustomBuilder> sparseArray, @NonNull SparseIntArray sparseIntArray, @SuppressWarnings({ "WeakerAccess" }) @Nullable Boolean nullableBoolean)71 /* package-private */ ParcelAllTheThingsDataClass( 72 @NonNull String[] stringArray, 73 @NonNull int[] intArray, 74 @NonNull List<String> stringList, 75 @NonNull Map<String,SampleWithCustomBuilder> map, 76 @NonNull Map<String,String> stringMap, 77 @NonNull SparseArray<SampleWithCustomBuilder> sparseArray, 78 @NonNull SparseIntArray sparseIntArray, 79 @SuppressWarnings({ "WeakerAccess" }) @Nullable Boolean nullableBoolean) { 80 this.mStringArray = stringArray; 81 AnnotationValidations.validate( 82 NonNull.class, null, mStringArray); 83 this.mIntArray = intArray; 84 AnnotationValidations.validate( 85 NonNull.class, null, mIntArray); 86 this.mStringList = stringList; 87 AnnotationValidations.validate( 88 NonNull.class, null, mStringList); 89 this.mMap = map; 90 AnnotationValidations.validate( 91 NonNull.class, null, mMap); 92 this.mStringMap = stringMap; 93 AnnotationValidations.validate( 94 NonNull.class, null, mStringMap); 95 this.mSparseArray = sparseArray; 96 AnnotationValidations.validate( 97 NonNull.class, null, mSparseArray); 98 this.mSparseIntArray = sparseIntArray; 99 AnnotationValidations.validate( 100 NonNull.class, null, mSparseIntArray); 101 this.mNullableBoolean = nullableBoolean; 102 103 // onConstructed(); // You can define this method to get a callback 104 } 105 106 @DataClass.Generated.Member getStringArray()107 public @NonNull String[] getStringArray() { 108 return mStringArray; 109 } 110 111 @DataClass.Generated.Member getIntArray()112 public @NonNull int[] getIntArray() { 113 return mIntArray; 114 } 115 116 @DataClass.Generated.Member getStringList()117 public @NonNull List<String> getStringList() { 118 return mStringList; 119 } 120 121 @DataClass.Generated.Member getMap()122 public @NonNull Map<String,SampleWithCustomBuilder> getMap() { 123 return mMap; 124 } 125 126 @DataClass.Generated.Member getStringMap()127 public @NonNull Map<String,String> getStringMap() { 128 return mStringMap; 129 } 130 131 @DataClass.Generated.Member getSparseArray()132 public @NonNull SparseArray<SampleWithCustomBuilder> getSparseArray() { 133 return mSparseArray; 134 } 135 136 @DataClass.Generated.Member getSparseIntArray()137 public @NonNull SparseIntArray getSparseIntArray() { 138 return mSparseIntArray; 139 } 140 141 @DataClass.Generated.Member getNullableBoolean()142 public @SuppressWarnings({ "WeakerAccess" }) @Nullable Boolean getNullableBoolean() { 143 return mNullableBoolean; 144 } 145 146 @Override 147 @DataClass.Generated.Member toString()148 public String toString() { 149 // You can override field toString logic by defining methods like: 150 // String fieldNameToString() { ... } 151 152 return "ParcelAllTheThingsDataClass { " + 153 "stringArray = " + java.util.Arrays.toString(mStringArray) + ", " + 154 "intArray = " + java.util.Arrays.toString(mIntArray) + ", " + 155 "stringList = " + mStringList + ", " + 156 "map = " + mMap + ", " + 157 "stringMap = " + mStringMap + ", " + 158 "sparseArray = " + mSparseArray + ", " + 159 "sparseIntArray = " + mSparseIntArray + ", " + 160 "nullableBoolean = " + mNullableBoolean + 161 " }"; 162 } 163 164 @Override 165 @DataClass.Generated.Member writeToParcel(@onNull Parcel dest, int flags)166 public void writeToParcel(@NonNull Parcel dest, int flags) { 167 // You can override field parcelling by defining methods like: 168 // void parcelFieldName(Parcel dest, int flags) { ... } 169 170 int flg = 0; 171 if (mNullableBoolean != null) flg |= 0x80; 172 dest.writeInt(flg); 173 dest.writeStringArray(mStringArray); 174 dest.writeIntArray(mIntArray); 175 dest.writeStringList(mStringList); 176 dest.writeMap(mMap); 177 dest.writeMap(mStringMap); 178 dest.writeSparseArray(mSparseArray); 179 dest.writeSparseIntArray(mSparseIntArray); 180 if (mNullableBoolean != null) dest.writeBoolean(mNullableBoolean); 181 } 182 183 @Override 184 @DataClass.Generated.Member describeContents()185 public int describeContents() { return 0; } 186 187 /** @hide */ 188 @SuppressWarnings({"unchecked", "RedundantCast"}) 189 @DataClass.Generated.Member ParcelAllTheThingsDataClass(@onNull Parcel in)190 protected ParcelAllTheThingsDataClass(@NonNull Parcel in) { 191 // You can override field unparcelling by defining methods like: 192 // static FieldType unparcelFieldName(Parcel in) { ... } 193 194 int flg = in.readInt(); 195 String[] stringArray = in.createStringArray(); 196 int[] intArray = in.createIntArray(); 197 List<String> stringList = new java.util.ArrayList<>(); 198 in.readStringList(stringList); 199 Map<String,SampleWithCustomBuilder> map = new java.util.LinkedHashMap<>(); 200 in.readMap(map, SampleWithCustomBuilder.class.getClassLoader()); 201 Map<String,String> stringMap = new java.util.LinkedHashMap<>(); 202 in.readMap(stringMap, String.class.getClassLoader()); 203 SparseArray<SampleWithCustomBuilder> sparseArray = (SparseArray) in.readSparseArray(SampleWithCustomBuilder.class.getClassLoader()); 204 SparseIntArray sparseIntArray = (SparseIntArray) in.readSparseIntArray(); 205 Boolean nullableBoolean = (flg & 0x80) == 0 ? null : (Boolean) in.readBoolean(); 206 207 this.mStringArray = stringArray; 208 AnnotationValidations.validate( 209 NonNull.class, null, mStringArray); 210 this.mIntArray = intArray; 211 AnnotationValidations.validate( 212 NonNull.class, null, mIntArray); 213 this.mStringList = stringList; 214 AnnotationValidations.validate( 215 NonNull.class, null, mStringList); 216 this.mMap = map; 217 AnnotationValidations.validate( 218 NonNull.class, null, mMap); 219 this.mStringMap = stringMap; 220 AnnotationValidations.validate( 221 NonNull.class, null, mStringMap); 222 this.mSparseArray = sparseArray; 223 AnnotationValidations.validate( 224 NonNull.class, null, mSparseArray); 225 this.mSparseIntArray = sparseIntArray; 226 AnnotationValidations.validate( 227 NonNull.class, null, mSparseIntArray); 228 this.mNullableBoolean = nullableBoolean; 229 230 // onConstructed(); // You can define this method to get a callback 231 } 232 233 @DataClass.Generated.Member 234 public static final @NonNull Parcelable.Creator<ParcelAllTheThingsDataClass> CREATOR 235 = new Parcelable.Creator<ParcelAllTheThingsDataClass>() { 236 @Override 237 public ParcelAllTheThingsDataClass[] newArray(int size) { 238 return new ParcelAllTheThingsDataClass[size]; 239 } 240 241 @Override 242 public ParcelAllTheThingsDataClass createFromParcel(@NonNull Parcel in) { 243 return new ParcelAllTheThingsDataClass(in); 244 } 245 }; 246 247 /** 248 * A builder for {@link ParcelAllTheThingsDataClass} 249 */ 250 @SuppressWarnings("WeakerAccess") 251 @DataClass.Generated.Member 252 public static class Builder { 253 254 private @NonNull String[] mStringArray; 255 private @NonNull int[] mIntArray; 256 private @NonNull List<String> mStringList; 257 private @NonNull Map<String,SampleWithCustomBuilder> mMap; 258 private @NonNull Map<String,String> mStringMap; 259 private @NonNull SparseArray<SampleWithCustomBuilder> mSparseArray; 260 private @NonNull SparseIntArray mSparseIntArray; 261 private @SuppressWarnings({ "WeakerAccess" }) @Nullable Boolean mNullableBoolean; 262 263 private long mBuilderFieldsSet = 0L; 264 Builder()265 public Builder() { 266 } 267 268 @DataClass.Generated.Member setStringArray(@onNull String... value)269 public @NonNull Builder setStringArray(@NonNull String... value) { 270 checkNotUsed(); 271 mBuilderFieldsSet |= 0x1; 272 mStringArray = value; 273 return this; 274 } 275 276 @DataClass.Generated.Member setIntArray(@onNull int... value)277 public @NonNull Builder setIntArray(@NonNull int... value) { 278 checkNotUsed(); 279 mBuilderFieldsSet |= 0x2; 280 mIntArray = value; 281 return this; 282 } 283 284 @DataClass.Generated.Member setStringList(@onNull List<String> value)285 public @NonNull Builder setStringList(@NonNull List<String> value) { 286 checkNotUsed(); 287 mBuilderFieldsSet |= 0x4; 288 mStringList = value; 289 return this; 290 } 291 292 /** @see #setStringList */ 293 @DataClass.Generated.Member addStringList(@onNull String value)294 public @NonNull Builder addStringList(@NonNull String value) { 295 // You can refine this method's name by providing item's singular name, e.g.: 296 // @DataClass.PluralOf("item")) mItems = ... 297 298 if (mStringList == null) setStringList(new java.util.ArrayList<>()); 299 mStringList.add(value); 300 return this; 301 } 302 303 @DataClass.Generated.Member setMap(@onNull Map<String,SampleWithCustomBuilder> value)304 public @NonNull Builder setMap(@NonNull Map<String,SampleWithCustomBuilder> value) { 305 checkNotUsed(); 306 mBuilderFieldsSet |= 0x8; 307 mMap = value; 308 return this; 309 } 310 311 /** @see #setMap */ 312 @DataClass.Generated.Member addMap(@onNull String key, @NonNull SampleWithCustomBuilder value)313 public @NonNull Builder addMap(@NonNull String key, @NonNull SampleWithCustomBuilder value) { 314 // You can refine this method's name by providing item's singular name, e.g.: 315 // @DataClass.PluralOf("item")) mItems = ... 316 317 if (mMap == null) setMap(new java.util.LinkedHashMap()); 318 mMap.put(key, value); 319 return this; 320 } 321 322 @DataClass.Generated.Member setStringMap(@onNull Map<String,String> value)323 public @NonNull Builder setStringMap(@NonNull Map<String,String> value) { 324 checkNotUsed(); 325 mBuilderFieldsSet |= 0x10; 326 mStringMap = value; 327 return this; 328 } 329 330 /** @see #setStringMap */ 331 @DataClass.Generated.Member addStringMap(@onNull String key, @NonNull String value)332 public @NonNull Builder addStringMap(@NonNull String key, @NonNull String value) { 333 // You can refine this method's name by providing item's singular name, e.g.: 334 // @DataClass.PluralOf("item")) mItems = ... 335 336 if (mStringMap == null) setStringMap(new java.util.LinkedHashMap()); 337 mStringMap.put(key, value); 338 return this; 339 } 340 341 @DataClass.Generated.Member setSparseArray(@onNull SparseArray<SampleWithCustomBuilder> value)342 public @NonNull Builder setSparseArray(@NonNull SparseArray<SampleWithCustomBuilder> value) { 343 checkNotUsed(); 344 mBuilderFieldsSet |= 0x20; 345 mSparseArray = value; 346 return this; 347 } 348 349 @DataClass.Generated.Member setSparseIntArray(@onNull SparseIntArray value)350 public @NonNull Builder setSparseIntArray(@NonNull SparseIntArray value) { 351 checkNotUsed(); 352 mBuilderFieldsSet |= 0x40; 353 mSparseIntArray = value; 354 return this; 355 } 356 357 @DataClass.Generated.Member setNullableBoolean(@uppressWarnings{ "WeakerAccess" }) @onNull Boolean value)358 public @NonNull Builder setNullableBoolean(@SuppressWarnings({ "WeakerAccess" }) @NonNull Boolean value) { 359 checkNotUsed(); 360 mBuilderFieldsSet |= 0x80; 361 mNullableBoolean = value; 362 return this; 363 } 364 365 /** Builds the instance. This builder should not be touched after calling this! */ build()366 public @NonNull ParcelAllTheThingsDataClass build() { 367 checkNotUsed(); 368 mBuilderFieldsSet |= 0x100; // Mark builder used 369 370 if ((mBuilderFieldsSet & 0x1) == 0) { 371 mStringArray = null; 372 } 373 if ((mBuilderFieldsSet & 0x2) == 0) { 374 mIntArray = null; 375 } 376 if ((mBuilderFieldsSet & 0x4) == 0) { 377 mStringList = null; 378 } 379 if ((mBuilderFieldsSet & 0x8) == 0) { 380 mMap = null; 381 } 382 if ((mBuilderFieldsSet & 0x10) == 0) { 383 mStringMap = null; 384 } 385 if ((mBuilderFieldsSet & 0x20) == 0) { 386 mSparseArray = null; 387 } 388 if ((mBuilderFieldsSet & 0x40) == 0) { 389 mSparseIntArray = null; 390 } 391 if ((mBuilderFieldsSet & 0x80) == 0) { 392 mNullableBoolean = null; 393 } 394 ParcelAllTheThingsDataClass o = new ParcelAllTheThingsDataClass( 395 mStringArray, 396 mIntArray, 397 mStringList, 398 mMap, 399 mStringMap, 400 mSparseArray, 401 mSparseIntArray, 402 mNullableBoolean); 403 return o; 404 } 405 checkNotUsed()406 private void checkNotUsed() { 407 if ((mBuilderFieldsSet & 0x100) != 0) { 408 throw new IllegalStateException( 409 "This Builder should not be reused. Use a new Builder instance instead"); 410 } 411 } 412 } 413 414 @DataClass.Generated( 415 time = 1582685649678L, 416 codegenVersion = "1.0.15", 417 sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java", 418 inputSignatures = " @android.annotation.NonNull java.lang.String[] mStringArray\n @android.annotation.NonNull int[] mIntArray\n @android.annotation.NonNull java.util.List<java.lang.String> mStringList\n @android.annotation.NonNull java.util.Map<java.lang.String,com.android.codegentest.SampleWithCustomBuilder> mMap\n @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.String> mStringMap\n @android.annotation.NonNull android.util.SparseArray<com.android.codegentest.SampleWithCustomBuilder> mSparseArray\n @android.annotation.NonNull android.util.SparseIntArray mSparseIntArray\n @java.lang.SuppressWarnings({\"WeakerAccess\"}) @android.annotation.Nullable java.lang.Boolean mNullableBoolean\nclass ParcelAllTheThingsDataClass extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genAidl=false, genToString=true)") 419 @Deprecated __metadata()420 private void __metadata() {} 421 422 423 //@formatter:on 424 // End of generated code 425 426 } 427