diff options
author | Andy Martin <heuronze@gmail.com> | 2018-08-16 23:25:33 +0100 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-08-16 15:25:33 -0700 |
commit | c2c3a84aafb6adba7a0c2d841fe248108e1a9d67 (patch) | |
tree | 8c912ee7e88f54a45bd6962f950532a00c1ba4f1 /src | |
parent | 1f03becd24b60d8634d5e725b51fabdbafd28ddb (diff) | |
download | flatbuffers-c2c3a84aafb6adba7a0c2d841fe248108e1a9d67.tar.gz flatbuffers-c2c3a84aafb6adba7a0c2d841fe248108e1a9d67.tar.bz2 flatbuffers-c2c3a84aafb6adba7a0c2d841fe248108e1a9d67.zip |
Add C#/Java generator behaviour for 'private' attribute (#4882)
* Added 'private' attribute, supported when generating C# and Java
* Added use of 'private' attribute in monster_test
Diffstat (limited to 'src')
-rw-r--r-- | src/idl_gen_general.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 27eb8c40..eda0214d 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -504,7 +504,16 @@ class GeneralGenerator : public BaseGenerator { // to map directly to how they're used in C/C++ and file formats. // That, and Java Enums are expensive, and not universally liked. GenComment(enum_def.doc_comment, code_ptr, &lang_.comment_config); - code += std::string("public ") + lang_.enum_decl + enum_def.name; + if (enum_def.attributes.Lookup("private")) { + // For Java, we leave the enum unmarked to indicate package-private + // For C# we mark the enum as internal + if (lang_.language == IDLOptions::kCSharp) { + code += "internal "; + } + } else { + code += "public "; + } + code += lang_.enum_decl + enum_def.name; if (lang_.language == IDLOptions::kCSharp) { code += lang_.inheritance_marker + GenTypeBasic(enum_def.underlying_type, false); @@ -773,7 +782,15 @@ class GeneralGenerator : public BaseGenerator { // int o = __offset(offset); return o != 0 ? bb.getType(o + i) : default; // } GenComment(struct_def.doc_comment, code_ptr, &lang_.comment_config); - code += "public "; + if (struct_def.attributes.Lookup("private")) { + // For Java, we leave the struct unmarked to indicate package-private + // For C# we mark the struct as internal + if (lang_.language == IDLOptions::kCSharp) { + code += "internal "; + } + } else { + code += "public "; + } if (lang_.language == IDLOptions::kCSharp && struct_def.attributes.Lookup("csharp_partial")) { // generate a partial class for this C# struct/table |