mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 11:40:01 +00:00
Apply Namer to Java. (#7194)
* Started applying Namer to Java. - Java didn't previously have keyword escaping - Added prefixes and suffixes to the Namer methods - TODO: migrate previous namer applications to using pre/suffixes - Java methods / functions are interesting, it's mostly camel case except when it involves a struct/enum name. That section is Keep case - I changed the casing for some internal arguments/variables. This violates the "don't change genfiles" rule that I've been using but it shouldn't break user code. - LegacyJavaMethod2 is interesting. Basically, Java has a "mixed" case convention where it's camel case, except for the type/variant name itself, which is keep case. So a type foo_bar would become getfoo_bar instead of getFooBar. * small fix * Namer for Namespaces * removed unused parameter, add const everywhere * Remove unused argument * More unused args * Use mutable reference out parameters * Made more strings const and inlined const empty strings * remove do not submit Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -25,6 +25,8 @@ class IdlNamer : public Namer {
|
||||
using Namer::Variable;
|
||||
using Namer::Variant;
|
||||
|
||||
std::string Constant(const FieldDef &d) const { return Constant(d.name); }
|
||||
|
||||
// Types are always structs or enums so we can only expose these two
|
||||
// overloads.
|
||||
std::string Type(const StructDef &d) const { return Type(d.name); }
|
||||
@@ -33,6 +35,9 @@ class IdlNamer : public Namer {
|
||||
std::string Function(const Definition &s) const { return Function(s.name); }
|
||||
|
||||
std::string Field(const FieldDef &s) const { return Field(s.name); }
|
||||
std::string Field(const FieldDef &d, const std::string &s) const {
|
||||
return Field(d.name + "_" + s);
|
||||
}
|
||||
|
||||
std::string Variable(const FieldDef &s) const { return Variable(s.name); }
|
||||
|
||||
@@ -49,10 +54,21 @@ class IdlNamer : public Namer {
|
||||
}
|
||||
std::string ObjectType(const EnumDef &d) const { return ObjectType(d.name); }
|
||||
|
||||
std::string Method(const FieldDef &d, const std::string &suffix) const {
|
||||
return Method(d.name, suffix);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const FieldDef &d) const {
|
||||
return Method(prefix, d.name);
|
||||
}
|
||||
|
||||
std::string Namespace(const struct Namespace &ns) const {
|
||||
return Namespace(ns.components);
|
||||
}
|
||||
|
||||
std::string NamespacedEnumVariant(const EnumDef &e, const EnumVal &v) const {
|
||||
return NamespacedString(e.defined_namespace, EnumVariant(e, v));
|
||||
}
|
||||
|
||||
std::string NamespacedType(const Definition &def) const {
|
||||
return NamespacedString(def.defined_namespace, Type(def.name));
|
||||
}
|
||||
@@ -86,6 +102,11 @@ class IdlNamer : public Namer {
|
||||
return EscapeKeyword(ConvertCase(name, Case::kLowerCamel));
|
||||
}
|
||||
|
||||
std::string LegacyJavaMethod2(const std::string &prefix, const StructDef &sd,
|
||||
const std::string &suffix) const {
|
||||
return prefix + sd.name + suffix;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string NamespacedString(const struct Namespace *ns,
|
||||
const std::string &str) const {
|
||||
@@ -111,4 +132,4 @@ inline Namer::Config WithFlagOptions(const Namer::Config &input,
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_IDL_NAMER
|
||||
#endif // FLATBUFFERS_IDL_NAMER
|
||||
|
||||
Reference in New Issue
Block a user