From 30d873bd66f50a6021de5d44d7ee5b8a809b0524 Mon Sep 17 00:00:00 2001 From: Jeff Davidson Date: Wed, 11 Feb 2015 13:12:14 -0800 Subject: Generate @IntDef annotations for nanoproto enums. @IntDef is a support library annotation which allows build tools to determine the valid set of values for a given integer field when that field is intended to be restricted like an enum. This avoids the overhead of enums while still allowing for compile-time type checking in most circumstances. Change-Id: Iee02e0b49a8e069f6456572f538e0a0d301fdfd5 --- java/README.txt | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/README.txt b/java/README.txt index 7081a84..b02e88b 100644 --- a/java/README.txt +++ b/java/README.txt @@ -593,6 +593,28 @@ ignore_services={true,false} (default: false) parcelable_messages={true,false} (default: false) Android-specific option to generate Parcelable messages. +generate_intdefs={true,false} (default: false) + Android-specific option to generate @IntDef annotations for enums. + + If turned on, an @IntDef annotation (a public @interface) will be + generated for each enum, and every integer parameter and return + value in the generated code meant for this enum will be annotated + with it. This interface is generated with the same name and at the + same place as the enum members' container interfaces described + above under enum_style=java, regardless of the enum_style option + used. When this is combined with enum_style=java, the interface + will be both the @IntDef annotation and the container of the enum + members; otherwise the interface has an empty body. + + Your app must declare a compile-time dependency on the + android-support-annotations library. + + For more information on how these @IntDef annotations help with + compile-time type safety, see: + https://sites.google.com/a/android.com/tools/tech-docs/support-annotations + and + https://developer.android.com/reference/android/support/annotation/IntDef.html + To use nano protobufs within the Android repo: @@ -646,7 +668,7 @@ Please run the following steps to test: - "make -j12 aprotoc libprotobuf-java-nano aprotoc-test-nano-params NanoAndroidTest" and check for build errors. - Plug in an Android device or start an emulator. -- adb install -r out/target/product/generic/data/app/NanoAndroidTest.apk +- adb install -r out/target/product/generic/data/app/NanoAndroidTest/NanoAndroidTest.apk - Run: "adb shell am instrument -w com.google.protobuf.nano.test/android.test.InstrumentationTestRunner" and verify all tests pass. -- cgit v1.1