forked from BigfootDev/flatbuffers
Removed C# references from java generator. Move annotations closer to definitions (#6204)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -134,4 +134,5 @@ js/**/*.js
|
|||||||
js/**/*.d.ts
|
js/**/*.d.ts
|
||||||
mjs/**/*.js
|
mjs/**/*.js
|
||||||
mjs/**/*.d.ts
|
mjs/**/*.d.ts
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
.cache/
|
||||||
@@ -60,7 +60,7 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
one_file_code += enumcode;
|
one_file_code += enumcode;
|
||||||
} else {
|
} else {
|
||||||
if (!SaveType(enum_def.name, *enum_def.defined_namespace, enumcode,
|
if (!SaveType(enum_def.name, *enum_def.defined_namespace, enumcode,
|
||||||
false))
|
/* needs_includes= */ false))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,14 +76,14 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
one_file_code += declcode;
|
one_file_code += declcode;
|
||||||
} else {
|
} else {
|
||||||
if (!SaveType(struct_def.name, *struct_def.defined_namespace, declcode,
|
if (!SaveType(struct_def.name, *struct_def.defined_namespace, declcode,
|
||||||
true))
|
/* needs_includes= */ true))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser_.opts.one_file) {
|
if (parser_.opts.one_file) {
|
||||||
return SaveType(file_name_, *parser_.current_namespace_, one_file_code,
|
return SaveType(file_name_, *parser_.current_namespace_, one_file_code,
|
||||||
true);
|
/* needs_includes= */ true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -112,11 +112,9 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
if (parser_.opts.java_checkerframework) {
|
if (parser_.opts.java_checkerframework) {
|
||||||
code += "\nimport org.checkerframework.dataflow.qual.Pure;\n";
|
code += "\nimport org.checkerframework.dataflow.qual.Pure;\n";
|
||||||
}
|
}
|
||||||
code += "\n@SuppressWarnings(\"unused\")\n";
|
code += "\n";
|
||||||
}
|
|
||||||
if (parser_.opts.gen_generated) {
|
|
||||||
code += "\n@javax.annotation.Generated(value=\"flatc\")\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code += classcode;
|
code += classcode;
|
||||||
if (!namespace_name.empty()) code += "";
|
if (!namespace_name.empty()) code += "";
|
||||||
auto filename = NamespaceDir(ns) + defname + ".java";
|
auto filename = NamespaceDir(ns) + defname + ".java";
|
||||||
@@ -226,9 +224,7 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
// Cast statements for mutator method parameters.
|
// Cast statements for mutator method parameters.
|
||||||
// In Java, parameters representing unsigned numbers need to be cast down to
|
// In Java, parameters representing unsigned numbers need to be cast down to
|
||||||
// their respective type. For example, a long holding an unsigned int value
|
// 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
|
// would be cast down to int before being put onto the buffer.
|
||||||
// directly cast an Enum to its underlying type, which is essential before
|
|
||||||
// putting it onto the buffer.
|
|
||||||
std::string SourceCast(const Type &type, bool castFromDest) const {
|
std::string SourceCast(const Type &type, bool castFromDest) const {
|
||||||
if (IsSeries(type)) {
|
if (IsSeries(type)) {
|
||||||
return SourceCast(type.VectorType(), castFromDest);
|
return SourceCast(type.VectorType(), castFromDest);
|
||||||
@@ -305,7 +301,6 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
|
|
||||||
if (enum_def.attributes.Lookup("private")) {
|
if (enum_def.attributes.Lookup("private")) {
|
||||||
// For Java, we leave the enum unmarked to indicate package-private
|
// For Java, we leave the enum unmarked to indicate package-private
|
||||||
// For C# we mark the enum as internal
|
|
||||||
} else {
|
} else {
|
||||||
code += "public ";
|
code += "public ";
|
||||||
}
|
}
|
||||||
@@ -324,7 +319,6 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a generate string table for enum values.
|
// 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
|
// 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
|
// tables. Ideally in that case we generate a map lookup instead, but for
|
||||||
// the moment we simply don't output a table at all.
|
// the moment we simply don't output a table at all.
|
||||||
@@ -354,10 +348,7 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the class
|
// Close the class
|
||||||
code += "}";
|
code += "}\n\n";
|
||||||
// Java does not need the closing semi-colon on class definitions.
|
|
||||||
code += "";
|
|
||||||
code += "\n\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the function name that is able to read a value of the given type.
|
// 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;
|
// int o = __offset(offset); return o != 0 ? bb.getType(o + i) : default;
|
||||||
// }
|
// }
|
||||||
GenComment(struct_def.doc_comment, code_ptr, &comment_config);
|
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")) {
|
if (struct_def.attributes.Lookup("private")) {
|
||||||
// For Java, we leave the struct unmarked to indicate package-private
|
// For Java, we leave the struct unmarked to indicate package-private
|
||||||
// For C# we mark the struct as internal
|
|
||||||
} else {
|
} else {
|
||||||
code += "public ";
|
code += "public ";
|
||||||
}
|
}
|
||||||
code += "final ";
|
code += "final class " + struct_def.name;
|
||||||
code += "class " + struct_def.name;
|
|
||||||
code += " extends ";
|
code += " extends ";
|
||||||
code += struct_def.fixed ? "Struct" : "Table";
|
code += struct_def.fixed ? "Struct" : "Table";
|
||||||
code += " {\n";
|
code += " {\n";
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import java.lang.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.google.flatbuffers.*;
|
import com.google.flatbuffers.*;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
/**
|
/**
|
||||||
* an example documentation comment: "monster object"
|
* an example documentation comment: "monster object"
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class Monster extends Table {
|
public final class Monster extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
|
||||||
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
||||||
|
|||||||
Reference in New Issue
Block a user