Eugene Susla | 3156a4c | 2019-07-25 14:05:12 -0700 | [diff] [blame] | 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.SystemClock; |
| 21 | |
| 22 | import com.android.internal.util.DataClass; |
| 23 | |
| 24 | import java.util.concurrent.TimeUnit; |
| 25 | |
| 26 | @DataClass(genBuilder = true) |
| 27 | public class SampleWithCustomBuilder { |
| 28 | |
| 29 | long delayAmount = 0; |
| 30 | @NonNull |
| 31 | TimeUnit delayUnit = TimeUnit.MILLISECONDS; |
| 32 | |
| 33 | long creationTimestamp = SystemClock.uptimeMillis(); |
| 34 | |
| 35 | /** |
| 36 | * You can declare a class named {@code BaseBuilder} to have the generated builder extend from |
| 37 | * it instead. |
| 38 | * |
| 39 | * Same rules apply where defining a non-abstract method will suppress the generation of a |
| 40 | * method with the same signature. |
| 41 | * |
| 42 | * For abstract generatable methods, implementations are generated as normal, but original |
| 43 | * visibility is used, allowing you to hide methods. |
| 44 | * |
| 45 | * Here for example, we hide {@link #setDelayUnit} and {@link #setDelayAmount} from public API, |
| 46 | * replacing it with {@link #setDelay} instead. |
| 47 | */ |
| 48 | // Suppress setter generation for a field that is not supposed to come from user input. |
| 49 | @DataClass.Suppress("setCreationTimestamp") |
| 50 | static abstract class BaseBuilder { |
| 51 | |
| 52 | /** |
| 53 | * Hide methods by declaring them with reduced (package-private) visibility. |
| 54 | */ |
| 55 | abstract Builder setDelayAmount(long value); |
| 56 | |
| 57 | /** |
| 58 | * Alternatively, hide methods by using @hide, to hide them from public API only. |
| 59 | * |
| 60 | * @hide |
| 61 | */ |
| 62 | public abstract Builder setDelayUnit(TimeUnit value); |
| 63 | |
| 64 | /** |
| 65 | * Can provide additional method on the builder, e.g. as a replacement for the ones we've |
| 66 | * just hidden. |
| 67 | */ |
| 68 | public Builder setDelay(long amount, TimeUnit unit) { |
| 69 | setDelayAmount(amount); |
| 70 | setDelayUnit(unit); |
| 71 | return (Builder) this; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |
Eugene Susla | c49e8ee | 2019-10-01 11:49:15 -0700 | [diff] [blame] | 77 | // Code below generated by codegen v1.0.3. |
Eugene Susla | 3156a4c | 2019-07-25 14:05:12 -0700 | [diff] [blame] | 78 | // |
| 79 | // DO NOT MODIFY! |
Eugene Susla | c49e8ee | 2019-10-01 11:49:15 -0700 | [diff] [blame] | 80 | // CHECKSTYLE:OFF Generated code |
Eugene Susla | 3156a4c | 2019-07-25 14:05:12 -0700 | [diff] [blame] | 81 | // |
| 82 | // To regenerate run: |
| 83 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java |
Eugene Susla | c49e8ee | 2019-10-01 11:49:15 -0700 | [diff] [blame] | 84 | |
Eugene Susla | 3156a4c | 2019-07-25 14:05:12 -0700 | [diff] [blame] | 85 | |
| 86 | @DataClass.Generated.Member |
| 87 | /* package-private */ SampleWithCustomBuilder( |
| 88 | long delayAmount, |
| 89 | @NonNull TimeUnit delayUnit, |
| 90 | long creationTimestamp) { |
| 91 | this.delayAmount = delayAmount; |
| 92 | this.delayUnit = delayUnit; |
| 93 | com.android.internal.util.AnnotationValidations.validate( |
| 94 | NonNull.class, null, delayUnit); |
| 95 | this.creationTimestamp = creationTimestamp; |
| 96 | |
| 97 | // onConstructed(); // You can define this method to get a callback |
| 98 | } |
| 99 | |
| 100 | @DataClass.Generated.Member |
| 101 | public long getDelayAmount() { |
| 102 | return delayAmount; |
| 103 | } |
| 104 | |
| 105 | @DataClass.Generated.Member |
| 106 | public @NonNull TimeUnit getDelayUnit() { |
| 107 | return delayUnit; |
| 108 | } |
| 109 | |
| 110 | @DataClass.Generated.Member |
| 111 | public long getCreationTimestamp() { |
| 112 | return creationTimestamp; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * A builder for {@link SampleWithCustomBuilder} |
| 117 | */ |
| 118 | @SuppressWarnings("WeakerAccess") |
| 119 | @DataClass.Generated.Member |
| 120 | public static class Builder extends BaseBuilder { |
| 121 | |
| 122 | private long delayAmount; |
| 123 | private @NonNull TimeUnit delayUnit; |
| 124 | private long creationTimestamp; |
| 125 | |
| 126 | private long mBuilderFieldsSet = 0L; |
| 127 | |
| 128 | public Builder() { |
| 129 | } |
| 130 | |
| 131 | @DataClass.Generated.Member |
| 132 | @Override |
| 133 | @NonNull Builder setDelayAmount(long value) { |
| 134 | checkNotUsed(); |
| 135 | mBuilderFieldsSet |= 0x1; |
| 136 | delayAmount = value; |
| 137 | return this; |
| 138 | } |
| 139 | |
| 140 | @DataClass.Generated.Member |
| 141 | @Override |
| 142 | public @NonNull Builder setDelayUnit(@NonNull TimeUnit value) { |
| 143 | checkNotUsed(); |
| 144 | mBuilderFieldsSet |= 0x2; |
| 145 | delayUnit = value; |
| 146 | return this; |
| 147 | } |
| 148 | |
| 149 | /** Builds the instance. This builder should not be touched after calling this! */ |
| 150 | public SampleWithCustomBuilder build() { |
| 151 | checkNotUsed(); |
| 152 | mBuilderFieldsSet |= 0x8; // Mark builder used |
| 153 | |
| 154 | if ((mBuilderFieldsSet & 0x1) == 0) { |
| 155 | delayAmount = 0; |
| 156 | } |
| 157 | if ((mBuilderFieldsSet & 0x2) == 0) { |
| 158 | delayUnit = TimeUnit.MILLISECONDS; |
| 159 | } |
| 160 | if ((mBuilderFieldsSet & 0x4) == 0) { |
| 161 | creationTimestamp = SystemClock.uptimeMillis(); |
| 162 | } |
| 163 | SampleWithCustomBuilder o = new SampleWithCustomBuilder( |
| 164 | delayAmount, |
| 165 | delayUnit, |
| 166 | creationTimestamp); |
| 167 | return o; |
| 168 | } |
| 169 | |
| 170 | private void checkNotUsed() { |
| 171 | if ((mBuilderFieldsSet & 0x8) != 0) { |
| 172 | throw new IllegalStateException( |
| 173 | "This Builder should not be reused. Use a new Builder instance instead"); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | @DataClass.Generated( |
Eugene Susla | c49e8ee | 2019-10-01 11:49:15 -0700 | [diff] [blame] | 179 | time = 1569956014908L, |
| 180 | codegenVersion = "1.0.3", |
Eugene Susla | 3156a4c | 2019-07-25 14:05:12 -0700 | [diff] [blame] | 181 | sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java", |
| 182 | inputSignatures = " long delayAmount\n @android.annotation.NonNull java.util.concurrent.TimeUnit delayUnit\n long creationTimestamp\nclass SampleWithCustomBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genBuilder=true)\nabstract com.android.codegentest.SampleWithCustomBuilder.Builder setDelayAmount(long)\npublic abstract com.android.codegentest.SampleWithCustomBuilder.Builder setDelayUnit(java.util.concurrent.TimeUnit)\npublic com.android.codegentest.SampleWithCustomBuilder.Builder setDelay(long,java.util.concurrent.TimeUnit)\nclass BaseBuilder extends java.lang.Object implements []") |
| 183 | @Deprecated |
| 184 | private void __metadata() {} |
| 185 | |
| 186 | } |