Skip to content

Commit c8cf74a

Browse files
committed
[Java] Fix up CSharp naming references and some warnings.
1 parent 25389b0 commit c8cf74a

File tree

7 files changed

+98
-110
lines changed

7 files changed

+98
-110
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Simple Binary Encoding (SBE)
33

44
[SBE](https://github.com/FIXTradingCommunity/fix-simple-binary-encoding) is an OSI layer 6 presentation for
55
encoding and decoding binary application messages for low-latency financial applications. This repository contains
6-
the reference implementations in Java, C++, Golang, and Csharp.
6+
the reference implementations in Java, C++, Golang, and C#.
77

88
Further details on the background and usage of SBE can be found on the
99
[Wiki](https://github.com/real-logic/simple-binary-encoding/wiki).
@@ -138,7 +138,7 @@ First build using Gradle to generate the SBE jar and then use it to
138138
generate the C# code used for testing and the examples.
139139

140140
$ ./gradlew
141-
$ ./gradlew generateCsharpCodecs
141+
$ ./gradlew generateCSharpCodecs
142142

143143
You can then use the [Visual Studio 2017 Community solution](https://github.com/real-logic/simple-binary-encoding/blob/master/csharp/csharp.sln) to build and explore the
144144
example. This solution also builds some tests which can be run via the provided

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ task generateGolangCodecs {
524524
'generateGolangCodecsWithXSD'
525525
}
526526

527-
task(generateCsharpCodecs, type:JavaExec) {
527+
task(generateCSharpCodecs, type:JavaExec) {
528528
main = 'uk.co.real_logic.sbe.SbeTool'
529529
classpath = project(':sbe-all').sourceSets.main.runtimeClasspath
530530
systemProperties(
531531
'sbe.output.dir': 'csharp/sbe-generated',
532-
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.Csharp',
532+
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharp',
533533
'sbe.validation.xsd': validationXsdPath)
534-
args = [
534+
args = [
535535
'sbe-tool/src/test/resources/FixBinary.xml',
536536
'sbe-tool/src/test/resources/issue435.xml',
537537
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',

csharp/.nuget/sbe-tool.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ if [ ! -f $SCHEMA ]; then echo no schema at $SCHEMA; exit 1; fi
3737
java \
3838
-Dsbe.output.dir=$OUTPUTDIR \
3939
-Dsbe.generate.ir="false" \
40-
-Dsbe.target.language="uk.co.real_logic.sbe.generation.csharp.Csharp" \
40+
-Dsbe.target.language="uk.co.real_logic.sbe.generation.csharp.CSharp" \
4141
-jar $SBE_JAR \
4242
$SCHEMA

csharp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The Java code that performs the generation of C# code is
1919
[here](https://github.com/real-logic/simple-binary-encoding/tree/master/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp).
2020

2121
$ ./gradlew # Will build sbe-tool jar
22-
$ ./gradlew generateCsharpCodecs # will generate the test, benchmark, and example C# code
22+
$ ./gradlew generateCSharpCodecs # will generate the test, benchmark, and example C# code
2323

2424
The [Visual Studio 2017 Community
2525
solution](https://github.com/real-logic/simple-binary-encoding/blob/master/csharp/csharp.sln) provides the projects:
@@ -46,7 +46,7 @@ Want to build things yourself?
4646

4747
For now you can:
4848
* build the SBE csharp generator using `gradlew`
49-
* generate the csharp codecs using `gradlew GenerateCsharpCodecs`
49+
* generate the csharp codecs using `gradlew GenerateCSharpCodecs`
5050
* Use the [Visual Studio 2017 Community solution](https://github.com/real-logic/simple-binary-encoding/blob/master/csharp/csharp.sln) to build the solution, run the unit tests, examples and benchmarks
5151
* Use the bash script [runtests.sh](https://github.com/real-logic/simple-binary-encoding/blob/master/csharp/runtests.sh) to run the tests
5252
* Build the nuget package via [do-release.sh](https://github.com/real-logic/simple-binary-encoding/blob/master/csharp/.nuget/do-release.sh) although this remains a largely manual process.

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/Csharp.java renamed to sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import java.io.IOException;
2323

24-
public class Csharp implements TargetCodeGenerator
24+
public class CSharp implements TargetCodeGenerator
2525
{
2626
public CodeGenerator newInstance(final Ir ir, final String outputDir) throws IOException
2727
{

sbe-tool/src/main/java/uk/co/real_logic/sbe/util/ValidationUtil.java

Lines changed: 86 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,27 @@ public class ValidationUtil
2727
{
2828
private static final Pattern PATTERN = Pattern.compile("\\.");
2929

30-
private static final Set<String> CPP_KEYWORDS = new HashSet<>(
31-
Arrays.asList(new String[]
32-
{
33-
"alignas", "and", "and_eq", "asm", "auto",
34-
"bitand", "bitor", "bool", "break", "case",
35-
"catch", "char", "class", "compl", "const",
36-
"const_cast", "continue", "char16_t", "char32_t", "default",
37-
"delete", "do", "double", "dynamic_cast", "else",
38-
"enum", "explicit", "export", "extern", "false",
39-
"float", "for", "friend", "goto", "if",
40-
"inline", "int", "long", "mutable", "namespace",
41-
"new", "not", "not_eq", "noexcept", "operator",
42-
"or", "or_eq", "private", "protected", "public",
43-
"register", "reinterpret_cast", "return", "short", "signed",
44-
"sizeof", "static", "static_cast", "struct", "switch",
45-
"template", "this", "throw", "true", "try",
46-
"typedef", "typeid", "typename", "union", "unsigned",
47-
"using", "virtual", "void", "volatile", "wchar_t",
48-
"while", "xor", "xor_eq", "override",
49-
// since C++11
50-
"alignof", "constexpr", "decltype", "nullptr", "static_assert", "thread_local",
51-
// since C++11 have special meaning, so avoid
52-
"final"
53-
}));
30+
private static final Set<String> CPP_KEYWORDS = new HashSet<>(Arrays.asList(
31+
"alignas", "and", "and_eq", "asm", "auto",
32+
"bitand", "bitor", "bool", "break", "case",
33+
"catch", "char", "class", "compl", "const",
34+
"const_cast", "continue", "char16_t", "char32_t", "default",
35+
"delete", "do", "double", "dynamic_cast", "else",
36+
"enum", "explicit", "export", "extern", "false",
37+
"float", "for", "friend", "goto", "if",
38+
"inline", "int", "long", "mutable", "namespace",
39+
"new", "not", "not_eq", "noexcept", "operator",
40+
"or", "or_eq", "private", "protected", "public",
41+
"register", "reinterpret_cast", "return", "short", "signed",
42+
"sizeof", "static", "static_cast", "struct", "switch",
43+
"template", "this", "throw", "true", "try",
44+
"typedef", "typeid", "typename", "union", "unsigned",
45+
"using", "virtual", "void", "volatile", "wchar_t",
46+
"while", "xor", "xor_eq", "override",
47+
// since C++11
48+
"alignof", "constexpr", "decltype", "nullptr", "static_assert", "thread_local",
49+
// since C++11 have special meaning, so avoid
50+
"final"));
5451

5552
/**
5653
* Check value for validity of usage as a C++ identifier. A programmatic variable
@@ -116,21 +113,18 @@ private static boolean isSbeCppIdentifierPart(final char c)
116113
return Character.isLetterOrDigit(c) || c == '_';
117114
}
118115

119-
private static final Set<String> JAVA_KEYWORDS = new HashSet<>(
120-
Arrays.asList(new String[]
121-
{
122-
"abstract", "assert", "boolean", "break", "byte",
123-
"case", "catch", "char", "class", "const",
124-
"continue", "default", "do", "double", "else",
125-
"enum", "extends", "final", "finally", "float",
126-
"for", "goto", "if", "implements", "import",
127-
"instanceof", "int", "interface", "long", "native",
128-
"new", "package", "private", "protected", "public",
129-
"return", "short", "static", "strictfp", "super",
130-
"switch", "synchronized", "this", "throw", "throws",
131-
"transient", "try", "void", "volatile", "while",
132-
"null", "true", "false", "_"
133-
}));
116+
private static final Set<String> JAVA_KEYWORDS = new HashSet<>(Arrays.asList(
117+
"abstract", "assert", "boolean", "break", "byte",
118+
"case", "catch", "char", "class", "const",
119+
"continue", "default", "do", "double", "else",
120+
"enum", "extends", "final", "finally", "float",
121+
"for", "goto", "if", "implements", "import",
122+
"instanceof", "int", "interface", "long", "native",
123+
"new", "package", "private", "protected", "public",
124+
"return", "short", "static", "strictfp", "super",
125+
"switch", "synchronized", "this", "throw", "throws",
126+
"transient", "try", "void", "volatile", "while",
127+
"null", "true", "false", "_"));
134128

135129
/**
136130
* Check string for validity of usage as a Java identifier. Avoiding keywords.
@@ -199,29 +193,26 @@ private static boolean isJavaIdentifier(final String token)
199193
return true;
200194
}
201195

202-
private static final Set<String> GOLANG_KEYWORDS = new HashSet<>(
203-
Arrays.asList(new String[]
204-
{
205-
/* https://golang.org/ref/spec#Keywords */
206-
"break", "default", "func", "interface", "select",
207-
"case", "defer", "go", "map", "struct",
208-
"chan", "else", "goto", "package", "switch",
209-
"const", "fallthrough", "if", "range", "type",
210-
"continue", "for", "import", "return", "var",
211-
212-
/* https://golang.org/ref/spec#Predeclared_identifiers */
213-
/* types */
214-
"bool", "byte", "complex64", "complex128", "error", "float32", "float64",
215-
"int", "int8", "int16", "int32", "int64", "rune", "string",
216-
"uint", "uint8", "uint16", "uint32", "uint64", "uintptr",
217-
/* constants */
218-
"true", "false", "iota",
219-
/* zero value */
220-
"nil",
221-
/* functions */
222-
"append", "cap", "close", "complex", "copy", "delete", "imag", "len",
223-
"make", "new", "panic", "print", "println", "real", "recover"
224-
}));
196+
/* https://golang.org/ref/spec#Keywords */
197+
private static final Set<String> GOLANG_KEYWORDS = new HashSet<>(Arrays.asList(
198+
"break", "default", "func", "interface", "select",
199+
"case", "defer", "go", "map", "struct",
200+
"chan", "else", "goto", "package", "switch",
201+
"const", "fallthrough", "if", "range", "type",
202+
"continue", "for", "import", "return", "var",
203+
204+
/* https://golang.org/ref/spec#Predeclared_identifiers */
205+
/* types */
206+
"bool", "byte", "complex64", "complex128", "error", "float32", "float64",
207+
"int", "int8", "int16", "int32", "int64", "rune", "string",
208+
"uint", "uint8", "uint16", "uint32", "uint64", "uintptr",
209+
/* constants */
210+
"true", "false", "iota",
211+
/* zero value */
212+
"nil",
213+
/* functions */
214+
"append", "cap", "close", "complex", "copy", "delete", "imag", "len",
215+
"make", "new", "panic", "print", "println", "real", "recover"));
225216

226217
/**
227218
* "Check" value for validity of usage as a golang identifier. From:
@@ -291,36 +282,33 @@ private static boolean isSbeGolangIdentifierPart(final char c)
291282
return Character.isLetterOrDigit(c) || c == '_';
292283
}
293284

294-
private static final Set<String> CSHARP_KEYWORDS = new HashSet<>(
295-
Arrays.asList(new String[]
296-
{
297-
/**
298-
* https://docs.microsoft.com/en-gb/dotnet/articles/csharp/language-reference/keywords/index
299-
* Note this does not include the contextual keywords
300-
* Note "virtual" is no longer but was in early versions of C#
301-
*/
302-
"abstract", "as", "base", "bool", "break",
303-
"byte", "case", "catch", "char", "checked",
304-
"class", "const", "continue", "decimal", "default",
305-
"delegate", "do", "double", "else", "enum",
306-
"event", "explicit", "extern", "false", "finally",
307-
"fixed", "float", "for", "foreach", "goto",
308-
"if", "implicit", "in", "int", "interface",
309-
"internal", "is", "lock", "long", "namespace",
310-
"new", "null", "object", "operator", "out",
311-
"override", "params", "private", "protected", "public",
312-
"readonly", "ref", "return", "sbyte", "sealed",
313-
"short", "sizeof", "stackalloc", "static", "string",
314-
"struct", "switch", "this", "throw", "true",
315-
"try", "typeof", "uint", "ulong", "unchecked",
316-
"unsafe", "ushort", "using", "using static", "virtual",
317-
"void", "volatile", "while"
318-
}));
285+
/**
286+
* https://docs.microsoft.com/en-gb/dotnet/articles/csharp/language-reference/keywords/index
287+
* Note this does not include the contextual keywords
288+
* Note "virtual" is no longer but was in early versions of C#
289+
*/
290+
private static final Set<String> CSHARP_KEYWORDS = new HashSet<>(Arrays.asList(
291+
"abstract", "as", "base", "bool", "break",
292+
"byte", "case", "catch", "char", "checked",
293+
"class", "const", "continue", "decimal", "default",
294+
"delegate", "do", "double", "else", "enum",
295+
"event", "explicit", "extern", "false", "finally",
296+
"fixed", "float", "for", "foreach", "goto",
297+
"if", "implicit", "in", "int", "interface",
298+
"internal", "is", "lock", "long", "namespace",
299+
"new", "null", "object", "operator", "out",
300+
"override", "params", "private", "protected", "public",
301+
"readonly", "ref", "return", "sbyte", "sealed",
302+
"short", "sizeof", "stackalloc", "static", "string",
303+
"struct", "switch", "this", "throw", "true",
304+
"try", "typeof", "uint", "ulong", "unchecked",
305+
"unsafe", "ushort", "using", "using static", "virtual",
306+
"void", "volatile", "while"));
319307

320308
/**
321309
* "Check" value for validity of usage as a csharp identifier.
322310
* https://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx
323-
( Which basically boils down to
311+
* ( Which basically boils down to
324312
*
325313
* first subsequent*
326314
* first is { @ | letter | underscore }
@@ -338,11 +326,11 @@ private static boolean isSbeGolangIdentifierPart(final char c)
338326
* @param value to check
339327
* @return true for validity as a csharp name. false if not.
340328
*/
341-
public static boolean isSbeCsharpName(final String value)
329+
public static boolean isSbeCSharpName(final String value)
342330
{
343-
if (possibleCsharpKeyword(value))
331+
if (possibleCSharpKeyword(value))
344332
{
345-
if (isCsharpKeyword(value))
333+
if (isCSharpKeyword(value))
346334
{
347335
return false;
348336
}
@@ -355,23 +343,23 @@ public static boolean isSbeCsharpName(final String value)
355343
return true;
356344
}
357345

358-
public static boolean isCsharpKeyword(final String token)
346+
public static boolean isCSharpKeyword(final String token)
359347
{
360348
return CSHARP_KEYWORDS.contains(token);
361349
}
362350

363-
private static boolean possibleCsharpKeyword(final String value)
351+
private static boolean possibleCSharpKeyword(final String value)
364352
{
365353
for (int i = 0, size = value.length(); i < size; i++)
366354
{
367355
final char c = value.charAt(i);
368356

369-
if (i == 0 && isSbeCsharpIdentifierStart(c))
357+
if (i == 0 && isSbeCSharpIdentifierStart(c))
370358
{
371359
continue;
372360
}
373361

374-
if (isSbeCsharpIdentifierPart(c))
362+
if (isSbeCSharpIdentifierPart(c))
375363
{
376364
continue;
377365
}
@@ -382,14 +370,14 @@ private static boolean possibleCsharpKeyword(final String value)
382370
return true;
383371
}
384372

385-
private static boolean isSbeCsharpIdentifierStart(final char c)
373+
private static boolean isSbeCSharpIdentifierStart(final char c)
386374
{
387375
return Character.isLetter(c) || c == '_' || c == '@';
388376
}
389377

390-
private static boolean isSbeCsharpIdentifierPart(final char c)
378+
private static boolean isSbeCSharpIdentifierPart(final char c)
391379
{
392-
if (isSbeCsharpIdentifierStart(c))
380+
if (isSbeCSharpIdentifierStart(c))
393381
{
394382
return true;
395383
}
@@ -406,5 +394,4 @@ private static boolean isSbeCsharpIdentifierPart(final char c)
406394
return false;
407395
}
408396
}
409-
410397
}

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,10 @@ public static void checkForValidName(final Node node, final String name)
315315
{
316316
handleWarning(node, "name is not valid for Golang: " + name);
317317
}
318-
if (!ValidationUtil.isSbeCsharpName(name))
318+
319+
if (!ValidationUtil.isSbeCSharpName(name))
319320
{
320-
handleWarning(node, "name is not valid for Csharp: " + name);
321+
handleWarning(node, "name is not valid for C#: " + name);
321322
}
322323
}
323324

0 commit comments

Comments
 (0)