@@ -70,8 +70,8 @@ enum CodecType
70
70
private final boolean shouldGenerateGroupOrderAnnotation ;
71
71
private final boolean shouldGenerateInterfaces ;
72
72
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 <>();
75
75
76
76
/**
77
77
* Create a new Java language {@link CodeGenerator}. Generator support for types in their own package is disabled.
@@ -106,7 +106,7 @@ public JavaGenerator(
106
106
* @param shouldGenerateGroupOrderAnnotation in the codecs.
107
107
* @param shouldGenerateInterfaces for common methods.
108
108
* @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.
110
110
* @param outputManager for generating the codecs to.
111
111
*/
112
112
public JavaGenerator (
@@ -116,14 +116,14 @@ public JavaGenerator(
116
116
final boolean shouldGenerateGroupOrderAnnotation ,
117
117
final boolean shouldGenerateInterfaces ,
118
118
final boolean shouldDecodeUnknownEnumValues ,
119
- final boolean shouldSupportTypePackages ,
119
+ final boolean shouldSupportTypesPackageNames ,
120
120
final DynamicPackageOutputManager outputManager )
121
121
{
122
122
Verify .notNull (ir , "ir" );
123
123
Verify .notNull (outputManager , "outputManager" );
124
124
125
125
this .ir = ir ;
126
- this .shouldSupportTypePackages = shouldSupportTypePackages ;
126
+ this .shouldSupportTypesPackageNames = shouldSupportTypesPackageNames ;
127
127
this .outputManager = outputManager ;
128
128
129
129
this .mutableBuffer = validateBufferImplementation (mutableBuffer , MutableDirectBuffer .class );
@@ -176,18 +176,19 @@ public void generateTypeStubs() throws IOException
176
176
}
177
177
178
178
/**
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.
180
180
*
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()}.
184
184
*/
185
- private String registerTypePackage (final Token token , final Ir ir )
185
+ private String registerTypesPackageName (final Token token , final Ir ir )
186
186
{
187
- if (shouldSupportTypePackages && token .packageName () != null )
187
+ if (shouldSupportTypesPackageNames && token .packageName () != null )
188
188
{
189
- typePackages .add (token .packageName ());
189
+ packageNameByTypes .add (token .packageName ());
190
190
outputManager .setPackageName (token .packageName ());
191
+
191
192
return token .packageName ();
192
193
}
193
194
return ir .applicableNamespace ();
@@ -198,7 +199,7 @@ private String registerTypePackage(final Token token, final Ir ir)
198
199
*/
199
200
public void generate () throws IOException
200
201
{
201
- typePackages .clear ();
202
+ packageNameByTypes .clear ();
202
203
generatePackageInfo ();
203
204
generateTypeStubs ();
204
205
generateMessageHeaderStub ();
@@ -1238,7 +1239,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException
1238
1239
final List <Token > choiceList = tokens .subList (1 , tokens .size () - 1 );
1239
1240
final String implementsString = implementsInterface (Flyweight .class .getSimpleName ());
1240
1241
1241
- registerTypePackage (token , ir );
1242
+ registerTypesPackageName (token , ir );
1242
1243
try (Writer out = outputManager .createOutput (decoderName ))
1243
1244
{
1244
1245
final Encoding encoding = token .encoding ();
@@ -1259,7 +1260,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException
1259
1260
out .append ("}\n " );
1260
1261
}
1261
1262
1262
- registerTypePackage (token , ir );
1263
+ registerTypesPackageName (token , ir );
1263
1264
try (Writer out = outputManager .createOutput (encoderName ))
1264
1265
{
1265
1266
generateFixedFlyweightHeader (out , token , encoderName , implementsString , mutableBuffer , fqMutableBuffer );
@@ -1277,7 +1278,7 @@ private void generateFixedFlyweightHeader(
1277
1278
final String buffer ,
1278
1279
final String fqBuffer ) throws IOException
1279
1280
{
1280
- final String packageName = registerTypePackage (token , ir );
1281
+ final String packageName = registerTypesPackageName (token , ir );
1281
1282
out .append (generateFileHeader (packageName , fqBuffer ));
1282
1283
out .append (generateDeclaration (typeName , implementsString , token ));
1283
1284
out .append (generateFixedFlyweightCode (typeName , token .encodedLength (), buffer ));
@@ -1291,7 +1292,7 @@ private void generateCompositeFlyweightHeader(
1291
1292
final String fqBuffer ,
1292
1293
final String implementsString ) throws IOException
1293
1294
{
1294
- final String packageName = registerTypePackage (token , ir );
1295
+ final String packageName = registerTypesPackageName (token , ir );
1295
1296
out .append (generateFileHeader (packageName , fqBuffer ));
1296
1297
out .append (generateDeclaration (typeName , implementsString , token ));
1297
1298
out .append (generateFixedFlyweightCode (typeName , token .encodedLength (), buffer ));
@@ -1304,7 +1305,7 @@ private void generateEnum(final List<Token> tokens) throws IOException
1304
1305
final Encoding encoding = enumToken .encoding ();
1305
1306
final String nullVal = encoding .applicableNullValue ().toString ();
1306
1307
1307
- final String packageName = registerTypePackage (enumToken , ir );
1308
+ final String packageName = registerTypesPackageName (enumToken , ir );
1308
1309
try (Writer out = outputManager .createOutput (enumName ))
1309
1310
{
1310
1311
out .append (generateEnumFileHeader (packageName ));
@@ -1327,7 +1328,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
1327
1328
final String decoderName = decoderName (compositeName );
1328
1329
final String encoderName = encoderName (compositeName );
1329
1330
1330
- registerTypePackage (token , ir );
1331
+ registerTypesPackageName (token , ir );
1331
1332
try (Writer out = outputManager .createOutput (decoderName ))
1332
1333
{
1333
1334
final String implementsString = implementsInterface (CompositeDecoderFlyweight .class .getSimpleName ());
@@ -1376,7 +1377,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
1376
1377
out .append ("}\n " );
1377
1378
}
1378
1379
1379
- registerTypePackage (token , ir );
1380
+ registerTypesPackageName (token , ir );
1380
1381
try (Writer out = outputManager .createOutput (encoderName ))
1381
1382
{
1382
1383
final String implementsString = implementsInterface (CompositeEncoderFlyweight .class .getSimpleName ());
@@ -1629,8 +1630,8 @@ private CharSequence generateFileHeader(final String packageName, final String f
1629
1630
private CharSequence generateMainHeader (
1630
1631
final String packageName , final CodecType codecType , final boolean hasVarData )
1631
1632
{
1632
- final StringBuffer packageImports = new StringBuffer ();
1633
- for (final String typePackage : typePackages )
1633
+ final StringBuilder packageImports = new StringBuilder ();
1634
+ for (final String typePackage : packageNameByTypes )
1634
1635
{
1635
1636
packageImports .append ("import " );
1636
1637
packageImports .append (typePackage );
@@ -1644,7 +1645,7 @@ private CharSequence generateMainHeader(
1644
1645
"package " + packageName + ";\n \n " +
1645
1646
"import " + fqMutableBuffer + ";\n " +
1646
1647
interfaceImportLine () +
1647
- packageImports . toString () ;
1648
+ packageImports ;
1648
1649
}
1649
1650
else
1650
1651
{
@@ -1657,7 +1658,7 @@ private CharSequence generateMainHeader(
1657
1658
(hasMutableBuffer ? "import " + fqMutableBuffer + ";\n " : "" ) +
1658
1659
(hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n " : "" ) +
1659
1660
interfaceImportLine () +
1660
- packageImports . toString () ;
1661
+ packageImports ;
1661
1662
}
1662
1663
}
1663
1664
0 commit comments