Fix LongEnum definitions (#7596)

The MyGame/Example/LongEnum.java class did not compile because
Java expects an "L" suffix for literals of type long.

This CL fixes the code generation to include such a suffix.

Co-authored-by: Dominic Battre <battre@chromium.org>
This commit is contained in:
Dominic Battre 2022-10-21 03:15:00 +02:00 committed by GitHub
parent 5792623df4
commit f7b734438d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -63,7 +63,6 @@
<configuration>
<release>8</release>
<testExcludes>
<testExclude>**/LongEnum.java</testExclude>
<testExclude>MyGame/Example/MonsterStorageGrpc.java</testExclude>
<testExclude>MyGame/Example/StructOfStructs**</testExclude>
<testExclude>MyGame/OtherNameSpace/TableBT.java</testExclude>

View File

@ -397,6 +397,10 @@ class JavaGenerator : public BaseGenerator {
code += " ";
code += namer_.Variant(ev) + " = ";
code += enum_def.ToString(ev);
if (enum_def.underlying_type.base_type == BASE_TYPE_LONG ||
enum_def.underlying_type.base_type == BASE_TYPE_ULONG) {
code += "L";
}
code += ";\n";
}

View File

@ -5,8 +5,8 @@ package MyGame.Example;
@SuppressWarnings("unused")
public final class LongEnum {
private LongEnum() { }
public static final long LongOne = 2;
public static final long LongTwo = 4;
public static final long LongBig = 1099511627776;
public static final long LongOne = 2L;
public static final long LongTwo = 4L;
public static final long LongBig = 1099511627776L;
}