Skip to content

Commit 23a995c

Browse files
committed
[Java] Code tidy up after merge.
1 parent 88451e7 commit 23a995c

File tree

13 files changed

+196
-26
lines changed

13 files changed

+196
-26
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public class SbeTool
125125
* Package in which the generated Java interfaces will be placed.
126126
*/
127127
public static final String JAVA_INTERFACE_PACKAGE = "org.agrona.sbe";
128+
128129
/**
129130
* Default class to use as the buffer mutable implementation in generated code.
130131
*/
@@ -153,7 +154,7 @@ public static void main(final String[] args) throws Exception
153154
{
154155
if (args.length == 0)
155156
{
156-
System.err.format("Usage: %s <filenames>...\n", SbeTool.class.getName());
157+
System.err.format("Usage: %s <filenames>...%n", SbeTool.class.getName());
157158
System.exit(-1);
158159
}
159160

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import java.util.List;
3434
import java.util.function.BiConsumer;
3535
import java.util.function.Function;
36-
import static uk.co.real_logic.sbe.SbeTool.JAVA_INTERFACE_PACKAGE;
3736

37+
import static uk.co.real_logic.sbe.SbeTool.JAVA_INTERFACE_PACKAGE;
3838
import static uk.co.real_logic.sbe.generation.java.JavaUtil.*;
3939
import static uk.co.real_logic.sbe.ir.GenerationUtil.*;
4040

@@ -137,8 +137,8 @@ private void copyInterface(String simpleInterfaceName) throws IOException
137137
final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
138138
try (final Writer out = interfaceOutputManager.createOutput(simpleInterfaceName))
139139
{
140-
int bytes = 0;
141-
final char[] buffer = new char[512];
140+
int bytes;
141+
final char[] buffer = new char[4096];
142142
while (-1 != (bytes = reader.read(buffer)))
143143
{
144144
out.write(buffer, 0, bytes);
@@ -148,31 +148,30 @@ private void copyInterface(String simpleInterfaceName) throws IOException
148148

149149
public void generateInterfaces() throws IOException
150150
{
151-
if (!generateInterfaces)
151+
if (generateInterfaces)
152152
{
153-
return;
153+
copyInterface(GEN_COMPOSITE_DECODER_FLYWEIGHT);
154+
copyInterface(GEN_COMPOSITE_ENCODER_FLYWEIGHT);
155+
copyInterface(GEN_COMPOSITE_STRUCTURE);
156+
copyInterface(GEN_DECODER_FLYWEIGHT);
157+
copyInterface(GEN_ENCODER_FLYWEIGHT);
158+
copyInterface(GEN_FLYWEIGHT);
159+
copyInterface(GEN_MESSAGE_DECODER_FLYWEIGHT);
160+
copyInterface(GEN_MESSAGE_ENCODER_FLYWEIGHT);
161+
copyInterface(GEN_MESSAGE_FLYWEIGHT);
162+
copyInterface(GEN_MESSAGE_STRUCTURE);
163+
copyInterface(GEN_STRUCTURE);
154164
}
155-
copyInterface(GEN_COMPOSITE_DECODER_FLYWEIGHT);
156-
copyInterface(GEN_COMPOSITE_ENCODER_FLYWEIGHT);
157-
copyInterface(GEN_COMPOSITE_STRUCTURE);
158-
copyInterface(GEN_DECODER_FLYWEIGHT);
159-
copyInterface(GEN_ENCODER_FLYWEIGHT);
160-
copyInterface(GEN_FLYWEIGHT);
161-
copyInterface(GEN_MESSAGE_DECODER_FLYWEIGHT);
162-
copyInterface(GEN_MESSAGE_ENCODER_FLYWEIGHT);
163-
copyInterface(GEN_MESSAGE_FLYWEIGHT);
164-
copyInterface(GEN_MESSAGE_STRUCTURE);
165-
copyInterface(GEN_STRUCTURE);
166165
}
167166

168-
private String implementsInterface(String tokenName, String interfaceName)
167+
private String implementsInterface(final String tokenName, final String interfaceName)
169168
{
170169
if (!generateInterfaces)
171170
{
172171
return "";
173172
}
174-
final String structName = formatClassName(structureName(tokenName));
175-
return String.format(" implements %s<%s>", interfaceName, structName);
173+
174+
return String.format(" implements %s<%s>", interfaceName, formatClassName(structureName(tokenName)));
176175
}
177176

178177
public void generateMessageHeaderStub() throws IOException
@@ -201,6 +200,7 @@ private void generateMessageStructure(final Token msgToken) throws IOException
201200
{
202201
return;
203202
}
203+
204204
final String structName = formatClassName(structureName(msgToken.name()));
205205
try (final Writer out = outputManager.createOutput(structName))
206206
{
@@ -1011,7 +1011,6 @@ private void generateBitSet(final List<Token> tokens) throws IOException
10111011
{
10121012
generateFixedFlyweightHeader(token, decoderName, out, readOnlyBuffer, fqReadOnlyBuffer, "");
10131013
out.append(generateChoiceDecoders(messageBody));
1014-
10151014
out.append("}\n");
10161015
}
10171016

@@ -1025,7 +1024,11 @@ private void generateBitSet(final List<Token> tokens) throws IOException
10251024
}
10261025

10271026
private void generateFixedFlyweightHeader(
1028-
final Token token, final String encoderName, final Writer out, final String buffer, final String fqBuffer,
1027+
final Token token,
1028+
final String encoderName,
1029+
final Writer out,
1030+
final String buffer,
1031+
final String fqBuffer,
10291032
final String implementsString) throws IOException
10301033
{
10311034
out.append(generateFileHeader(encoderName, ir.applicableNamespace(), fqBuffer));
@@ -1295,6 +1298,7 @@ private CharSequence interfaceImportLine(final String packageName)
12951298
{
12961299
return "\n";
12971300
}
1301+
12981302
return String.format("import %s.*;\n\n", JAVA_INTERFACE_PACKAGE);
12991303
}
13001304

@@ -2224,8 +2228,8 @@ private CharSequence generateEnumEncoder(
22242228
formatClassName(containingClassName),
22252229
propertyName,
22262230
enumName,
2227-
generatePut(encoding.primitiveType(), "offset + " + offset, "value.value()", byteOrderString(encoding))
2228-
);
2231+
generatePut(encoding.primitiveType(), "offset + " + offset, "value.value()", byteOrderString(encoding)
2232+
));
22292233
}
22302234

22312235
private CharSequence generateBitSetProperty(

sbe-tool/src/main/resources/java/interfaces/CompositeDecoderFlyweight.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
import org.agrona.DirectBuffer;
@@ -7,5 +22,5 @@
722
*/
823
public interface CompositeDecoderFlyweight<T extends CompositeStructure> extends Flyweight<T>, DecoderFlyweight<T>
924
{
10-
CompositeDecoderFlyweight<T> wrap(final DirectBuffer buffer, final int offset);
25+
CompositeDecoderFlyweight<T> wrap(DirectBuffer buffer, int offset);
1126
}

sbe-tool/src/main/resources/java/interfaces/CompositeEncoderFlyweight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
/**

sbe-tool/src/main/resources/java/interfaces/CompositeStructure.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
/**

sbe-tool/src/main/resources/java/interfaces/DecoderFlyweight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
/**

sbe-tool/src/main/resources/java/interfaces/EncoderFlyweight.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
import org.agrona.MutableDirectBuffer;
@@ -7,5 +22,5 @@
722
*/
823
public interface EncoderFlyweight<T extends Structure> extends Flyweight<T>
924
{
10-
EncoderFlyweight<T> wrap(final MutableDirectBuffer buffer, final int offset);
25+
EncoderFlyweight<T> wrap(MutableDirectBuffer buffer, int offset);
1126
}

sbe-tool/src/main/resources/java/interfaces/Flyweight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
/**

sbe-tool/src/main/resources/java/interfaces/MessageDecoderFlyweight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
import org.agrona.DirectBuffer;

sbe-tool/src/main/resources/java/interfaces/MessageEncoderFlyweight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2014 - 2016 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.agrona.sbe;
217

318
/**

0 commit comments

Comments
 (0)