Fixed flatc not writing Java files without namespace.

If the schema didn't contain a namespace, paths would contain a
leading /, causing files not to be written.

Change-Id: I508772cbf6d18d464ef7d9f8842d0dbff14358a3
Tested: on Linux.
Bug: 19067493
parent 2b01247b
...@@ -605,15 +605,14 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser, ...@@ -605,15 +605,14 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
if (!classcode.length()) return true; if (!classcode.length()) return true;
std::string namespace_general; std::string namespace_general;
std::string namespace_dir = path; std::string namespace_dir = path; // Either empty or ends in separator.
auto &namespaces = parser.namespaces_.back()->components; auto &namespaces = parser.namespaces_.back()->components;
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) { for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
if (namespace_general.length()) { if (namespace_general.length()) {
namespace_general += "."; namespace_general += ".";
namespace_dir += kPathSeparator;
} }
namespace_general += *it; namespace_general += *it;
namespace_dir += *it; namespace_dir += *it + kPathSeparator;
} }
EnsureDirExists(namespace_dir); EnsureDirExists(namespace_dir);
...@@ -623,8 +622,7 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser, ...@@ -623,8 +622,7 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
if (needs_includes) code += lang.includes; if (needs_includes) code += lang.includes;
code += classcode; code += classcode;
code += lang.namespace_end; code += lang.namespace_end;
auto filename = namespace_dir + kPathSeparator + def.name + auto filename = namespace_dir + def.name + lang.file_extension;
lang.file_extension;
return SaveFile(filename.c_str(), code, false); return SaveFile(filename.c_str(), code, false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment