[Java] Use Table's fully qualified path (#8729)

* [Java] Use Table's fully qualified path

When a table's name is called `Table`, the Java bindings generated result in an error due to there being  2 Tables. This fixes the issue by fully qualifyng the flatbuffers Table import.

* Update codegen

* Update generated Java code

---------

Co-authored-by: Neville Dipale <neville@urbanlogiq.com>
This commit is contained in:
Wakahisa
2025-12-01 18:28:50 +02:00
committed by GitHub
parent 31ab0bf6c8
commit a577050817
58 changed files with 38 additions and 96 deletions

View File

@@ -207,7 +207,6 @@ class JavaGenerator : public BaseGenerator {
"import com.google.flatbuffers.ShortVector;\n"
"import com.google.flatbuffers.StringVector;\n"
"import com.google.flatbuffers.Struct;\n"
"import com.google.flatbuffers.Table;\n"
"import com.google.flatbuffers.UnionVector;\n"
"import java.nio.ByteBuffer;\n"
"import java.nio.ByteOrder;\n";
@@ -269,7 +268,7 @@ class JavaGenerator : public BaseGenerator {
case BASE_TYPE_UNION:
FLATBUFFERS_FALLTHROUGH(); // else fall thru
default:
return "Table";
return "com.google.flatbuffers.Table";
}
}
@@ -718,7 +717,7 @@ class JavaGenerator : public BaseGenerator {
const auto struct_class = namer_.Type(struct_def);
code += "final class " + struct_class;
code += " extends ";
code += struct_def.fixed ? "Struct" : "Table";
code += struct_def.fixed ? "Struct" : "com.google.flatbuffers.Table";
code += " {\n";
if (!struct_def.fixed) {
@@ -1469,7 +1468,7 @@ class JavaGenerator : public BaseGenerator {
" " + variable_name + "Type = " + field_name + "Type(" +
type_params + ");\n";
code += indent + variable_name + ".setType(" + variable_name + "Type);\n";
code += indent + "Table " + variable_name + "Value;\n";
code += indent + "com.google.flatbuffers.Table " + variable_name + "Value;\n";
code += indent + "switch (" + variable_name + "Type) {\n";
for (auto eit = enum_def.Vals().begin(); eit != enum_def.Vals().end();
++eit) {