Skip to content

Commit 2131ff0

Browse files
committed
[Java] Make CodeGenerator a FunctionalInterface.
1 parent 4509fdc commit 2131ff0

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,13 @@
2020
/**
2121
* Abstraction for code generators to implement.
2222
*/
23+
@FunctionalInterface
2324
public interface CodeGenerator
2425
{
25-
/**
26-
* Class name to be used for visitor pattern that accesses the message headerStructure.
27-
*/
28-
String MESSAGE_HEADER_ENCODER_TYPE = "MessageHeaderEncoder";
29-
30-
String MESSAGE_HEADER_DECODER_TYPE = "MessageHeaderDecoder";
31-
3226
/**
3327
* Generate the complete set of types and messages for a schema.
3428
*
3529
* @throws IOException if an error is encountered when writing the output.
3630
*/
3731
void generate() throws IOException;
38-
39-
/**
40-
* Generate the composites for dealing with the message header.
41-
*
42-
* @throws IOException if an error is encountered when writing the output.
43-
*/
44-
void generateMessageHeaderStub() throws IOException;
4532
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public CGenerator(final Ir ir, final OutputManager outputManager)
6161
}
6262

6363
/**
64-
* {@inheritDoc}
64+
* Generate the composites for dealing with the message header.
65+
*
66+
* @throws IOException if an error is encountered when writing the output.
6567
*/
6668
public void generateMessageHeaderStub() throws IOException
6769
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public CppGenerator(final Ir ir, final boolean shouldDecodeUnknownEnumValues, fi
7070
}
7171

7272
/**
73-
* {@inheritDoc}
73+
* Generate the composites for dealing with the message header.
74+
*
75+
* @throws IOException if an error is encountered when writing the output.
7476
*/
7577
public void generateMessageHeaderStub() throws IOException
7678
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public CSharpGenerator(final Ir ir, final OutputManager outputManager)
6666
}
6767

6868
/**
69-
* {@inheritDoc}
69+
* Generate the composites for dealing with the message header.
70+
*
71+
* @throws IOException if an error is encountered when writing the output.
7072
*/
7173
public void generateMessageHeaderStub() throws IOException
7274
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ public void generateTypeStubs() throws IOException
112112

113113
// MessageHeader is special but the standard allows it to be
114114
// pretty arbitrary after the first four fields.
115-
// All we need is the imports, type declaration, and encode/decode
115+
// All we need is the imports, type declaration, and encode/decode.
116116
/**
117-
* {@inheritDoc}
117+
* Generate the composites for dealing with the message header.
118+
*
119+
* @throws IOException if an error is encountered when writing the output.
118120
*/
119121
public void generateMessageHeaderStub() throws IOException
120122
{

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
@SuppressWarnings("MethodLength")
4343
public class JavaGenerator implements CodeGenerator
4444
{
45+
static final String MESSAGE_HEADER_ENCODER_TYPE = "MessageHeaderEncoder";
46+
static final String MESSAGE_HEADER_DECODER_TYPE = "MessageHeaderDecoder";
47+
4548
enum CodecType
4649
{
4750
DECODER,
@@ -101,7 +104,9 @@ public JavaGenerator(
101104
}
102105

103106
/**
104-
* {@inheritDoc}
107+
* Generate the composites for dealing with the message header.
108+
*
109+
* @throws IOException if an error is encountered when writing the output.
105110
*/
106111
public void generateMessageHeaderStub() throws IOException
107112
{

sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import static org.hamcrest.Matchers.*;
3939
import static org.junit.jupiter.api.Assertions.*;
4040
import static org.mockito.Mockito.*;
41-
import static uk.co.real_logic.sbe.generation.CodeGenerator.MESSAGE_HEADER_DECODER_TYPE;
42-
import static uk.co.real_logic.sbe.generation.java.JavaGenerator.MESSAGE_HEADER_ENCODER_TYPE;
41+
import static uk.co.real_logic.sbe.generation.java.JavaGenerator.MESSAGE_HEADER_DECODER_TYPE;
4342
import static uk.co.real_logic.sbe.generation.java.ReflectionUtil.*;
4443
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.parse;
4544

@@ -75,7 +74,7 @@ public void shouldGenerateMessageHeaderStub() throws Exception
7574
final int templateIdOffset = 2;
7675
final short templateId = (short)7;
7776
final int blockLength = 32;
78-
final String fqClassName = ir.applicableNamespace() + "." + MESSAGE_HEADER_ENCODER_TYPE;
77+
final String fqClassName = ir.applicableNamespace() + "." + JavaGenerator.MESSAGE_HEADER_ENCODER_TYPE;
7978

8079
when(mockBuffer.getShort(bufferOffset + templateIdOffset, BYTE_ORDER)).thenReturn(templateId);
8180

0 commit comments

Comments
 (0)