Skip to content

Commit 0f8a6b2

Browse files
committed
refactoring
1 parent de3c234 commit 0f8a6b2

File tree

6 files changed

+41
-79
lines changed

6 files changed

+41
-79
lines changed

jbbp-plugins/jbbp-gradle/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ apply plugin: 'groovy'
1717
apply plugin: 'maven-publish'
1818
apply plugin: "com.gradle.plugin-publish"
1919

20-
sourceCompatibility = 1.8
21-
targetCompatibility = 1.8
20+
sourceCompatibility = 11
21+
targetCompatibility = 11
2222

2323
dependencies {
2424
implementation gradleApi()

jbbp-plugins/jbbp-gradle/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
</dependencies>
2323

2424
<properties>
25-
<maven.compiler.source>1.8</maven.compiler.source>
26-
<maven.compiler.target>1.8</maven.compiler.target>
2725
<gradle.executable>gradle8</gradle.executable>
2826
<gradleGoal>publishToMavenLocal</gradleGoal>
2927
</properties>

jbbp-plugins/jbbp-maven/jbbp-maven-plugin/pom.xml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
<name>JBBP Maven plugin</name>
1515
<description>Generator of sources from JBBP scripts</description>
1616

17-
<properties>
18-
<maven.compiler.source>1.8</maven.compiler.source>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
</properties>
21-
2217
<profiles>
2318
<profile>
2419
<id>publish</id>
@@ -185,31 +180,10 @@
185180
</execution>
186181
</executions>
187182
</plugin>
188-
<plugin>
189-
<groupId>org.codehaus.mojo</groupId>
190-
<artifactId>animal-sniffer-maven-plugin</artifactId>
191-
<version>1.19</version>
192-
<configuration>
193-
<signature>
194-
<groupId>org.codehaus.mojo.signature</groupId>
195-
<artifactId>java16-sun</artifactId>
196-
<version>1.10</version>
197-
</signature>
198-
</configuration>
199-
<executions>
200-
<execution>
201-
<id>animal-sniffer</id>
202-
<phase>test</phase>
203-
<goals>
204-
<goal>check</goal>
205-
</goals>
206-
</execution>
207-
</executions>
208-
</plugin>
209183
<plugin>
210184
<groupId>org.apache.maven.plugins</groupId>
211185
<artifactId>maven-plugin-plugin</artifactId>
212-
<version>3.5</version>
186+
<version>3.8.1</version>
213187
<configuration>
214188
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
215189
<goalPrefix>jbbp</goalPrefix>

jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPTokenizer.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,6 @@ public static boolean isGlobalReservedName(final String name) {
135135
return GLOBAL_RESERVED_TYPE_NAMES.contains(name);
136136
}
137137

138-
private static JBBPByteOrder getJbbpByteOrder(String groupTypeByteOrder, String fieldType) {
139-
JBBPByteOrder byteOrder;
140-
if (groupTypeByteOrder != null) {
141-
if (">".equals(groupTypeByteOrder)) {
142-
byteOrder = JBBPByteOrder.BIG_ENDIAN;
143-
} else if ("<".equals(groupTypeByteOrder)) {
144-
byteOrder = JBBPByteOrder.LITTLE_ENDIAN;
145-
} else {
146-
throw new Error(
147-
"Illegal byte order char, unexpected error, contact developer please ["
148-
+ fieldType + ']');
149-
}
150-
} else {
151-
byteOrder = JBBPByteOrder.BIG_ENDIAN;
152-
}
153-
return byteOrder;
154-
}
155-
156138
/**
157139
* Inside method to read the next token from the string and place it into
158140
* inside storage.
@@ -240,7 +222,20 @@ private void readNextItem() {
240222

241223
wrongFormat = false;
242224

243-
JBBPByteOrder byteOrder = getJbbpByteOrder(groupTypeByteOrder, fieldType);
225+
JBBPByteOrder byteOrder;
226+
if (groupTypeByteOrder != null) {
227+
if (">".equals(groupTypeByteOrder)) {
228+
byteOrder = JBBPByteOrder.BIG_ENDIAN;
229+
} else if ("<".equals(groupTypeByteOrder)) {
230+
byteOrder = JBBPByteOrder.LITTLE_ENDIAN;
231+
} else {
232+
throw new Error(
233+
"Illegal byte order char, unexpected error, contact developer please ["
234+
+ fieldType + ']');
235+
}
236+
} else {
237+
byteOrder = JBBPByteOrder.BIG_ENDIAN;
238+
}
244239

245240
parsedType =
246241
new JBBPFieldTypeParameterContainer(byteOrder, groupTypeName, groupTypeExtraField);

jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,29 @@ public JBBPExpressionEvaluator(final String expression,
362362

363363
prevoperator = false;
364364
try {
365-
int parsed = getParsed(number, unaryOperatorCode);
365+
int parsed = Integer.parseInt(number);
366+
367+
if (unaryOperatorCode >= 0) {
368+
switch (unaryOperatorCode) {
369+
case CODE_UNARYPLUS:
370+
case CODE_ADD: {
371+
// do nothing
372+
}
373+
break;
374+
case CODE_UNARYMINUS:
375+
case CODE_MINUS: {
376+
parsed = -parsed;
377+
}
378+
break;
379+
case CODE_NOT: {
380+
parsed = ~parsed;
381+
}
382+
break;
383+
default: {
384+
throw new Error("Unsupported unary operator [" + SYMBOLS[unaryOperatorCode] + ']');
385+
}
386+
}
387+
}
366388

367389
unaryOperatorCode = -1;
368390
compiledScript.write(CODE_CONST);
@@ -415,33 +437,6 @@ public JBBPExpressionEvaluator(final String expression,
415437
this.maxStackDepth = calculateMaxStackDepth();
416438
}
417439

418-
private static int getParsed(String number, int unaryOperatorCode) {
419-
int parsed = Integer.parseInt(number);
420-
421-
if (unaryOperatorCode >= 0) {
422-
switch (unaryOperatorCode) {
423-
case CODE_UNARYPLUS:
424-
case CODE_ADD: {
425-
// do nothing
426-
}
427-
break;
428-
case CODE_UNARYMINUS:
429-
case CODE_MINUS: {
430-
parsed = -parsed;
431-
}
432-
break;
433-
case CODE_NOT: {
434-
parsed = ~parsed;
435-
}
436-
break;
437-
default: {
438-
throw new Error("Unsupported unary operator [" + SYMBOLS[unaryOperatorCode] + ']');
439-
}
440-
}
441-
}
442-
return parsed;
443-
}
444-
445440
/**
446441
* Encode code of an operator to code of similar unary operator.
447442
*

jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ public static void traceData(final InputStream inStream,
11361136
* @param script script to be processed, must not be null
11371137
* @param customFieldTypeProcessor custom field type processor if needed, can be null if no custom types in use
11381138
* @return detected biggest static array size with embedded structure awareness
1139-
* @since 2.1.1
1139+
* @since 3.0.0
11401140
*/
11411141
public static int findMaxStaticArraySize(final String script,
11421142
final JBBPCustomFieldTypeProcessor customFieldTypeProcessor) {

0 commit comments

Comments
 (0)