Seal all classes in Java/C#

Makes enums/structs/tables unsubclassable (final or sealed) and
prevents instantiation of enum classes (which are solely static
constants).

Tested (Mac OS 10.10.2):
1. run flattests
2. cd tests && ../flatc -c monster_test.fbs && ../flatc -j
monster_test.fbs && ../flatc -g monster_test.fbs && ../flatc -n
monster_test.fbs  # Note deltas for C# and Java.
3. ./JavaTest.sh

**Breaking api change**

Change-Id: Ie008c941c36d212690da58ddc72c9b228eb7a093
This commit is contained in:
Advay Mengle
2015-04-06 16:42:08 -07:00
committed by Wouter van Oortmerssen
parent 9d368deb05
commit 557c57eb9d
14 changed files with 26 additions and 17 deletions

View File

@@ -3,8 +3,9 @@
namespace MyGame.Example
{
public class Any
public sealed class Any
{
private Any() { }
public static readonly byte NONE = 0;
public static readonly byte Monster = 1;

View File

@@ -2,7 +2,8 @@
package MyGame.Example;
public class Any {
public final class Any {
private Any() { }
public static final byte NONE = 0;
public static final byte Monster = 1;

View File

@@ -3,8 +3,9 @@
namespace MyGame.Example
{
public class Color
public sealed class Color
{
private Color() { }
public static readonly sbyte Red = 1;
public static readonly sbyte Green = 2;
public static readonly sbyte Blue = 8;

View File

@@ -2,7 +2,8 @@
package MyGame.Example;
public class Color {
public final class Color {
private Color() { }
public static final byte Red = 1;
public static final byte Green = 2;
public static final byte Blue = 8;

View File

@@ -5,7 +5,7 @@ namespace MyGame.Example
using FlatBuffers;
public class Monster : Table {
public sealed class Monster : Table {
public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); }
public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb)); }
public static bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }

View File

@@ -148,9 +148,7 @@ func (rcv *Monster) TestarrayofstringLength() int {
}
/// an example documentation comment: this will end up in the generated code
/// multiline too
func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(26))
if o != 0 {

View File

@@ -7,7 +7,7 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class Monster extends Table {
public final class Monster extends Table {
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public static boolean MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }

View File

@@ -5,7 +5,7 @@ namespace MyGame.Example
using FlatBuffers;
public class Stat : Table {
public sealed class Stat : Table {
public static Stat GetRootAsStat(ByteBuffer _bb) { return GetRootAsStat(_bb, new Stat()); }
public static Stat GetRootAsStat(ByteBuffer _bb, Stat obj) { return (obj.__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb)); }
public Stat __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }

View File

@@ -7,7 +7,7 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class Stat extends Table {
public final class Stat extends Table {
public static Stat getRootAsStat(ByteBuffer _bb) { return getRootAsStat(_bb, new Stat()); }
public static Stat getRootAsStat(ByteBuffer _bb, Stat obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public Stat __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }

View File

@@ -5,7 +5,7 @@ namespace MyGame.Example
using FlatBuffers;
public class Test : Struct {
public sealed class Test : Struct {
public Test __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public short A() { return bb.GetShort(bb_pos + 0); }

View File

@@ -7,7 +7,7 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class Test extends Struct {
public final class Test extends Struct {
public Test __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public short a() { return bb.getShort(bb_pos + 0); }

View File

@@ -5,7 +5,7 @@ namespace MyGame.Example
using FlatBuffers;
public class Vec3 : Struct {
public sealed class Vec3 : Struct {
public Vec3 __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public float X() { return bb.GetFloat(bb_pos + 0); }

View File

@@ -7,7 +7,7 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class Vec3 extends Struct {
public final class Vec3 extends Struct {
public Vec3 __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public float x() { return bb.getFloat(bb_pos + 0); }