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 17 package com.android.codegentest; 18 19 import android.annotation.NonNull; 20 import android.os.Parcelable; 21 22 import com.android.internal.util.DataClass; 23 24 /** 25 * An example of data classes that extend one another. 26 * 27 * Note that some features like constructor generation might not work well due to lack of 28 * information about the superclass when generating code for subclass. 29 * 30 * It is recommended to avoid inheritance in favor of composition for new data classes, 31 * particularly parcelable ones. 32 * 33 * However for legacy classes or where inheritance is desired for allocation efficiency, 34 * you can either use a technique from this example, opting for mutability/setters, or just write 35 * constructors by hand. 36 * 37 * @see HierrarchicalDataClassBase 38 */ 39 @DataClass( 40 genParcelable = true, 41 genConstructor = false, 42 genSetters = true) 43 public class HierrarchicalDataClassChild extends HierrarchicalDataClassBase { 44 45 private @NonNull String mChildData; 46 47 48 49 // Code below generated by codegen v1.0.23. 50 // 51 // DO NOT MODIFY! 52 // CHECKSTYLE:OFF Generated code 53 // 54 // To regenerate run: 55 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java 56 // 57 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 58 // Settings > Editor > Code Style > Formatter Control 59 //@formatter:off 60 61 62 @DataClass.Generated.Member getChildData()63 public @NonNull String getChildData() { 64 return mChildData; 65 } 66 67 @DataClass.Generated.Member setChildData(@onNull String value)68 public @NonNull HierrarchicalDataClassChild setChildData(@NonNull String value) { 69 mChildData = value; 70 com.android.internal.util.AnnotationValidations.validate( 71 NonNull.class, null, mChildData); 72 return this; 73 } 74 75 @Override 76 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)77 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 78 // You can override field parcelling by defining methods like: 79 // void parcelFieldName(Parcel dest, int flags) { ... } 80 81 super.writeToParcel(dest, flags); 82 83 dest.writeString(mChildData); 84 } 85 86 @Override 87 @DataClass.Generated.Member describeContents()88 public int describeContents() { return 0; } 89 90 /** @hide */ 91 @SuppressWarnings({"unchecked", "RedundantCast"}) 92 @DataClass.Generated.Member HierrarchicalDataClassChild(@onNull android.os.Parcel in)93 protected HierrarchicalDataClassChild(@NonNull android.os.Parcel in) { 94 // You can override field unparcelling by defining methods like: 95 // static FieldType unparcelFieldName(Parcel in) { ... } 96 97 super(in); 98 99 String childData = in.readString(); 100 101 this.mChildData = childData; 102 com.android.internal.util.AnnotationValidations.validate( 103 NonNull.class, null, mChildData); 104 105 // onConstructed(); // You can define this method to get a callback 106 } 107 108 @DataClass.Generated.Member 109 public static final @NonNull Parcelable.Creator<HierrarchicalDataClassChild> CREATOR 110 = new Parcelable.Creator<HierrarchicalDataClassChild>() { 111 @Override 112 public HierrarchicalDataClassChild[] newArray(int size) { 113 return new HierrarchicalDataClassChild[size]; 114 } 115 116 @Override 117 public HierrarchicalDataClassChild createFromParcel(@NonNull android.os.Parcel in) { 118 return new HierrarchicalDataClassChild(in); 119 } 120 }; 121 122 @DataClass.Generated( 123 time = 1616541543730L, 124 codegenVersion = "1.0.23", 125 sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java", 126 inputSignatures = "private @android.annotation.NonNull java.lang.String mChildData\nclass HierrarchicalDataClassChild extends com.android.codegentest.HierrarchicalDataClassBase implements []\n@com.android.internal.util.DataClass(genParcelable=true, genConstructor=false, genSetters=true)") 127 @Deprecated __metadata()128 private void __metadata() {} 129 130 131 //@formatter:on 132 // End of generated code 133 134 } 135