[transform] Code optimization for Java17: instanceof matching and multiline strings (#15483)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -161,41 +161,40 @@ public class Bin2Json {
|
||||
final String fieldName = field.getFieldName() == null ? "nonamed" : field.getFieldName();
|
||||
if (field instanceof JBBPAbstractArrayField) {
|
||||
final JsonArray jsonArray = new JsonArray();
|
||||
if (field instanceof JBBPFieldArrayBit) {
|
||||
for (final byte b : ((JBBPFieldArrayBit) field).getArray()) {
|
||||
if (field instanceof JBBPFieldArrayBit bit) {
|
||||
for (final byte b : bit.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayBoolean) {
|
||||
for (final boolean b : ((JBBPFieldArrayBoolean) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayBoolean boolean1) {
|
||||
for (final boolean b : boolean1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayByte) {
|
||||
for (final byte b : ((JBBPFieldArrayByte) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayByte byte1) {
|
||||
for (final byte b : byte1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayInt) {
|
||||
for (final int b : ((JBBPFieldArrayInt) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayInt int1) {
|
||||
for (final int b : int1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayLong) {
|
||||
for (final long b : ((JBBPFieldArrayLong) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayLong long1) {
|
||||
for (final long b : long1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayShort) {
|
||||
for (final short b : ((JBBPFieldArrayShort) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayShort short1) {
|
||||
for (final short b : short1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayStruct) {
|
||||
final JBBPFieldArrayStruct array = (JBBPFieldArrayStruct) field;
|
||||
} else if (field instanceof JBBPFieldArrayStruct array) {
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
jsonArray.add(convertToJSon(new JsonObject(), array.getElementAt(i)));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayUByte) {
|
||||
for (final byte b : ((JBBPFieldArrayUByte) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayUByte byte1) {
|
||||
for (final byte b : byte1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b & 0xFF));
|
||||
}
|
||||
} else if (field instanceof JBBPFieldArrayUShort) {
|
||||
for (final short b : ((JBBPFieldArrayUShort) field).getArray()) {
|
||||
} else if (field instanceof JBBPFieldArrayUShort short1) {
|
||||
for (final short b : short1.getArray()) {
|
||||
jsonArray.add(new JsonPrimitive(b & 0xFFFF));
|
||||
}
|
||||
} else {
|
||||
@@ -203,20 +202,19 @@ public class Bin2Json {
|
||||
}
|
||||
jsn.add(fieldName, jsonArray);
|
||||
} else {
|
||||
if (field instanceof JBBPFieldBit) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldBit) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldBoolean) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldBoolean) field).getAsBool());
|
||||
} else if (field instanceof JBBPFieldByte) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldByte) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldInt) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldInt) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldLong) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldLong) field).getAsLong());
|
||||
} else if (field instanceof JBBPFieldShort) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldShort) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldStruct) {
|
||||
final JBBPFieldStruct struct = (JBBPFieldStruct) field;
|
||||
if (field instanceof JBBPFieldBit bit) {
|
||||
jsn.addProperty(fieldName, bit.getAsInt());
|
||||
} else if (field instanceof JBBPFieldBoolean boolean1) {
|
||||
jsn.addProperty(fieldName, boolean1.getAsBool());
|
||||
} else if (field instanceof JBBPFieldByte byte1) {
|
||||
jsn.addProperty(fieldName, byte1.getAsInt());
|
||||
} else if (field instanceof JBBPFieldInt int1) {
|
||||
jsn.addProperty(fieldName, int1.getAsInt());
|
||||
} else if (field instanceof JBBPFieldLong long1) {
|
||||
jsn.addProperty(fieldName, long1.getAsLong());
|
||||
} else if (field instanceof JBBPFieldShort short1) {
|
||||
jsn.addProperty(fieldName, short1.getAsInt());
|
||||
} else if (field instanceof JBBPFieldStruct struct) {
|
||||
final JsonObject obj = new JsonObject();
|
||||
for (final JBBPAbstractField f : struct.getArray()) {
|
||||
convertToJSon(obj, f);
|
||||
@@ -226,10 +224,10 @@ public class Bin2Json {
|
||||
} else {
|
||||
jsn.add(fieldName, obj);
|
||||
}
|
||||
} else if (field instanceof JBBPFieldUByte) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldUByte) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldUShort) {
|
||||
jsn.addProperty(fieldName, ((JBBPFieldUShort) field).getAsInt());
|
||||
} else if (field instanceof JBBPFieldUByte byte1) {
|
||||
jsn.addProperty(fieldName, byte1.getAsInt());
|
||||
} else if (field instanceof JBBPFieldUShort short1) {
|
||||
jsn.addProperty(fieldName, short1.getAsInt());
|
||||
} else {
|
||||
throw new ConversionException(String.format("Unexpected field '%s'", field));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user