Relax literal initializer requirement when codegen detects constants
Test: . frameworks/base/tests/Codegen/runTest.sh
Fixes: 158195639
Change-Id: I93bdea18f348aeca896a9fd619bef2d65704bb41
diff --git a/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassBase.java b/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassBase.java
index 66e44e1..1adbc2d 100644
--- a/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassBase.java
+++ b/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassBase.java
@@ -32,7 +32,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -51,7 +51,7 @@
}
@DataClass.Generated.Member
- public HierrarchicalDataClassBase setBaseData( int value) {
+ public @android.annotation.NonNull HierrarchicalDataClassBase setBaseData( int value) {
mBaseData = value;
return this;
}
@@ -98,8 +98,8 @@
};
@DataClass.Generated(
- time = 1601950882280L,
- codegenVersion = "1.0.16",
+ time = 1603836848866L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassBase.java",
inputSignatures = "private int mBaseData\nclass HierrarchicalDataClassBase extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genSetters=true)")
@Deprecated
diff --git a/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java b/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java
index 643abd8..a4fdcd1 100644
--- a/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java
+++ b/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java
@@ -46,7 +46,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -65,7 +65,7 @@
}
@DataClass.Generated.Member
- public HierrarchicalDataClassChild setChildData(@NonNull String value) {
+ public @NonNull HierrarchicalDataClassChild setChildData(@NonNull String value) {
mChildData = value;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mChildData);
@@ -120,8 +120,8 @@
};
@DataClass.Generated(
- time = 1601950883222L,
- codegenVersion = "1.0.16",
+ time = 1603836849753L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/HierrarchicalDataClassChild.java",
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)")
@Deprecated
diff --git a/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java b/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java
index 5e33a33..f0d728e 100644
--- a/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java
+++ b/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java
@@ -54,7 +54,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -412,8 +412,8 @@
}
@DataClass.Generated(
- time = 1601950881327L,
- codegenVersion = "1.0.16",
+ time = 1603836847927L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/ParcelAllTheThingsDataClass.java",
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)")
@Deprecated
diff --git a/tests/Codegen/src/com/android/codegentest/SampleDataClass.java b/tests/Codegen/src/com/android/codegentest/SampleDataClass.java
index 9e5b1a9..a3f458b 100644
--- a/tests/Codegen/src/com/android/codegentest/SampleDataClass.java
+++ b/tests/Codegen/src/com/android/codegentest/SampleDataClass.java
@@ -23,6 +23,7 @@
import android.annotation.StringDef;
import android.annotation.StringRes;
import android.annotation.UserIdInt;
+import android.content.pm.PackageManager;
import android.net.LinkAddress;
import android.os.Parcel;
import android.os.Parcelable;
@@ -86,9 +87,10 @@
* @see #toString()
* @see State
*/
- public static final int STATE_UNDEFINED = -1;
public static final int STATE_ON = 1;
public static final int STATE_OFF = 0;
+ public static final int STATE_UNDEFINED
+ = PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
/**
* {@link IntDef}s with values specified in hex("0x...") are considered to be
@@ -342,7 +344,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -356,9 +358,9 @@
@IntDef(prefix = "STATE_", value = {
- STATE_UNDEFINED,
STATE_ON,
- STATE_OFF
+ STATE_OFF,
+ STATE_UNDEFINED
})
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
@DataClass.Generated.Member
@@ -367,12 +369,12 @@
@DataClass.Generated.Member
public static String stateToString(@State int value) {
switch (value) {
- case STATE_UNDEFINED:
- return "STATE_UNDEFINED";
case STATE_ON:
return "STATE_ON";
case STATE_OFF:
return "STATE_OFF";
+ case STATE_UNDEFINED:
+ return "STATE_UNDEFINED";
default: return Integer.toHexString(value);
}
}
@@ -560,14 +562,14 @@
| FLAG_AUGMENTED_REQUEST);
this.mState = state;
- if (!(mState == STATE_UNDEFINED)
- && !(mState == STATE_ON)
- && !(mState == STATE_OFF)) {
+ if (!(mState == STATE_ON)
+ && !(mState == STATE_OFF)
+ && !(mState == STATE_UNDEFINED)) {
throw new java.lang.IllegalArgumentException(
"state was " + mState + " but must be one of: "
- + "STATE_UNDEFINED(" + STATE_UNDEFINED + "), "
+ "STATE_ON(" + STATE_ON + "), "
- + "STATE_OFF(" + STATE_OFF + ")");
+ + "STATE_OFF(" + STATE_OFF + "), "
+ + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
}
this.charSeq = charSeq;
@@ -820,7 +822,7 @@
* pieces in multiple places for each field.
*/
@DataClass.Generated.Member
- public SampleDataClass setNum( int value) {
+ public @NonNull SampleDataClass setNum( int value) {
mNum = value;
return this;
}
@@ -832,7 +834,7 @@
* @see #mNum2 ..and so should blocks at the bottom, e.g. {@code @see} blocks.
*/
@DataClass.Generated.Member
- public SampleDataClass setNum2( int value) {
+ public @NonNull SampleDataClass setNum2( int value) {
mNum2 = value;
return this;
}
@@ -846,7 +848,7 @@
* @hide
*/
@DataClass.Generated.Member
- public SampleDataClass setNum4( int value) {
+ public @NonNull SampleDataClass setNum4( int value) {
mNum4 = value;
return this;
}
@@ -855,7 +857,7 @@
* {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
*/
@DataClass.Generated.Member
- public SampleDataClass setName(@NonNull String value) {
+ public @NonNull SampleDataClass setName(@NonNull String value) {
mName = value;
return this;
}
@@ -868,7 +870,7 @@
* while mandatory fields are passed via {@link Builder#Builder constructor}.
*/
@DataClass.Generated.Member
- public SampleDataClass setName2(@NonNull String value) {
+ public @NonNull SampleDataClass setName2(@NonNull String value) {
mName2 = value;
AnnotationValidations.validate(
NonNull.class, null, mName2);
@@ -880,7 +882,7 @@
* {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
*/
@DataClass.Generated.Member
- public SampleDataClass setName4(@NonNull String value) {
+ public @NonNull SampleDataClass setName4(@NonNull String value) {
mName4 = value;
AnnotationValidations.validate(
NonNull.class, null, mName4);
@@ -892,7 +894,7 @@
* E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
*/
@DataClass.Generated.Member
- public SampleDataClass setOtherParcelable(@NonNull AccessibilityNodeInfo value) {
+ public @NonNull SampleDataClass setOtherParcelable(@NonNull AccessibilityNodeInfo value) {
mOtherParcelable = value;
return this;
}
@@ -904,7 +906,7 @@
* @see MyDateParcelling an example {@link Parcelling} implementation
*/
@DataClass.Generated.Member
- public SampleDataClass setDate(@NonNull Date value) {
+ public @NonNull SampleDataClass setDate(@NonNull Date value) {
mDate = value;
AnnotationValidations.validate(
NonNull.class, null, mDate);
@@ -916,7 +918,7 @@
* to encourage its reuse.
*/
@DataClass.Generated.Member
- public SampleDataClass setPattern(@NonNull Pattern value) {
+ public @NonNull SampleDataClass setPattern(@NonNull Pattern value) {
mPattern = value;
AnnotationValidations.validate(
NonNull.class, null, mPattern);
@@ -929,7 +931,7 @@
* {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
*/
@DataClass.Generated.Member
- public SampleDataClass setLinkAddresses2(@NonNull List<LinkAddress> value) {
+ public @NonNull SampleDataClass setLinkAddresses2(@NonNull List<LinkAddress> value) {
mLinkAddresses2 = value;
AnnotationValidations.validate(
NonNull.class, null, mLinkAddresses2);
@@ -943,7 +945,7 @@
* @see Builder#addLinkAddress(LinkAddress)
*/
@DataClass.Generated.Member
- public SampleDataClass setLinkAddresses(@NonNull ArrayList<LinkAddress> value) {
+ public @NonNull SampleDataClass setLinkAddresses(@NonNull ArrayList<LinkAddress> value) {
mLinkAddresses = value;
AnnotationValidations.validate(
NonNull.class, null, mLinkAddresses);
@@ -957,7 +959,7 @@
* @see Builder#setLinkAddresses4(LinkAddress...)
*/
@DataClass.Generated.Member
- public SampleDataClass setLinkAddresses4(@NonNull LinkAddress... value) {
+ public @NonNull SampleDataClass setLinkAddresses4(@NonNull LinkAddress... value) {
mLinkAddresses4 = value;
return this;
}
@@ -970,7 +972,7 @@
* @see Builder#setStateName
*/
@DataClass.Generated.Member
- public SampleDataClass setStateName(@StateName @NonNull String value) {
+ public @NonNull SampleDataClass setStateName(@StateName @NonNull String value) {
mStateName = value;
if (!(Objects.equals(mStateName, STATE_NAME_UNDEFINED))
@@ -992,7 +994,7 @@
* Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
*/
@DataClass.Generated.Member
- public SampleDataClass setFlags(@RequestFlags int value) {
+ public @NonNull SampleDataClass setFlags(@RequestFlags int value) {
mFlags = value;
Preconditions.checkFlagsArgument(
@@ -1007,17 +1009,17 @@
* Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
*/
@DataClass.Generated.Member
- public SampleDataClass setState(@State int value) {
+ public @NonNull SampleDataClass setState(@State int value) {
mState = value;
- if (!(mState == STATE_UNDEFINED)
- && !(mState == STATE_ON)
- && !(mState == STATE_OFF)) {
+ if (!(mState == STATE_ON)
+ && !(mState == STATE_OFF)
+ && !(mState == STATE_UNDEFINED)) {
throw new java.lang.IllegalArgumentException(
"state was " + mState + " but must be one of: "
- + "STATE_UNDEFINED(" + STATE_UNDEFINED + "), "
+ "STATE_ON(" + STATE_ON + "), "
- + "STATE_OFF(" + STATE_OFF + ")");
+ + "STATE_OFF(" + STATE_OFF + "), "
+ + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
}
return this;
@@ -1036,7 +1038,7 @@
* @see #SampleDataClass
*/
@DataClass.Generated.Member
- public SampleDataClass setStringRes(@StringRes int value) {
+ public @NonNull SampleDataClass setStringRes(@StringRes int value) {
mStringRes = value;
AnnotationValidations.validate(
StringRes.class, null, mStringRes);
@@ -1051,7 +1053,7 @@
* @see AnnotationValidations#validate(Class, Size, int, String, int, String, int)
*/
@DataClass.Generated.Member
- public SampleDataClass setDayOfWeek(@android.annotation.IntRange(from = 0, to = 6) int value) {
+ public @NonNull SampleDataClass setDayOfWeek(@android.annotation.IntRange(from = 0, to = 6) int value) {
mDayOfWeek = value;
AnnotationValidations.validate(
android.annotation.IntRange.class, null, mDayOfWeek,
@@ -1070,7 +1072,7 @@
* @see AnnotationValidations#validate(Class, Size, int, String, int)
*/
@DataClass.Generated.Member
- public SampleDataClass setCoords(@Size(2) @NonNull @FloatRange(from = 0f) float... value) {
+ public @NonNull SampleDataClass setCoords(@Size(2) @NonNull @FloatRange(from = 0f) float... value) {
mCoords = value;
AnnotationValidations.validate(
Size.class, null, mCoords.length,
@@ -1372,14 +1374,14 @@
| FLAG_AUGMENTED_REQUEST);
this.mState = state;
- if (!(mState == STATE_UNDEFINED)
- && !(mState == STATE_ON)
- && !(mState == STATE_OFF)) {
+ if (!(mState == STATE_ON)
+ && !(mState == STATE_OFF)
+ && !(mState == STATE_UNDEFINED)) {
throw new java.lang.IllegalArgumentException(
"state was " + mState + " but must be one of: "
- + "STATE_UNDEFINED(" + STATE_UNDEFINED + "), "
+ "STATE_ON(" + STATE_ON + "), "
- + "STATE_OFF(" + STATE_OFF + ")");
+ + "STATE_OFF(" + STATE_OFF + "), "
+ + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
}
this.charSeq = _charSeq;
@@ -1872,10 +1874,10 @@
}
@DataClass.Generated(
- time = 1601950879293L,
- codegenVersion = "1.0.16",
+ time = 1603836845952L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleDataClass.java",
- inputSignatures = "public static final java.lang.String STATE_NAME_UNDEFINED\npublic static final java.lang.String STATE_NAME_ON\npublic static final java.lang.String STATE_NAME_OFF\npublic static final int STATE_UNDEFINED\npublic static final int STATE_ON\npublic static final int STATE_OFF\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_AUGMENTED_REQUEST\nprivate int mNum\nprivate int mNum2\nprivate int mNum4\nprivate @android.annotation.Nullable java.lang.String mName\nprivate @android.annotation.NonNull java.lang.String mName2\nprivate @android.annotation.NonNull java.lang.String mName4\nprivate @android.annotation.Nullable android.view.accessibility.AccessibilityNodeInfo mOtherParcelable\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.codegentest.MyDateParcelling.class) @android.annotation.NonNull java.util.Date mDate\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForPattern.class) @android.annotation.NonNull java.util.regex.Pattern mPattern\nprivate @android.annotation.NonNull java.util.List<android.net.LinkAddress> mLinkAddresses2\nprivate @com.android.internal.util.DataClass.PluralOf(\"linkAddress\") @android.annotation.NonNull java.util.ArrayList<android.net.LinkAddress> mLinkAddresses\nprivate @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses4\nprivate @com.android.codegentest.SampleDataClass.StateName @android.annotation.NonNull java.lang.String mStateName\nprivate @com.android.codegentest.SampleDataClass.RequestFlags int mFlags\nprivate @com.android.codegentest.SampleDataClass.State int mState\npublic @android.annotation.NonNull java.lang.CharSequence charSeq\nprivate final @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses5\nprivate transient android.net.LinkAddress[] mLinkAddresses6\ntransient int[] mTmpStorage\nprivate @android.annotation.StringRes int mStringRes\nprivate @android.annotation.IntRange(from=0L, to=6L) int mDayOfWeek\nprivate @android.annotation.Size(2L) @android.annotation.NonNull @com.android.internal.util.DataClass.Each @android.annotation.FloatRange(from=0.0) float[] mCoords\nprivate static java.lang.String defaultName4()\nprivate int[] lazyInitTmpStorage()\npublic android.net.LinkAddress[] getLinkAddresses4()\nprivate boolean patternEquals(java.util.regex.Pattern)\nprivate int patternHashCode()\nprivate void onConstructed()\npublic void dump(java.io.PrintWriter)\nclass SampleDataClass extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genConstructor=true, genEqualsHashCode=true, genToString=true, genForEachField=true, genSetters=true)")
+ inputSignatures = "public static final java.lang.String STATE_NAME_UNDEFINED\npublic static final java.lang.String STATE_NAME_ON\npublic static final java.lang.String STATE_NAME_OFF\npublic static final int STATE_ON\npublic static final int STATE_OFF\npublic static final int STATE_UNDEFINED\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_AUGMENTED_REQUEST\nprivate int mNum\nprivate int mNum2\nprivate int mNum4\nprivate @android.annotation.Nullable java.lang.String mName\nprivate @android.annotation.NonNull java.lang.String mName2\nprivate @android.annotation.NonNull java.lang.String mName4\nprivate @android.annotation.Nullable android.view.accessibility.AccessibilityNodeInfo mOtherParcelable\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.codegentest.MyDateParcelling.class) @android.annotation.NonNull java.util.Date mDate\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForPattern.class) @android.annotation.NonNull java.util.regex.Pattern mPattern\nprivate @android.annotation.NonNull java.util.List<android.net.LinkAddress> mLinkAddresses2\nprivate @com.android.internal.util.DataClass.PluralOf(\"linkAddress\") @android.annotation.NonNull java.util.ArrayList<android.net.LinkAddress> mLinkAddresses\nprivate @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses4\nprivate @com.android.codegentest.SampleDataClass.StateName @android.annotation.NonNull java.lang.String mStateName\nprivate @com.android.codegentest.SampleDataClass.RequestFlags int mFlags\nprivate @com.android.codegentest.SampleDataClass.State int mState\npublic @android.annotation.NonNull java.lang.CharSequence charSeq\nprivate final @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses5\nprivate transient android.net.LinkAddress[] mLinkAddresses6\ntransient int[] mTmpStorage\nprivate @android.annotation.StringRes int mStringRes\nprivate @android.annotation.IntRange(from=0L, to=6L) int mDayOfWeek\nprivate @android.annotation.Size(2L) @android.annotation.NonNull @com.android.internal.util.DataClass.Each @android.annotation.FloatRange(from=0.0) float[] mCoords\nprivate static java.lang.String defaultName4()\nprivate int[] lazyInitTmpStorage()\npublic android.net.LinkAddress[] getLinkAddresses4()\nprivate boolean patternEquals(java.util.regex.Pattern)\nprivate int patternHashCode()\nprivate void onConstructed()\npublic void dump(java.io.PrintWriter)\nclass SampleDataClass extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genConstructor=true, genEqualsHashCode=true, genToString=true, genForEachField=true, genSetters=true)")
@Deprecated
private void __metadata() {}
diff --git a/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java b/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java
index 735f704..e356704 100644
--- a/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java
+++ b/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java
@@ -85,7 +85,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -253,8 +253,8 @@
}
@DataClass.Generated(
- time = 1601950880290L,
- codegenVersion = "1.0.16",
+ time = 1603836846970L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithCustomBuilder.java",
inputSignatures = " long delayAmount\n @android.annotation.NonNull java.util.concurrent.TimeUnit delayUnit\n long creationTimestamp\nprivate static java.util.concurrent.TimeUnit unparcelDelayUnit(android.os.Parcel)\nprivate void parcelDelayUnit(android.os.Parcel,int)\nclass SampleWithCustomBuilder extends java.lang.Object implements [android.os.Parcelable]\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 []\n@com.android.internal.util.DataClass(genBuilder=true, genAidl=false, genToString=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 []")
@Deprecated
diff --git a/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java b/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java
index 5160121..07ec31d 100644
--- a/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java
+++ b/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java
@@ -36,7 +36,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -135,8 +135,8 @@
};
@DataClass.Generated(
- time = 1601950885147L,
- codegenVersion = "1.0.16",
+ time = 1603836851627L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java",
inputSignatures = " @android.annotation.NonNull java.lang.String mBar\nclass NestedDataClass extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true)")
@Deprecated
@@ -160,7 +160,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -259,8 +259,8 @@
};
@DataClass.Generated(
- time = 1601950885156L,
- codegenVersion = "1.0.16",
+ time = 1603836851635L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java",
inputSignatures = " @android.annotation.NonNull long mBaz2\nclass NestedDataClass3 extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true)")
@Deprecated
@@ -274,7 +274,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -373,8 +373,8 @@
};
@DataClass.Generated(
- time = 1601950885161L,
- codegenVersion = "1.0.16",
+ time = 1603836851640L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleWithNestedDataClasses.java",
inputSignatures = " @android.annotation.NonNull java.lang.String mBaz\nclass NestedDataClass2 extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true)")
@Deprecated
diff --git a/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java b/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java
index 5417c11..5cbc6b3 100644
--- a/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java
+++ b/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java
@@ -59,7 +59,7 @@
- // Code below generated by codegen v1.0.16.
+ // Code below generated by codegen v1.0.18.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -78,14 +78,14 @@
}
@DataClass.Generated.Member
- public StaleDataclassDetectorFalsePositivesTest setUsesWildcards(@NonNull List<Set<?>> value) {
+ public @NonNull StaleDataclassDetectorFalsePositivesTest setUsesWildcards(@NonNull List<Set<?>> value) {
mUsesWildcards = value;
return this;
}
@DataClass.Generated(
- time = 1601950884160L,
- codegenVersion = "1.0.16",
+ time = 1603836850677L,
+ codegenVersion = "1.0.18",
sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java",
inputSignatures = "private @android.annotation.Nullable java.util.List<java.util.Set<?>> mUsesWildcards\npublic @android.annotation.NonNull java.lang.String someMethod(int)\nclass StaleDataclassDetectorFalsePositivesTest extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=false)")
@Deprecated
diff --git a/tools/codegen/src/com/android/codegen/Debug.kt b/tools/codegen/src/com/android/codegen/Debug.kt
new file mode 100644
index 0000000..de31844
--- /dev/null
+++ b/tools/codegen/src/com/android/codegen/Debug.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.codegen
+
+import com.github.javaparser.ast.Node
+
+fun Node.dump(indent: String = ""): String {
+ return buildString {
+ append(indent)
+ appendln(dumpOneLineNoChildren())
+ childNodes.forEach { child ->
+ append(child.dump(indent + " "))
+ }
+ }
+}
+
+private fun Node.dumpOneLineNoChildren(): String {
+ val node = this
+ return buildString {
+ append(node::class.java.simpleName)
+ if (childNodes.isEmpty()) {
+ append(": ").append(node.toString())
+ }
+ }
+}
diff --git a/tools/codegen/src/com/android/codegen/Generators.kt b/tools/codegen/src/com/android/codegen/Generators.kt
index 6e1ab59..6c6d011 100644
--- a/tools/codegen/src/com/android/codegen/Generators.kt
+++ b/tools/codegen/src/com/android/codegen/Generators.kt
@@ -16,10 +16,7 @@
fun ClassPrinter.generateConstDefs() {
val consts = classAst.fields.filter {
it.isStatic && it.isFinal && it.variables.all { variable ->
- val initializer = variable.initializer.orElse(null)
- val isLiteral = initializer is LiteralExpr
- || (initializer is UnaryExpr && initializer.expression is LiteralExpr)
- isLiteral && variable.type.asString() in listOf("int", "String")
+ variable.type.asString() in listOf("int", "String")
} && it.annotations.none { it.nameAsString == DataClassSuppressConstDefs }
}.flatMap { field -> field.variables.map { it to field } }
val intConsts = consts.filter { it.first.type.asString() == "int" }
diff --git a/tools/codegen/src/com/android/codegen/SharedConstants.kt b/tools/codegen/src/com/android/codegen/SharedConstants.kt
index 785aa910..ca658a9 100644
--- a/tools/codegen/src/com/android/codegen/SharedConstants.kt
+++ b/tools/codegen/src/com/android/codegen/SharedConstants.kt
@@ -1,7 +1,7 @@
package com.android.codegen
const val CODEGEN_NAME = "codegen"
-const val CODEGEN_VERSION = "1.0.17"
+const val CODEGEN_VERSION = "1.0.18"
const val CANONICAL_BUILDER_CLASS = "Builder"
const val BASE_BUILDER_CLASS = "BaseBuilder"