summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Bailey <derekbailey@google.com>2020-10-25 21:42:29 -0700
committerGitHub <noreply@github.com>2020-10-25 21:42:29 -0700
commit914c6460144d98efc09b0e1f1bd329bb715a4973 (patch)
tree554a292dc1b1272edf25b4c06a64961c87ac5634 /src
parent42d7c799776165c7d58a1c039c584fad2f392dac (diff)
downloadflatbuffers-914c6460144d98efc09b0e1f1bd329bb715a4973.tar.gz
flatbuffers-914c6460144d98efc09b0e1f1bd329bb715a4973.tar.bz2
flatbuffers-914c6460144d98efc09b0e1f1bd329bb715a4973.zip
Removed C# references from java generator. Move annotations closer to definitions (#6204)
Diffstat (limited to 'src')
-rw-r--r--src/idl_gen_java.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/idl_gen_java.cpp b/src/idl_gen_java.cpp
index e2ce1151..0d539393 100644
--- a/src/idl_gen_java.cpp
+++ b/src/idl_gen_java.cpp
@@ -60,7 +60,7 @@ class JavaGenerator : public BaseGenerator {
one_file_code += enumcode;
} else {
if (!SaveType(enum_def.name, *enum_def.defined_namespace, enumcode,
- false))
+ /* needs_includes= */ false))
return false;
}
}
@@ -76,14 +76,14 @@ class JavaGenerator : public BaseGenerator {
one_file_code += declcode;
} else {
if (!SaveType(struct_def.name, *struct_def.defined_namespace, declcode,
- true))
+ /* needs_includes= */ true))
return false;
}
}
if (parser_.opts.one_file) {
return SaveType(file_name_, *parser_.current_namespace_, one_file_code,
- true);
+ /* needs_includes= */ true);
}
return true;
}
@@ -112,11 +112,9 @@ class JavaGenerator : public BaseGenerator {
if (parser_.opts.java_checkerframework) {
code += "\nimport org.checkerframework.dataflow.qual.Pure;\n";
}
- code += "\n@SuppressWarnings(\"unused\")\n";
- }
- if (parser_.opts.gen_generated) {
- code += "\n@javax.annotation.Generated(value=\"flatc\")\n";
+ code += "\n";
}
+
code += classcode;
if (!namespace_name.empty()) code += "";
auto filename = NamespaceDir(ns) + defname + ".java";
@@ -226,9 +224,7 @@ class JavaGenerator : public BaseGenerator {
// Cast statements for mutator method parameters.
// In Java, parameters representing unsigned numbers need to be cast down to
// their respective type. For example, a long holding an unsigned int value
- // would be cast down to int before being put onto the buffer. In C#, one cast
- // directly cast an Enum to its underlying type, which is essential before
- // putting it onto the buffer.
+ // would be cast down to int before being put onto the buffer.
std::string SourceCast(const Type &type, bool castFromDest) const {
if (IsSeries(type)) {
return SourceCast(type.VectorType(), castFromDest);
@@ -305,7 +301,6 @@ class JavaGenerator : public BaseGenerator {
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
} else {
code += "public ";
}
@@ -324,7 +319,6 @@ class JavaGenerator : public BaseGenerator {
}
// Generate a generate string table for enum values.
- // We do not do that for C# where this functionality is native.
// Problem is, if values are very sparse that could generate really big
// tables. Ideally in that case we generate a map lookup instead, but for
// the moment we simply don't output a table at all.
@@ -354,10 +348,7 @@ class JavaGenerator : public BaseGenerator {
}
// Close the class
- code += "}";
- // Java does not need the closing semi-colon on class definitions.
- code += "";
- code += "\n\n";
+ code += "}\n\n";
}
// Returns the function name that is able to read a value of the given type.
@@ -575,14 +566,17 @@ class JavaGenerator : public BaseGenerator {
// int o = __offset(offset); return o != 0 ? bb.getType(o + i) : default;
// }
GenComment(struct_def.doc_comment, code_ptr, &comment_config);
+
+ if (parser_.opts.gen_generated) {
+ code += "@javax.annotation.Generated(value=\"flatc\")\n";
+ }
+ code += "@SuppressWarnings(\"unused\")\n";
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
} else {
code += "public ";
}
- code += "final ";
- code += "class " + struct_def.name;
+ code += "final class " + struct_def.name;
code += " extends ";
code += struct_def.fixed ? "Struct" : "Table";
code += " {\n";