Remove unused code and add pmd check (#395)

This commit is contained in:
Austin Shalit
2016-12-23 11:20:13 -08:00
committed by Peter Johnson
parent cc246bb9ac
commit 8f67f2c24c
19 changed files with 56 additions and 21 deletions

View File

@@ -19,4 +19,10 @@
<exclude name="AvoidDuplicateLiterals" />
</rule>
<rule ref="rulesets/java/unnecessary.xml" />
<rule ref="rulesets/java/unusedcode.xml" />
<rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
<properties>
<property name="checkAll" value="true"/>
</properties>
</rule>
</ruleset>

View File

@@ -28,6 +28,7 @@ class AnalogOutput : public SensorBase, public LiveWindowSendable {
void SetVoltage(double voltage);
double GetVoltage() const;
int GetChannel();
void UpdateTable() override;
void StartLiveWindowMode() override;

View File

@@ -35,7 +35,7 @@ class I2C : SensorBase {
bool WriteBulk(uint8_t* data, int count);
bool Read(int registerAddress, int count, uint8_t* data);
bool ReadOnly(int count, uint8_t* buffer);
void Broadcast(int registerAddress, uint8_t data);
// void Broadcast(int registerAddress, uint8_t data);
bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
private:

View File

@@ -59,6 +59,11 @@ AnalogOutput::AnalogOutput(int channel) {
*/
AnalogOutput::~AnalogOutput() { HAL_FreeAnalogOutputPort(m_port); }
/**
* Get the channel of this AnalogOutput.
*/
int AnalogOutput::GetChannel() { return m_channel; }
/**
* Set the value of the analog output.
*

View File

@@ -159,8 +159,8 @@ bool I2C::ReadOnly(int count, uint8_t* buffer) {
* @param registerAddress The register to write on all devices on the bus.
* @param data The value to write to the devices.
*/
[[gnu::warning("I2C::Broadcast() is not implemented.")]] void I2C::Broadcast(
int registerAddress, uint8_t data) {}
// [[gnu::warning("I2C::Broadcast() is not implemented.")]] void I2C::Broadcast(
// int registerAddress, uint8_t data) {}
/**
* Verify that a device's registers contain expected values.

View File

@@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.tables.ITable;
/**
* ADXL345 I2C Accelerometer.
*/
@SuppressWarnings("TypeName")
@SuppressWarnings({"TypeName", "PMD.UnusedPrivateField"})
public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindowSendable {
private static final byte kAddress = 0x1D;

View File

@@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.tables.ITable;
/**
* ADXL345 SPI Accelerometer.
*/
@SuppressWarnings({"TypeName"})
@SuppressWarnings({"TypeName", "PMD.UnusedPrivateField"})
public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindowSendable {
private static final int kPowerCtlRegister = 0x2D;
private static final int kDataFormatRegister = 0x31;

View File

@@ -22,6 +22,7 @@ import edu.wpi.first.wpilibj.tables.ITable;
*
* <p>This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
*/
@SuppressWarnings("PMD.UnusedPrivateField")
public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSendable {
private static final byte kRegWrite = 0x0A;
private static final byte kRegRead = 0x0B;

View File

@@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
*
* <p>This class is for the digital ADXRS450 gyro sensor that connects via SPI.
*/
@SuppressWarnings({"TypeName", "AbbreviationAsWordInName"})
@SuppressWarnings({"TypeName", "AbbreviationAsWordInName", "PMD.UnusedPrivateField"})
public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, LiveWindowSendable {
private static final double kSamplePeriod = 0.001;
private static final double kCalibrationSampleTime = 5.0;

View File

@@ -47,6 +47,13 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
m_channel = 0;
}
/**
* Get the channel of this AnalogOutput.
*/
public int getChannel() {
return m_channel;
}
public void setVoltage(double voltage) {
AnalogJNI.setAnalogOutput(m_port, voltage);
}

View File

@@ -55,8 +55,8 @@ public class CameraServer {
private HashMap<String, VideoSink> m_sinks;
private HashMap<Integer, ITable> m_tables; // indexed by source handle
private ITable m_publishTable;
private VideoListener m_videoListener;
private int m_tableListener;
private VideoListener m_videoListener; //NOPMD
private int m_tableListener; //NOPMD
private int m_nextPort;
private String[] m_addresses;
@@ -129,7 +129,7 @@ public class CameraServer {
}
}
@SuppressWarnings("JavadocMethod")
@SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable"})
private CameraServer() {
m_sources = new HashMap<String, VideoSource>();
m_sinks = new HashMap<String, VideoSink>();

View File

@@ -81,24 +81,37 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
return m_channel;
}
/**
* Generate a single pulse. There can only be a single pulse going at any time.
*
* @param pulseLength The length of the pulse.
*/
public void pulse(final double pulseLength) {
DIOJNI.pulse(m_handle, pulseLength);
}
/**
* Generate a single pulse. Write a pulse to the specified digital output channel. There can only
* be a single pulse going at any time.
*
* @param channel The channel to pulse.
* @param channel Unused
* @param pulseLength The length of the pulse.
* @deprecated Use {@link #pulse(double)} instead.
*/
@Deprecated
@SuppressWarnings("PMD.UnusedFormalParameter")
public void pulse(final int channel, final double pulseLength) {
DIOJNI.pulse(m_handle, pulseLength);
}
/**
* @param channel The channel to pulse.
* @param channel Unused
* @param pulseLength The length of the pulse.
* @deprecated Generate a single pulse. Write a pulse to the specified digital output channel.
* There can only be a single pulse going at any time.
*/
@Deprecated
@SuppressWarnings("PMD.UnusedFormalParameter")
public void pulse(final int channel, final int pulseLength) {
double convertedPulse = pulseLength / 1.0e9 * (DIOJNI.getLoopTiming() * 25);
System.err

View File

@@ -294,7 +294,7 @@ public class I2C extends SensorBase {
< count;
}
/**
/*
* Send a broadcast write to all devices on the I2C bus.
*
* <p>This is not currently implemented!
@@ -302,8 +302,8 @@ public class I2C extends SensorBase {
* @param registerAddress The register to write on all devices on the bus.
* @param data The value to write to the devices.
*/
public void broadcast(int registerAddress, int data) {
}
// public void broadcast(int registerAddress, int data) {
// }
/**
* Verify that a device's registers contain expected values.

View File

@@ -201,6 +201,7 @@ public class Joystick extends JoystickBase {
* GenericHID interface.
* @return The state of the trigger.
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public boolean getTrigger(Hand hand) {
return getRawButton(m_buttons[ButtonType.kTrigger.value]);
}
@@ -214,6 +215,7 @@ public class Joystick extends JoystickBase {
* GenericHID interface.
* @return The state of the top button.
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public boolean getTop(Hand hand) {
return getRawButton(m_buttons[ButtonType.kTop.value]);
}
@@ -236,6 +238,7 @@ public class Joystick extends JoystickBase {
* GenericHID interface.
* @return The state of the bumper (always false)
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public boolean getBumper(Hand hand) {
return false;
}

View File

@@ -75,7 +75,6 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
private int m_forwardHandle = 0;
private int m_reverseHandle = 0;
private long m_port;
private Direction m_direction;

View File

@@ -189,6 +189,7 @@ public abstract class RobotBase {
/**
* Starting point for the applications.
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public static void main(String... args) {
initializeHardwareConfiguration();

View File

@@ -40,10 +40,6 @@ public class Ultrasonic extends SensorBase implements PIDSource, LiveWindowSenda
// Time (sec) for the ping trigger pulse.
private static final double kPingTime = 10 * 1e-6;
// Priority that the ultrasonic round robin task runs.
private static final int kPriority = 90;
// Max time (ms) between readings.
private static final double kMaxUltrasonicTime = 0.1;
private static final double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
// head of the ultrasonic sensor list
private static Ultrasonic m_firstSensor = null;
@@ -84,7 +80,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, LiveWindowSenda
}
if (ultrasonic.isEnabled()) {
// Do the ping
ultrasonic.m_pingChannel.pulse(m_pingChannel.getChannel(), kPingTime);
ultrasonic.m_pingChannel.pulse(kPingTime);
}
ultrasonic = ultrasonic.m_nextSensor;
Timer.delay(.1); // wait for ping to return
@@ -288,7 +284,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, LiveWindowSenda
// single sensor
m_counter.reset(); // reset the counter to zero (invalid data now)
// do the ping to start getting a single range
m_pingChannel.pulse(m_pingChannel.getChannel(), kPingTime);
m_pingChannel.pulse(kPingTime);
}
/**

View File

@@ -100,6 +100,7 @@ public class XboxController extends GamepadBase {
* GenericHID interface.
* @return The state of the trigger (always false)
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public boolean getTrigger(Hand hand) {
return false;
}
@@ -112,6 +113,7 @@ public class XboxController extends GamepadBase {
* GenericHID interface.
* @return The state of the top button (always false)
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public boolean getTop(Hand hand) {
return false;
}

View File

@@ -57,6 +57,7 @@ public class HLUsageReporting {
public void reportScheduler() {
}
@SuppressWarnings("PMD.UnusedFormalParameter")
public void reportPIDController(int num) {
}