Update Java linters and fix new PMD errors (#4157)

PMD requires that variables only initialized in the constructor be
final. The compiler errors if those final variables aren't guaranteed to
be initialized, so extra else branches were added to ensure that.

PMD also requires that classes with only private constructors be final.
The equivalent C++ classes were finalized as well, except for
TimeInterpolatableBuffer because it doesn't expose factory functions.
This commit is contained in:
Tyler Veness
2022-04-24 07:18:05 -07:00
committed by GitHub
parent ffc69d406c
commit 355a11a414
14 changed files with 50 additions and 28 deletions

View File

@@ -9,12 +9,12 @@ import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
public class RomiGyro {
private SimDouble m_simRateX;
private SimDouble m_simRateY;
private SimDouble m_simRateZ;
private SimDouble m_simAngleX;
private SimDouble m_simAngleY;
private SimDouble m_simAngleZ;
private final SimDouble m_simRateX;
private final SimDouble m_simRateY;
private final SimDouble m_simRateZ;
private final SimDouble m_simAngleX;
private final SimDouble m_simAngleY;
private final SimDouble m_simAngleZ;
private double m_angleXOffset;
private double m_angleYOffset;
@@ -32,6 +32,14 @@ public class RomiGyro {
m_simAngleX = gyroSimDevice.createDouble("angle_x", Direction.kInput, 0.0);
m_simAngleY = gyroSimDevice.createDouble("angle_y", Direction.kInput, 0.0);
m_simAngleZ = gyroSimDevice.createDouble("angle_z", Direction.kInput, 0.0);
} else {
m_simRateX = null;
m_simRateY = null;
m_simRateZ = null;
m_simAngleX = null;
m_simAngleY = null;
m_simAngleZ = null;
}
}

View File

@@ -22,12 +22,12 @@ public class OnBoardIO extends SubsystemBase {
private final DigitalOutput m_yellowLed = new DigitalOutput(3);
// DIO 1
private DigitalInput m_buttonB;
private DigitalOutput m_greenLed;
private final DigitalInput m_buttonB;
private final DigitalOutput m_greenLed;
// DIO 2
private DigitalInput m_buttonC;
private DigitalOutput m_redLed;
private final DigitalInput m_buttonC;
private final DigitalOutput m_redLed;
private static final double MESSAGE_INTERVAL = 1.0;
private double m_nextMessageTime;
@@ -46,13 +46,17 @@ public class OnBoardIO extends SubsystemBase {
public OnBoardIO(ChannelMode dio1, ChannelMode dio2) {
if (dio1 == ChannelMode.INPUT) {
m_buttonB = new DigitalInput(1);
m_greenLed = null;
} else {
m_buttonB = null;
m_greenLed = new DigitalOutput(1);
}
if (dio2 == ChannelMode.INPUT) {
m_buttonC = new DigitalInput(2);
m_redLed = null;
} else {
m_buttonC = null;
m_redLed = new DigitalOutput(2);
}
}

View File

@@ -62,11 +62,11 @@ public class DriveSubsystem extends SubsystemBase {
// These classes help us simulate our drivetrain
public DifferentialDrivetrainSim m_drivetrainSimulator;
private EncoderSim m_leftEncoderSim;
private EncoderSim m_rightEncoderSim;
private final EncoderSim m_leftEncoderSim;
private final EncoderSim m_rightEncoderSim;
// The Field2d class shows the field in the sim GUI
private Field2d m_fieldSim;
private ADXRS450_GyroSim m_gyroSim;
private final Field2d m_fieldSim;
private final ADXRS450_GyroSim m_gyroSim;
/** Creates a new DriveSubsystem. */
public DriveSubsystem() {
@@ -101,6 +101,12 @@ public class DriveSubsystem extends SubsystemBase {
// the Field2d class lets us visualize our robot in the simulation GUI.
m_fieldSim = new Field2d();
SmartDashboard.putData("Field", m_fieldSim);
} else {
m_leftEncoderSim = null;
m_rightEncoderSim = null;
m_gyroSim = null;
m_fieldSim = null;
}
}