diff options
author | Jeff Davidson <jpd@google.com> | 2015-02-19 20:05:20 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-02-19 20:05:20 +0000 |
commit | 0816d189919016880f36262e36b3a11407ead2b1 (patch) | |
tree | 34f42e05de89c57c8dd268f329e3ecb6625b2161 /src/google/protobuf/compiler/javanano/javanano_enum.cc | |
parent | f1c606d95efbfdb7a028dff14f9e8773d30a63b4 (diff) | |
parent | 72b0f4cfbb910909f953c52ba7d097a6b3904cbb (diff) | |
download | external_protobuf-0816d189919016880f36262e36b3a11407ead2b1.zip external_protobuf-0816d189919016880f36262e36b3a11407ead2b1.tar.gz external_protobuf-0816d189919016880f36262e36b3a11407ead2b1.tar.bz2 |
am 72b0f4cf: Merge "Generate @IntDef annotations for nanoproto enums."
* commit '72b0f4cfbb910909f953c52ba7d097a6b3904cbb':
Generate @IntDef annotations for nanoproto enums.
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_enum.cc')
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_enum.cc | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_enum.cc b/src/google/protobuf/compiler/javanano/javanano_enum.cc index f934b05..c6e8dfe 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum.cc +++ b/src/google/protobuf/compiler/javanano/javanano_enum.cc @@ -73,13 +73,45 @@ void EnumGenerator::Generate(io::Printer* printer) { "// enum $classname$\n", "classname", descriptor_->name()); + const string classname = RenameJavaKeywords(descriptor_->name()); + // Start of container interface + // If generating intdefs, we use the container interface as the intdef if + // present. Otherwise, we just make an empty @interface parallel to the + // constants. + bool use_intdef = params_.generate_intdefs(); bool use_shell_class = params_.java_enum_style(); - if (use_shell_class) { - printer->Print( - "public interface $classname$ {\n", - "classname", RenameJavaKeywords(descriptor_->name())); + if (use_intdef) { + // @IntDef annotation so tools can enforce correctness + // Annotations will be discarded by the compiler + printer->Print("@java.lang.annotation.Retention(" + "java.lang.annotation.RetentionPolicy.SOURCE)\n" + "@android.support.annotation.IntDef({\n"); printer->Indent(); + for (int i = 0; i < canonical_values_.size(); i++) { + const string constant_name = + RenameJavaKeywords(canonical_values_[i]->name()); + if (use_shell_class) { + printer->Print("$classname$.$name$,\n", + "classname", classname, + "name", constant_name); + } else { + printer->Print("$name$,\n", "name", constant_name); + } + } + printer->Outdent(); + printer->Print("})\n"); + } + if (use_shell_class || use_intdef) { + printer->Print( + "public $at_for_intdef$interface $classname$ {\n", + "classname", classname, + "at_for_intdef", use_intdef ? "@" : ""); + if (use_shell_class) { + printer->Indent(); + } else { + printer->Print("}\n\n"); + } } // Canonical values |