2424import uk .co .real_logic .sbe .ir .*;
2525
2626import java .io .IOException ;
27- import java .io .InputStream ;
28- import java .io .InputStreamReader ;
29- import java .io .Reader ;
3027import java .io .Writer ;
31- import java .nio .charset .StandardCharsets ;
3228import java .util .ArrayList ;
3329import java .util .List ;
3430import java .util .function .BiConsumer ;
@@ -45,30 +41,25 @@ public class JavaGenerator implements CodeGenerator
4541 private static final String INDENT = " " ;
4642 private static final String GEN_COMPOSITE_DECODER_FLYWEIGHT = "CompositeDecoderFlyweight" ;
4743 private static final String GEN_COMPOSITE_ENCODER_FLYWEIGHT = "CompositeEncoderFlyweight" ;
48- private static final String GEN_DECODER_FLYWEIGHT = "DecoderFlyweight" ;
49- private static final String GEN_ENCODER_FLYWEIGHT = "EncoderFlyweight" ;
50- private static final String GEN_FLYWEIGHT = "Flyweight" ;
5144 private static final String GEN_MESSAGE_DECODER_FLYWEIGHT = "MessageDecoderFlyweight" ;
5245 private static final String GEN_MESSAGE_ENCODER_FLYWEIGHT = "MessageEncoderFlyweight" ;
53- private static final String GEN_MESSAGE_FLYWEIGHT = "MessageFlyweight" ;
5446
5547 private final Ir ir ;
5648 private final OutputManager outputManager ;
57- private final OutputManager interfaceOutputManager ;
5849 private final String fqMutableBuffer ;
5950 private final String mutableBuffer ;
6051 private final String fqReadOnlyBuffer ;
6152 private final String readOnlyBuffer ;
6253 private final boolean shouldGenerateGroupOrderAnnotation ;
63- private final boolean generateInterfaces ;
54+ private final boolean shouldGenerateInterfaces ;
6455
6556 public JavaGenerator (
6657 final Ir ir ,
6758 final String mutableBuffer ,
6859 final String readOnlyBuffer ,
6960 final boolean shouldGenerateGroupOrderAnnotation ,
70- final OutputManager outputManager ,
71- final OutputManager interfaceOutputManager )
61+ final boolean shouldGenerateInterfaces ,
62+ final OutputManager outputManager )
7263 throws IOException
7364 {
7465 Verify .notNull (ir , "ir" );
@@ -84,8 +75,7 @@ public JavaGenerator(
8475 this .fqReadOnlyBuffer = readOnlyBuffer ;
8576
8677 this .shouldGenerateGroupOrderAnnotation = shouldGenerateGroupOrderAnnotation ;
87- this .generateInterfaces = interfaceOutputManager != null ;
88- this .interfaceOutputManager = interfaceOutputManager ;
78+ this .shouldGenerateInterfaces = shouldGenerateInterfaces ;
8979 }
9080
9181 private static String validateBufferImplementation (
@@ -121,41 +111,9 @@ private String decoderName(final String className)
121111 return className + "Decoder" ;
122112 }
123113
124- private void copyInterface ( String simpleInterfaceName ) throws IOException
114+ private String implementsInterface ( final String interfaceName )
125115 {
126- final String resource = String .format ("/java/interfaces/%s.java" , simpleInterfaceName );
127- final InputStream is = JavaGenerator .class .getResourceAsStream (resource );
128- Verify .notNull (is , resource );
129- final Reader reader = new InputStreamReader (is , StandardCharsets .UTF_8 );
130- try (final Writer out = interfaceOutputManager .createOutput (simpleInterfaceName ))
131- {
132- int bytes ;
133- final char [] buffer = new char [4096 ];
134- while (-1 != (bytes = reader .read (buffer )))
135- {
136- out .write (buffer , 0 , bytes );
137- }
138- }
139- }
140-
141- public void generateInterfaces () throws IOException
142- {
143- if (generateInterfaces )
144- {
145- copyInterface (GEN_COMPOSITE_DECODER_FLYWEIGHT );
146- copyInterface (GEN_COMPOSITE_ENCODER_FLYWEIGHT );
147- copyInterface (GEN_DECODER_FLYWEIGHT );
148- copyInterface (GEN_ENCODER_FLYWEIGHT );
149- copyInterface (GEN_FLYWEIGHT );
150- copyInterface (GEN_MESSAGE_DECODER_FLYWEIGHT );
151- copyInterface (GEN_MESSAGE_ENCODER_FLYWEIGHT );
152- copyInterface (GEN_MESSAGE_FLYWEIGHT );
153- }
154- }
155-
156- private String implementsInterface (final String tokenName , final String interfaceName )
157- {
158- if (!generateInterfaces )
116+ if (!shouldGenerateInterfaces )
159117 {
160118 return "" ;
161119 }
@@ -208,7 +166,6 @@ public void generateTypeStubs() throws IOException
208166
209167 public void generate () throws IOException
210168 {
211- generateInterfaces ();
212169 generateMessageHeaderStub ();
213170 generateTypeStubs ();
214171
@@ -240,7 +197,7 @@ private void generateEncoder(
240197 final Token msgToken ) throws IOException
241198 {
242199 final String className = formatClassName (encoderName (msgToken .name ()));
243- final String implementsString = implementsInterface (msgToken . name (), GEN_MESSAGE_ENCODER_FLYWEIGHT );
200+ final String implementsString = implementsInterface (GEN_MESSAGE_ENCODER_FLYWEIGHT );
244201
245202 try (final Writer out = outputManager .createOutput (className ))
246203 {
@@ -268,7 +225,7 @@ private void generateDecoder(
268225 final Token msgToken ) throws IOException
269226 {
270227 final String className = formatClassName (decoderName (msgToken .name ()));
271- final String implementsString = implementsInterface (msgToken . name (), GEN_MESSAGE_DECODER_FLYWEIGHT );
228+ final String implementsString = implementsInterface (GEN_MESSAGE_DECODER_FLYWEIGHT );
272229
273230 try (final Writer out = outputManager .createOutput (className ))
274231 {
@@ -1035,7 +992,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
1035992
1036993 try (final Writer out = outputManager .createOutput (decoderName ))
1037994 {
1038- final String implementsString = implementsInterface (token . name (), GEN_COMPOSITE_DECODER_FLYWEIGHT );
995+ final String implementsString = implementsInterface (GEN_COMPOSITE_DECODER_FLYWEIGHT );
1039996 generateFixedFlyweightHeader (token , decoderName , out , readOnlyBuffer , fqReadOnlyBuffer , implementsString );
1040997
1041998 for (int i = 1 , end = tokens .size () - 1 ; i < end ; i ++)
@@ -1070,7 +1027,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
10701027
10711028 try (final Writer out = outputManager .createOutput (encoderName ))
10721029 {
1073- final String implementsString = implementsInterface (token . name (), GEN_COMPOSITE_ENCODER_FLYWEIGHT );
1030+ final String implementsString = implementsInterface (GEN_COMPOSITE_ENCODER_FLYWEIGHT );
10741031 generateFixedFlyweightHeader (token , encoderName , out , mutableBuffer , fqMutableBuffer , implementsString );
10751032
10761033 for (int i = 1 , end = tokens .size () - 1 ; i < end ; i ++)
@@ -1253,9 +1210,9 @@ private CharSequence generateEnumLookupMethod(final List<Token> tokens, final St
12531210 return sb ;
12541211 }
12551212
1256- private CharSequence interfaceImportLine (final String packageName )
1213+ private CharSequence interfaceImportLine ()
12571214 {
1258- if (!generateInterfaces )
1215+ if (!shouldGenerateInterfaces )
12591216 {
12601217 return "\n " ;
12611218 }
@@ -1273,7 +1230,7 @@ private CharSequence generateFileHeader(final String className, final String pac
12731230 "@javax.annotation.Generated(value = {\" %s.%s\" })\n " ,
12741231 packageName ,
12751232 fqBuffer ,
1276- interfaceImportLine (packageName ),
1233+ interfaceImportLine (),
12771234 packageName ,
12781235 className
12791236 );
@@ -1291,7 +1248,7 @@ private CharSequence generateMainHeader(final String className, final String pac
12911248 "@javax.annotation.Generated(value = {\" %s.%s\" })\n " ,
12921249 packageName ,
12931250 fqMutableBuffer ,
1294- interfaceImportLine (packageName ),
1251+ interfaceImportLine (),
12951252 packageName ,
12961253 className
12971254 );
@@ -1308,7 +1265,7 @@ private CharSequence generateMainHeader(final String className, final String pac
13081265 packageName ,
13091266 fqMutableBuffer ,
13101267 fqReadOnlyBuffer ,
1311- interfaceImportLine (packageName ),
1268+ interfaceImportLine (),
13121269 packageName ,
13131270 className
13141271 );
0 commit comments