mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Clean up Java style (#5990)
Also make equivalent changes in C++ where applicable. Co-authored-by: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com>
This commit is contained in:
@@ -59,8 +59,7 @@ public final class CombinedRuntimeLoader {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<String> extractLibraries(Class<T> clazz, String resourceName)
|
||||
throws IOException {
|
||||
TypeReference<HashMap<String, Object>> typeRef =
|
||||
new TypeReference<HashMap<String, Object>>() {};
|
||||
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<>() {};
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> map;
|
||||
try (var stream = clazz.getResourceAsStream(resourceName)) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Deque;
|
||||
public class CleanupPool implements AutoCloseable {
|
||||
// Use a Deque instead of a Stack, as Stack's iterators go the wrong way, and docs
|
||||
// state ArrayDeque is faster anyway.
|
||||
private final Deque<AutoCloseable> m_closers = new ArrayDeque<AutoCloseable>();
|
||||
private final Deque<AutoCloseable> m_closers = new ArrayDeque<>();
|
||||
|
||||
/**
|
||||
* Registers an object in the object stack for cleanup.
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class ProtobufLogEntry<T> extends DataLogEntry {
|
||||
*/
|
||||
public static <T, MessageType extends ProtoMessage<?>> ProtobufLogEntry<T> create(
|
||||
DataLog log, String name, Protobuf<T, MessageType> proto, String metadata, long timestamp) {
|
||||
return new ProtobufLogEntry<T>(log, name, proto, metadata, timestamp);
|
||||
return new ProtobufLogEntry<>(log, name, proto, metadata, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class StructArrayLogEntry<T> extends DataLogEntry {
|
||||
*/
|
||||
public static <T> StructArrayLogEntry<T> create(
|
||||
DataLog log, String name, Struct<T> struct, String metadata, long timestamp) {
|
||||
return new StructArrayLogEntry<T>(log, name, struct, metadata, timestamp);
|
||||
return new StructArrayLogEntry<>(log, name, struct, metadata, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class StructLogEntry<T> extends DataLogEntry {
|
||||
*/
|
||||
public static <T> StructLogEntry<T> create(
|
||||
DataLog log, String name, Struct<T> struct, String metadata, long timestamp) {
|
||||
return new StructLogEntry<T>(log, name, struct, metadata, timestamp);
|
||||
return new StructLogEntry<>(log, name, struct, metadata, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class ProtobufBuffer<T, MessageType extends ProtoMessage<?>> {
|
||||
|
||||
public static <T, MessageType extends ProtoMessage<?>> ProtobufBuffer<T, MessageType> create(
|
||||
Protobuf<T, MessageType> proto) {
|
||||
return new ProtobufBuffer<T, MessageType>(proto);
|
||||
return new ProtobufBuffer<>(proto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class StructBuffer<T> {
|
||||
}
|
||||
|
||||
public static <T> StructBuffer<T> create(Struct<T> struct) {
|
||||
return new StructBuffer<T>(struct);
|
||||
return new StructBuffer<>(struct);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ public class StructDescriptorDatabase {
|
||||
}
|
||||
|
||||
// turn parsed schema into descriptors
|
||||
StructDescriptor theStruct = m_structs.computeIfAbsent(name, k -> new StructDescriptor(k));
|
||||
StructDescriptor theStruct = m_structs.computeIfAbsent(name, StructDescriptor::new);
|
||||
theStruct.m_schema = schema;
|
||||
theStruct.m_fields.clear();
|
||||
boolean isValid = true;
|
||||
@@ -76,7 +76,7 @@ public class StructDescriptorDatabase {
|
||||
|
||||
// cross-reference struct, creating a placeholder if necessary
|
||||
StructDescriptor aStruct =
|
||||
m_structs.computeIfAbsent(decl.typeString, k -> new StructDescriptor(k));
|
||||
m_structs.computeIfAbsent(decl.typeString, StructDescriptor::new);
|
||||
|
||||
// if the struct isn't valid, we can't be valid either
|
||||
if (aStruct.isValid()) {
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class PrintLog {
|
||||
@@ -133,11 +133,11 @@ public final class PrintLog {
|
||||
} else if ("boolean".equals(entry.type)) {
|
||||
System.out.println(" " + record.getBoolean());
|
||||
} else if ("double[]".equals(entry.type)) {
|
||||
System.out.println(" " + Arrays.asList(record.getDoubleArray()));
|
||||
System.out.println(" " + List.of(record.getDoubleArray()));
|
||||
} else if ("int64[]".equals(entry.type)) {
|
||||
System.out.println(" " + Arrays.asList(record.getIntegerArray()));
|
||||
System.out.println(" " + List.of(record.getIntegerArray()));
|
||||
} else if ("string[]".equals(entry.type)) {
|
||||
System.out.println(" " + Arrays.asList(record.getStringArray()));
|
||||
System.out.println(" " + List.of(record.getStringArray()));
|
||||
}
|
||||
} catch (InputMismatchException ex) {
|
||||
System.out.println(" invalid");
|
||||
|
||||
@@ -15,21 +15,21 @@ class ParserTest {
|
||||
@Test
|
||||
void testEmpty() {
|
||||
Parser p = new Parser("");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertTrue(schema.declarations.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptySemicolon() {
|
||||
Parser p = new Parser(";");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertTrue(schema.declarations.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSimple() {
|
||||
Parser p = new Parser("int32 a");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -40,14 +40,14 @@ class ParserTest {
|
||||
@Test
|
||||
void testSimpleTrailingSemi() {
|
||||
Parser p = new Parser("int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArray() {
|
||||
Parser p = new Parser("int32 a[2]");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -58,14 +58,14 @@ class ParserTest {
|
||||
@Test
|
||||
void testArrayTrailingSemi() {
|
||||
Parser p = new Parser("int32 a[2];");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBitfield() {
|
||||
Parser p = new Parser("int32 a:2");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -76,14 +76,14 @@ class ParserTest {
|
||||
@Test
|
||||
void testBitfieldTrailingSemi() {
|
||||
Parser p = new Parser("int32 a:2;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEnumKeyword() {
|
||||
Parser p = new Parser("enum {x=1} int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -95,7 +95,7 @@ class ParserTest {
|
||||
@Test
|
||||
void testEnumNoKeyword() {
|
||||
Parser p = new Parser("{x=1} int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -107,7 +107,7 @@ class ParserTest {
|
||||
@Test
|
||||
void testEnumNoValues() {
|
||||
Parser p = new Parser("{} int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -118,7 +118,7 @@ class ParserTest {
|
||||
@Test
|
||||
void testEnumMultipleValues() {
|
||||
Parser p = new Parser("{x=1,y=-2} int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -131,7 +131,7 @@ class ParserTest {
|
||||
@Test
|
||||
void testEnumTrailingComma() {
|
||||
Parser p = new Parser("{x=1,y=2,} int32 a;");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 1);
|
||||
var decl = schema.declarations.get(0);
|
||||
assertEquals(decl.typeString, "int32");
|
||||
@@ -144,7 +144,7 @@ class ParserTest {
|
||||
@Test
|
||||
void testMultipleNoTrailingSemi() {
|
||||
Parser p = new Parser("int32 a; int16 b");
|
||||
ParsedSchema schema = assertDoesNotThrow(() -> p.parse());
|
||||
ParsedSchema schema = assertDoesNotThrow(p::parse);
|
||||
assertEquals(schema.declarations.size(), 2);
|
||||
assertEquals(schema.declarations.get(0).typeString, "int32");
|
||||
assertEquals(schema.declarations.get(0).name, "a");
|
||||
@@ -155,58 +155,55 @@ class ParserTest {
|
||||
@Test
|
||||
void testErrBitfieldArray() {
|
||||
Parser p = new Parser("int32 a[1]:2");
|
||||
assertThrows(ParseException.class, () -> p.parse(), "10: expected ';', got ':'");
|
||||
assertThrows(ParseException.class, p::parse, "10: expected ';', got ':'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testErrNoArrayValue() {
|
||||
Parser p = new Parser("int32 a[]");
|
||||
assertThrows(ParseException.class, () -> p.parse(), "8: expected integer, got ']'");
|
||||
assertThrows(ParseException.class, p::parse, "8: expected integer, got ']'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testErrNoBitfieldValue() {
|
||||
Parser p = new Parser("int32 a:");
|
||||
assertThrows(ParseException.class, () -> p.parse(), "8: expected integer, got ''");
|
||||
assertThrows(ParseException.class, p::parse, "8: expected integer, got ''");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testErrNoNameArray() {
|
||||
Parser p = new Parser("int32 [2]");
|
||||
assertThrows(ParseException.class, () -> p.parse(), "6: expected identifier, got '['");
|
||||
assertThrows(ParseException.class, p::parse, "6: expected identifier, got '['");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testErrNoNameBitField() {
|
||||
Parser p = new Parser("int32 :2");
|
||||
assertThrows(ParseException.class, () -> p.parse(), "6: expected identifier, got ':'");
|
||||
assertThrows(ParseException.class, p::parse, "6: expected identifier, got ':'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeBitField() {
|
||||
Parser p = new Parser("int32 a:-1");
|
||||
assertThrows(
|
||||
ParseException.class, () -> p.parse(), "8: bitfield width '-1' is not a positive integer");
|
||||
ParseException.class, p::parse, "8: bitfield width '-1' is not a positive integer");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeArraySize() {
|
||||
Parser p = new Parser("int32 a[-1]");
|
||||
assertThrows(
|
||||
ParseException.class, () -> p.parse(), "8: array size '-1' is not a positive integer");
|
||||
assertThrows(ParseException.class, p::parse, "8: array size '-1' is not a positive integer");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testZeroBitField() {
|
||||
Parser p = new Parser("int32 a:0");
|
||||
assertThrows(
|
||||
ParseException.class, () -> p.parse(), "8: bitfield width '0' is not a positive integer");
|
||||
assertThrows(ParseException.class, p::parse, "8: bitfield width '0' is not a positive integer");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testZeroArraySize() {
|
||||
Parser p = new Parser("int32 a[0]");
|
||||
assertThrows(
|
||||
ParseException.class, () -> p.parse(), "8: array size '0' is not a positive integer");
|
||||
assertThrows(ParseException.class, p::parse, "8: array size '0' is not a positive integer");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user