Skip to content

Commit a52aef5

Browse files
committed
[Java] Clean up after merge of PR #904.
1 parent 742cd8a commit a52aef5

File tree

9 files changed

+97
-93
lines changed

9 files changed

+97
-93
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
* <li><b>sbe.keyword.append.token</b>: Token to be appended to keywords.</li>
6969
* <li><b>sbe.decode.unknown.enum.values</b>: Support unknown decoded enum values. Defaults to false.</li>
7070
* <li><b>sbe.xinclude.aware</b>: Is XInclude supported for the schema. Defaults to false.</li>
71-
* <li><b>sbe.type.package.override</b>: Is a package attribute for types element supported (only for JAVA). Defaults to
71+
* <li><b>sbe.type.package.override</b>: Is package attribute for types element supported (only for JAVA). Defaults to
7272
* false.</li>
7373
* </ul>
7474
*/
@@ -121,9 +121,9 @@ public class SbeTool
121121

122122
/**
123123
* Boolean system property to control the support of package names in {@code <types>} elements.
124-
* Part of SBE v2-rc2. Defaults to false.
124+
* Part of SBE v2-rc3. Defaults to false.
125125
*/
126-
public static final String TYPE_PACKAGE_OVERRIDE = "sbe.type.package.override";
126+
public static final String TYPES_PACKAGE_OVERRIDE = "sbe.types.package.override";
127127

128128
/**
129129
* Target language for generated code.

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir)
5252
"true".equals(System.getProperty(JAVA_GROUP_ORDER_ANNOTATION)),
5353
"true".equals(System.getProperty(JAVA_GENERATE_INTERFACES)),
5454
"true".equals(System.getProperty(DECODE_UNKNOWN_ENUM_VALUES)),
55-
"true".equals(System.getProperty(TYPE_PACKAGE_OVERRIDE)),
55+
"true".equals(System.getProperty(TYPES_PACKAGE_OVERRIDE)),
5656
new JavaOutputManager(outputDir, ir.applicableNamespace()));
5757
}
5858
},

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ enum CodecType
7070
private final boolean shouldGenerateGroupOrderAnnotation;
7171
private final boolean shouldGenerateInterfaces;
7272
private final boolean shouldDecodeUnknownEnumValues;
73-
private final boolean shouldSupportTypePackages;
74-
private final Set<String> typePackages = new HashSet<>();
73+
private final boolean shouldSupportTypesPackageNames;
74+
private final Set<String> packageNameByTypes = new HashSet<>();
7575

7676
/**
7777
* Create a new Java language {@link CodeGenerator}. Generator support for types in their own package is disabled.
@@ -106,7 +106,7 @@ public JavaGenerator(
106106
* @param shouldGenerateGroupOrderAnnotation in the codecs.
107107
* @param shouldGenerateInterfaces for common methods.
108108
* @param shouldDecodeUnknownEnumValues generate support for unknown enum values when decoding.
109-
* @param shouldSupportTypePackages generator support for types in their own package
109+
* @param shouldSupportTypesPackageNames generator support for types in their own package.
110110
* @param outputManager for generating the codecs to.
111111
*/
112112
public JavaGenerator(
@@ -116,14 +116,14 @@ public JavaGenerator(
116116
final boolean shouldGenerateGroupOrderAnnotation,
117117
final boolean shouldGenerateInterfaces,
118118
final boolean shouldDecodeUnknownEnumValues,
119-
final boolean shouldSupportTypePackages,
119+
final boolean shouldSupportTypesPackageNames,
120120
final DynamicPackageOutputManager outputManager)
121121
{
122122
Verify.notNull(ir, "ir");
123123
Verify.notNull(outputManager, "outputManager");
124124

125125
this.ir = ir;
126-
this.shouldSupportTypePackages = shouldSupportTypePackages;
126+
this.shouldSupportTypesPackageNames = shouldSupportTypesPackageNames;
127127
this.outputManager = outputManager;
128128

129129
this.mutableBuffer = validateBufferImplementation(mutableBuffer, MutableDirectBuffer.class);
@@ -176,18 +176,19 @@ public void generateTypeStubs() throws IOException
176176
}
177177

178178
/**
179-
* Register the the type's explicit package - if it's set and should be supported.
179+
* Register the types explicit package - if it's set and should be supported.
180180
*
181-
* @param token the 0-th token of the type
182-
* @param ir the intermediate representation
183-
* @return the overriden package name of the type if set and supported, or {@link Ir#applicableNamespace() }
181+
* @param token the 0-th token of the type.
182+
* @param ir the intermediate representation.
183+
* @return the overridden package name of the type if set and supported, or {@link Ir#applicableNamespace()}.
184184
*/
185-
private String registerTypePackage(final Token token, final Ir ir)
185+
private String registerTypesPackageName(final Token token, final Ir ir)
186186
{
187-
if (shouldSupportTypePackages && token.packageName() != null)
187+
if (shouldSupportTypesPackageNames && token.packageName() != null)
188188
{
189-
typePackages.add(token.packageName());
189+
packageNameByTypes.add(token.packageName());
190190
outputManager.setPackageName(token.packageName());
191+
191192
return token.packageName();
192193
}
193194
return ir.applicableNamespace();
@@ -198,7 +199,7 @@ private String registerTypePackage(final Token token, final Ir ir)
198199
*/
199200
public void generate() throws IOException
200201
{
201-
typePackages.clear();
202+
packageNameByTypes.clear();
202203
generatePackageInfo();
203204
generateTypeStubs();
204205
generateMessageHeaderStub();
@@ -1238,7 +1239,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException
12381239
final List<Token> choiceList = tokens.subList(1, tokens.size() - 1);
12391240
final String implementsString = implementsInterface(Flyweight.class.getSimpleName());
12401241

1241-
registerTypePackage(token, ir);
1242+
registerTypesPackageName(token, ir);
12421243
try (Writer out = outputManager.createOutput(decoderName))
12431244
{
12441245
final Encoding encoding = token.encoding();
@@ -1259,7 +1260,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException
12591260
out.append("}\n");
12601261
}
12611262

1262-
registerTypePackage(token, ir);
1263+
registerTypesPackageName(token, ir);
12631264
try (Writer out = outputManager.createOutput(encoderName))
12641265
{
12651266
generateFixedFlyweightHeader(out, token, encoderName, implementsString, mutableBuffer, fqMutableBuffer);
@@ -1277,7 +1278,7 @@ private void generateFixedFlyweightHeader(
12771278
final String buffer,
12781279
final String fqBuffer) throws IOException
12791280
{
1280-
final String packageName = registerTypePackage(token, ir);
1281+
final String packageName = registerTypesPackageName(token, ir);
12811282
out.append(generateFileHeader(packageName, fqBuffer));
12821283
out.append(generateDeclaration(typeName, implementsString, token));
12831284
out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer));
@@ -1291,7 +1292,7 @@ private void generateCompositeFlyweightHeader(
12911292
final String fqBuffer,
12921293
final String implementsString) throws IOException
12931294
{
1294-
final String packageName = registerTypePackage(token, ir);
1295+
final String packageName = registerTypesPackageName(token, ir);
12951296
out.append(generateFileHeader(packageName, fqBuffer));
12961297
out.append(generateDeclaration(typeName, implementsString, token));
12971298
out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer));
@@ -1304,7 +1305,7 @@ private void generateEnum(final List<Token> tokens) throws IOException
13041305
final Encoding encoding = enumToken.encoding();
13051306
final String nullVal = encoding.applicableNullValue().toString();
13061307

1307-
final String packageName = registerTypePackage(enumToken, ir);
1308+
final String packageName = registerTypesPackageName(enumToken, ir);
13081309
try (Writer out = outputManager.createOutput(enumName))
13091310
{
13101311
out.append(generateEnumFileHeader(packageName));
@@ -1327,7 +1328,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
13271328
final String decoderName = decoderName(compositeName);
13281329
final String encoderName = encoderName(compositeName);
13291330

1330-
registerTypePackage(token, ir);
1331+
registerTypesPackageName(token, ir);
13311332
try (Writer out = outputManager.createOutput(decoderName))
13321333
{
13331334
final String implementsString = implementsInterface(CompositeDecoderFlyweight.class.getSimpleName());
@@ -1376,7 +1377,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
13761377
out.append("}\n");
13771378
}
13781379

1379-
registerTypePackage(token, ir);
1380+
registerTypesPackageName(token, ir);
13801381
try (Writer out = outputManager.createOutput(encoderName))
13811382
{
13821383
final String implementsString = implementsInterface(CompositeEncoderFlyweight.class.getSimpleName());
@@ -1629,8 +1630,8 @@ private CharSequence generateFileHeader(final String packageName, final String f
16291630
private CharSequence generateMainHeader(
16301631
final String packageName, final CodecType codecType, final boolean hasVarData)
16311632
{
1632-
final StringBuffer packageImports = new StringBuffer();
1633-
for (final String typePackage : typePackages)
1633+
final StringBuilder packageImports = new StringBuilder();
1634+
for (final String typePackage : packageNameByTypes)
16341635
{
16351636
packageImports.append("import ");
16361637
packageImports.append(typePackage);
@@ -1644,7 +1645,7 @@ private CharSequence generateMainHeader(
16441645
"package " + packageName + ";\n\n" +
16451646
"import " + fqMutableBuffer + ";\n" +
16461647
interfaceImportLine() +
1647-
packageImports.toString();
1648+
packageImports;
16481649
}
16491650
else
16501651
{
@@ -1657,7 +1658,7 @@ private CharSequence generateMainHeader(
16571658
(hasMutableBuffer ? "import " + fqMutableBuffer + ";\n" : "") +
16581659
(hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n" : "") +
16591660
interfaceImportLine() +
1660-
packageImports.toString();
1661+
packageImports;
16611662
}
16621663
}
16631664

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@
1515
*/
1616
package uk.co.real_logic.sbe.generation.java;
1717

18-
import java.io.FilterWriter;
19-
import java.io.IOException;
20-
import java.io.Writer;
2118
import org.agrona.collections.Object2NullableObjectHashMap;
2219
import org.agrona.collections.Object2ObjectHashMap;
2320
import org.agrona.generation.DynamicPackageOutputManager;
2421
import org.agrona.generation.PackageOutputManager;
2522

23+
import java.io.FilterWriter;
24+
import java.io.IOException;
25+
import java.io.Writer;
26+
2627
/**
2728
* Implementation of {@link DynamicPackageOutputManager} for Java.
2829
*/
2930
public class JavaOutputManager implements DynamicPackageOutputManager
3031
{
3132
private final String baseDirName;
32-
private final PackageOutputManager basePackageOutputManager;
33+
private final PackageOutputManager initialPackageOutputManager;
3334
private PackageOutputManager actingPackageOutputManager;
34-
private final Object2ObjectHashMap<String, PackageOutputManager> outputManagerCache
35+
private final Object2ObjectHashMap<String, PackageOutputManager> outputManagerByPackageName
3536
= new Object2NullableObjectHashMap<>();
3637

3738
/**
3839
* Constructor.
40+
*
3941
* @param baseDirName the target directory
4042
* @param packageName the initial package name
4143
*/
4244
public JavaOutputManager(final String baseDirName, final String packageName)
4345
{
44-
basePackageOutputManager = new PackageOutputManager(baseDirName, packageName);
45-
actingPackageOutputManager = basePackageOutputManager;
46+
initialPackageOutputManager = new PackageOutputManager(baseDirName, packageName);
47+
actingPackageOutputManager = initialPackageOutputManager;
4648
this.baseDirName = baseDirName;
4749
}
4850

@@ -51,17 +53,17 @@ public JavaOutputManager(final String baseDirName, final String packageName)
5153
*/
5254
public void setPackageName(final String packageName)
5355
{
54-
actingPackageOutputManager = outputManagerCache.get(packageName);
56+
actingPackageOutputManager = outputManagerByPackageName.get(packageName);
5557
if (actingPackageOutputManager == null)
5658
{
5759
actingPackageOutputManager = new PackageOutputManager(baseDirName, packageName);
58-
outputManagerCache.put(packageName, actingPackageOutputManager);
60+
outputManagerByPackageName.put(packageName, actingPackageOutputManager);
5961
}
6062
}
6163

6264
private void resetPackage()
6365
{
64-
actingPackageOutputManager = basePackageOutputManager;
66+
actingPackageOutputManager = initialPackageOutputManager;
6567
}
6668

6769
/**

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public static class Builder
377377
{
378378
private Signal signal;
379379
private String name;
380-
private String packageName = null;
380+
private String packageName;
381381
private String referencedName;
382382
private String description;
383383
private int id = INVALID_ID;
@@ -413,7 +413,7 @@ public Builder name(final String name)
413413
}
414414

415415
/**
416-
* Package name for the Token. Default is null. Use for BEGIN_MESSAGE tokens for types that require an explicit
416+
* Package name for the Token, default is null. Use for BEGIN_MESSAGE tokens for types that require an explicit
417417
* package.
418418
*
419419
* @param packageName for the Token.

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public EncodedDataType(final Node node)
6565
/**
6666
* Construct a new encodedDataType from XML Schema.
6767
*
68-
* @param node from the XML Schema Parsing
68+
* @param node from the XML Schema Parsing.
6969
* @param givenName for this node.
7070
* @param referencedName of the type when created from a ref in a composite.
7171
*/
@@ -201,13 +201,13 @@ private PrimitiveValue lookupValueRef(final Node node)
201201
/**
202202
* Construct a new EncodedDataType with direct values. Does not handle constant values.
203203
*
204-
* @param name of the type
205-
* @param presence of the type
206-
* @param description of the type or null
207-
* @param semanticType of the type or null
208-
* @param primitiveType of the EncodedDataType
209-
* @param length of the EncodedDataType
210-
* @param varLen of the EncodedDataType
204+
* @param name of the type.
205+
* @param presence of the type.
206+
* @param description of the type or null.
207+
* @param semanticType of the type or null.
208+
* @param primitiveType of the EncodedDataType.
209+
* @param length of the EncodedDataType.
210+
* @param varLen of the EncodedDataType.
211211
*/
212212
public EncodedDataType(
213213
final String name,
@@ -222,16 +222,16 @@ public EncodedDataType(
222222
}
223223

224224
/**
225-
* Construct a new EncodedDataType with direct values.Does not handle constant values.
225+
* Construct a new EncodedDataType with direct values. Does not handle constant values.
226226
*
227-
* @param name of the type
228-
* @param packageName of the type
229-
* @param presence of the type
230-
* @param description of the type or null
231-
* @param semanticType of the type or null
232-
* @param primitiveType of the EncodedDataType
233-
* @param length of the EncodedDataType
234-
* @param varLen of the EncodedDataType
227+
* @param name of the type.
228+
* @param packageName of the type.
229+
* @param presence of the type.
230+
* @param description of the type or null.
231+
* @param semanticType of the type or null.
232+
* @param primitiveType of the EncodedDataType.
233+
* @param length of the EncodedDataType.
234+
* @param varLen of the EncodedDataType.
235235
*/
236236
public EncodedDataType(
237237
final String name,

0 commit comments

Comments
 (0)