From e548a5f7054ccc221ede1917bb62f512d1fb0fe3 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Sun, 3 Jun 2018 10:00:53 -0700 Subject: [PATCH] Update and enable PMD 6.3.0 (#1107) --- build.gradle | 8 +-- .../edu/wpi/first/cameraserver/DevMain.java | 5 +- .../edu/wpi/first/wpilibj/CameraServer.java | 33 ++++----- .../wpilibj/CameraServerSharedStore.java | 2 +- .../src/dev/java/edu/wpi/cscore/DevMain.java | 5 +- .../main/java/edu/wpi/cscore/VideoEvent.java | 2 + .../main/java/edu/wpi/cscore/VideoSink.java | 1 + .../main/java/edu/wpi/cscore/VideoSource.java | 3 + gen/wpilibj_frcnetcomm.py | 12 ++-- hal/src/dev/java/DevMain.java | 5 +- .../java/edu/wpi/first/wpilibj/CANData.java | 1 + .../wpilibj/can/CANExceptionFactory.java | 8 ++- .../edu/wpi/first/wpilibj/hal/FRCNetComm.java | 8 +-- .../java/edu/wpi/first/wpilibj/hal/HAL.java | 8 ++- .../edu/wpi/first/wpilibj/hal/HALUtil.java | 6 +- .../first/wpilibj/sim/AccelerometerSim.java | 2 +- .../wpi/first/wpilibj/sim/AnalogGyroSim.java | 2 +- .../wpi/first/wpilibj/sim/AnalogInSim.java | 2 +- .../wpi/first/wpilibj/sim/AnalogOutSim.java | 2 +- .../first/wpilibj/sim/AnalogTriggerSim.java | 2 +- .../wpi/first/wpilibj/sim/CallbackStore.java | 2 +- .../edu/wpi/first/wpilibj/sim/DIOSim.java | 2 +- .../wpi/first/wpilibj/sim/DigitalPWMSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/EncoderSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/I2CSim.java | 2 +- .../wpi/first/wpilibj/sim/NotifyCallback.java | 9 +-- .../edu/wpi/first/wpilibj/sim/PCMSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/PDPSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/PWMSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/RelaySim.java | 2 +- .../edu/wpi/first/wpilibj/sim/RoboRioSim.java | 3 +- .../wpilibj/sim/SPIAccelerometerSim.java | 2 +- .../edu/wpi/first/wpilibj/sim/SPISim.java | 2 +- .../edu/wpi/first/wpilibj/sim/SimHooks.java | 2 +- .../edu/wpi/first/wpilibj/sim/SimValue.java | 2 +- .../java/edu/wpi/first/ntcore/DevMain.java | 5 +- .../wpi/first/networktables/NetworkTable.java | 1 + .../wpilibj/networktables/NetworkTable.java | 21 ++++++ shared/java/javacommon.gradle | 9 --- shared/java/javastyle.gradle | 16 +++++ styleguide/pmd-ruleset.xml | 60 ++++++++++++++++ .../java/edu/wpi/first/wpilibj/DevMain.java | 5 +- .../first/wpilibj/AnalogAccelerometer.java | 14 ++-- .../edu/wpi/first/wpilibj/AnalogGyro.java | 4 +- .../edu/wpi/first/wpilibj/AnalogTrigger.java | 4 +- .../main/java/edu/wpi/first/wpilibj/CAN.java | 2 +- .../edu/wpi/first/wpilibj/CircularBuffer.java | 4 +- .../wpi/first/wpilibj/ControllerPower.java | 5 +- .../java/edu/wpi/first/wpilibj/Counter.java | 6 +- .../first/wpilibj/DigitalGlitchFilter.java | 1 + .../edu/wpi/first/wpilibj/DigitalInput.java | 6 +- .../edu/wpi/first/wpilibj/DigitalOutput.java | 4 +- .../edu/wpi/first/wpilibj/DoubleSolenoid.java | 4 +- .../edu/wpi/first/wpilibj/DriverStation.java | 70 +++++++++++-------- .../java/edu/wpi/first/wpilibj/Encoder.java | 10 ++- .../edu/wpi/first/wpilibj/GamepadBase.java | 9 +++ .../edu/wpi/first/wpilibj/GenericHID.java | 3 +- .../wpi/first/wpilibj/HLUsageReporting.java | 8 ++- .../main/java/edu/wpi/first/wpilibj/I2C.java | 9 +-- .../wpilibj/InterruptableSensorBase.java | 3 +- .../edu/wpi/first/wpilibj/IterativeRobot.java | 1 + .../wpi/first/wpilibj/IterativeRobotBase.java | 2 + .../edu/wpi/first/wpilibj/NamedSendable.java | 1 + .../edu/wpi/first/wpilibj/NidecBrushless.java | 10 +-- .../java/edu/wpi/first/wpilibj/Notifier.java | 6 +- .../java/edu/wpi/first/wpilibj/PIDBase.java | 38 ++++++---- .../main/java/edu/wpi/first/wpilibj/PWM.java | 2 +- .../wpi/first/wpilibj/PWMSpeedController.java | 2 +- .../edu/wpi/first/wpilibj/Preferences.java | 3 +- .../java/edu/wpi/first/wpilibj/Relay.java | 9 +-- .../java/edu/wpi/first/wpilibj/Resource.java | 2 +- .../java/edu/wpi/first/wpilibj/RobotBase.java | 15 ++-- .../edu/wpi/first/wpilibj/RobotDrive.java | 11 +-- .../edu/wpi/first/wpilibj/RobotState.java | 5 +- .../main/java/edu/wpi/first/wpilibj/SPI.java | 8 ++- .../java/edu/wpi/first/wpilibj/SafePWM.java | 7 ++ .../edu/wpi/first/wpilibj/SampleRobot.java | 2 + .../edu/wpi/first/wpilibj/SerialPort.java | 1 + .../first/wpilibj/SpeedControllerGroup.java | 5 +- .../java/edu/wpi/first/wpilibj/Threads.java | 5 +- .../edu/wpi/first/wpilibj/TimedRobot.java | 5 +- .../edu/wpi/first/wpilibj/Ultrasonic.java | 17 ++--- .../edu/wpi/first/wpilibj/XboxController.java | 2 +- .../first/wpilibj/buttons/InternalButton.java | 1 + .../first/wpilibj/buttons/JoystickButton.java | 1 + .../first/wpilibj/buttons/NetworkButton.java | 1 + .../wpi/first/wpilibj/buttons/Trigger.java | 2 +- .../wpi/first/wpilibj/command/Command.java | 13 ++-- .../first/wpilibj/command/CommandGroup.java | 15 +++- .../wpilibj/command/ConditionalCommand.java | 2 +- .../first/wpilibj/command/InstantCommand.java | 1 + .../wpi/first/wpilibj/command/PIDCommand.java | 3 + .../first/wpilibj/command/PIDSubsystem.java | 3 + .../first/wpilibj/command/PrintCommand.java | 3 +- .../wpi/first/wpilibj/command/Scheduler.java | 19 +++-- .../first/wpilibj/command/StartCommand.java | 3 +- .../wpi/first/wpilibj/command/Subsystem.java | 2 +- .../first/wpilibj/command/TimedCommand.java | 1 + .../wpilibj/command/WaitForChildren.java | 1 + .../wpilibj/command/WaitUntilCommand.java | 3 +- .../wpilibj/drive/DifferentialDrive.java | 12 ++-- .../first/wpilibj/drive/KilloughDrive.java | 4 +- .../wpi/first/wpilibj/drive/MecanumDrive.java | 12 ++-- .../edu/wpi/first/wpilibj/drive/Vector2d.java | 4 +- .../edu/wpi/first/wpilibj/filters/Filter.java | 2 +- .../wpilibj/filters/LinearDigitalFilter.java | 12 ++-- .../first/wpilibj/internal/HardwareTimer.java | 5 ++ .../first/wpilibj/livewindow/LiveWindow.java | 7 +- .../smartdashboard/SendableBuilderImpl.java | 5 +- .../smartdashboard/SendableChooser.java | 1 + .../smartdashboard/SmartDashboard.java | 2 + .../wpi/first/wpilibj/util/SortedVector.java | 1 + .../first/wpilibj/MockSpeedController.java | 4 +- .../wpilibj/command/AbstractCommandTest.java | 1 + .../first/wpilibj/command/MockCommand.java | 17 +++-- .../command/MockConditionalCommand.java | 17 +++-- .../first/wpilibj/command/MockSubsystem.java | 1 + .../commands/command/ReplaceMeCommand.java | 1 + .../first/wpilibj/examples/gearsbot/OI.java | 2 +- .../gearsbot/commands/DriveStraight.java | 2 +- .../gearsbot/commands/SetDistanceToBox.java | 2 +- .../commands/SetElevatorSetpoint.java | 2 +- .../gearsbot/commands/SetWristSetpoint.java | 2 +- .../examples/gearsbot/subsystems/Claw.java | 5 +- .../gearsbot/subsystems/DriveTrain.java | 14 ++-- .../gearsbot/subsystems/Elevator.java | 4 +- .../examples/gearsbot/subsystems/Wrist.java | 4 +- .../examples/gettingstarted/Robot.java | 6 +- .../first/wpilibj/examples/gyro/Robot.java | 6 +- .../wpilibj/examples/gyromecanum/Robot.java | 4 +- .../pacgoat/commands/DriveForward.java | 4 +- .../pacgoat/commands/SetCollectionSpeed.java | 2 +- .../pacgoat/commands/SetPivotSetpoint.java | 2 +- .../pacgoat/subsystems/Collector.java | 9 +-- .../pacgoat/subsystems/DriveTrain.java | 20 +++--- .../examples/pacgoat/subsystems/Pivot.java | 8 +-- .../examples/pacgoat/subsystems/Shooter.java | 1 + .../pacgoat/triggers/DoubleButton.java | 6 +- .../examples/potentiometerpid/Robot.java | 9 +-- .../wpilibj/examples/ultrasonic/Robot.java | 5 +- .../wpilibj/examples/ultrasonicpid/Robot.java | 6 +- .../subsystems/ExampleSubsystem.java | 1 + .../wpilibj/templates/iterative/Robot.java | 2 +- .../first/wpilibj/templates/sample/Robot.java | 6 +- .../first/wpilibj/templates/timed/Robot.java | 2 +- .../wpi/first/wpilibj/ConstantsPortsTest.java | 1 + .../wpilibj/DigitalGlitchFilterTest.java | 1 + .../java/edu/wpi/first/wpilibj/PCMTest.java | 1 + .../edu/wpi/first/wpilibj/RobotDriveTest.java | 1 + .../edu/wpi/first/wpilibj/SampleTest.java | 1 + .../mockhardware/FakeCounterSource.java | 2 + .../mockhardware/FakeEncoderSource.java | 2 + .../mockhardware/FakePotentiometerSource.java | 1 + .../smartdashboard/SmartDashboardTest.java | 1 + .../java/edu/wpi/first/wpiutil/DevMain.java | 5 +- .../wpi/first/wpiutil/RuntimeDetector.java | 13 ++-- 156 files changed, 619 insertions(+), 325 deletions(-) create mode 100644 shared/java/javastyle.gradle diff --git a/build.gradle b/build.gradle index d644075b39..2142f26c5f 100644 --- a/build.gradle +++ b/build.gradle @@ -75,17 +75,13 @@ ext.addTaskToCopyAllOutputs = { task -> subprojects { apply plugin: 'eclipse' apply plugin: 'idea' - apply plugin: 'checkstyle' + + apply from: "${rootDir}/shared/java/javastyle.gradle" repositories { mavenCentral() } - checkstyle { - toolVersion = "8.10" - configFile = new File(rootDir, "styleguide/checkstyle.xml") - } - // Disables doclint in java 8. if (JavaVersion.current().isJava8Compatible()) { tasks.withType(Javadoc) { diff --git a/cameraserver/src/dev/java/edu/wpi/first/cameraserver/DevMain.java b/cameraserver/src/dev/java/edu/wpi/first/cameraserver/DevMain.java index 5f3bf8709b..1182ac4438 100644 --- a/cameraserver/src/dev/java/edu/wpi/first/cameraserver/DevMain.java +++ b/cameraserver/src/dev/java/edu/wpi/first/cameraserver/DevMain.java @@ -7,8 +7,11 @@ package edu.wpi.first.cameraserver; -public class DevMain { +public final class DevMain { public static void main(String[] args) { } + + private DevMain() { + } } diff --git a/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServer.java b/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServer.java index 76be85cb71..bbfbd93fc8 100644 --- a/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServer.java @@ -8,7 +8,9 @@ package edu.wpi.first.wpilibj; import java.util.ArrayList; +import java.util.Arrays; import java.util.Hashtable; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import edu.wpi.cscore.AxisCamera; @@ -34,7 +36,8 @@ import edu.wpi.first.networktables.NetworkTableInstance; * Singleton class for creating and keeping camera servers. * Also publishes camera information to NetworkTables. */ -public class CameraServer { +@SuppressWarnings("PMD.TooManyMethods") +public final class CameraServer { public static final int kBasePort = 1181; @Deprecated @@ -57,11 +60,11 @@ public class CameraServer { return server; } - private AtomicInteger m_defaultUsbDevice; + private final AtomicInteger m_defaultUsbDevice; private String m_primarySourceName; - private final Hashtable m_sources; - private final Hashtable m_sinks; - private final Hashtable m_tables; // indexed by source handle + private final Map m_sources; + private final Map m_sinks; + private final Map m_tables; // indexed by source handle private final NetworkTable m_publishTable; private final VideoListener m_videoListener; //NOPMD private final int m_tableListener; //NOPMD @@ -115,7 +118,7 @@ public class CameraServer { // Otherwise generate for hostname and all interface addresses values.add(makeStreamValue(CameraServerJNI.getHostname() + ".local", port)); for (String addr : m_addresses) { - if (addr.equals("127.0.0.1")) { + if ("127.0.0.1".equals(addr)) { continue; // ignore localhost } values.add(makeStreamValue(addr, port)); @@ -146,10 +149,7 @@ public class CameraServer { if (source == sinkSource && VideoSink.getKindFromInt(CameraServerJNI.getSinkKind(sink)) == VideoSink.Kind.kMjpeg) { // Add USB-only passthrough - String[] finalValues = new String[values.length + 1]; - for (int j = 0; j < values.length; j++) { - finalValues[j] = values[j]; - } + String[] finalValues = Arrays.copyOf(values, values.length + 1); int port = CameraServerJNI.getMjpegServerPort(sink); finalValues[values.length] = makeStreamValue("172.22.11.2", port); return finalValues; @@ -238,7 +238,7 @@ public class CameraServer { return modeStrings; } - @SuppressWarnings("JavadocMethod") + @SuppressWarnings({"JavadocMethod", "PMD.CyclomaticComplexity"}) private static void putSourcePropertyValue(NetworkTable table, VideoEvent event, boolean isNew) { String name; String infoName; @@ -286,12 +286,13 @@ public class CameraServer { default: break; } - } catch (VideoException ex) { + } catch (VideoException ignored) { // ignore } } - @SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable"}) + @SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable", "PMD.ExcessiveMethodLength", + "PMD.NPathComplexity"}) private CameraServer() { m_defaultUsbDevice = new AtomicInteger(); m_sources = new Hashtable<>(); @@ -329,7 +330,7 @@ public class CameraServer { VideoMode mode = CameraServerJNI.getSourceVideoMode(event.sourceHandle); table.getEntry("mode").setDefaultString(videoModeToString(mode)); table.getEntry("modes").setStringArray(getSourceModeValues(event.sourceHandle)); - } catch (VideoException ex) { + } catch (VideoException ignored) { // Do nothing. Let the other event handlers update this if there is an error. } break; @@ -394,7 +395,7 @@ public class CameraServer { try { String[] choices = CameraServerJNI.getEnumPropertyChoices(event.propertyHandle); table.getEntry("PropertyInfo/" + event.name + "/choices").setStringArray(choices); - } catch (VideoException ex) { + } catch (VideoException ignored) { // ignore } } @@ -437,7 +438,7 @@ public class CameraServer { // handle standard names String propName; - if (relativeKey.equals("mode")) { + if ("mode".equals(relativeKey)) { // reset to current mode event.getEntry().setString(videoModeToString(source.getVideoMode())); return; diff --git a/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServerSharedStore.java b/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServerSharedStore.java index 3a7dfb3c0a..7fce82086f 100644 --- a/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServerSharedStore.java +++ b/cameraserver/src/main/java/edu/wpi/first/wpilibj/CameraServerSharedStore.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj; -public class CameraServerSharedStore { +public final class CameraServerSharedStore { private static CameraServerShared cameraServerShared; private CameraServerSharedStore() { diff --git a/cscore/src/dev/java/edu/wpi/cscore/DevMain.java b/cscore/src/dev/java/edu/wpi/cscore/DevMain.java index c406e9f6ae..e7fd516062 100644 --- a/cscore/src/dev/java/edu/wpi/cscore/DevMain.java +++ b/cscore/src/dev/java/edu/wpi/cscore/DevMain.java @@ -9,7 +9,7 @@ package edu.wpi.cscore; import edu.wpi.first.wpiutil.RuntimeDetector; -public class DevMain { +public final class DevMain { /** * Main method. */ @@ -18,4 +18,7 @@ public class DevMain { System.out.println(RuntimeDetector.getPlatformPath()); System.out.println(CameraServerJNI.getHostname()); } + + private DevMain() { + } } diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java b/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java index f0be9e31f4..835550669e 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java @@ -48,6 +48,7 @@ public class VideoEvent { * @param kind The numerical representation of kind * @return The kind */ + @SuppressWarnings("PMD.CyclomaticComplexity") public static Kind getKindFromInt(int kind) { switch (kind) { case 0x0001: return Kind.kSourceCreated; @@ -69,6 +70,7 @@ public class VideoEvent { } } + @SuppressWarnings("PMD.ExcessiveParameterList") VideoEvent(int kind, int source, int sink, String name, int pixelFormat, int width, int height, int fps, int property, int propertyKind, int value, String valueStr) { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java b/cscore/src/main/java/edu/wpi/cscore/VideoSink.java index bf3e5a6f20..4b187f148a 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoSink.java @@ -148,6 +148,7 @@ public class VideoSink implements AutoCloseable { * Enumerate all existing sinks. * @return Vector of sinks. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public static VideoSink[] enumerateSinks() { int[] handles = CameraServerJNI.enumerateSinks(); VideoSink[] rv = new VideoSink[handles.length]; diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java b/cscore/src/main/java/edu/wpi/cscore/VideoSource.java index f800045322..ab43ebb1a8 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoSource.java @@ -138,6 +138,7 @@ public class VideoSource implements AutoCloseable { /** * Enumerate all properties of this source. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public VideoProperty[] enumerateProperties() { int[] handles = CameraServerJNI.enumerateSourceProperties(m_handle); VideoProperty[] rv = new VideoProperty[handles.length]; @@ -239,6 +240,7 @@ public class VideoSource implements AutoCloseable { * Enumerate all sinks connected to this source. * @return Vector of sinks. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public VideoSink[] enumerateSinks() { int[] handles = CameraServerJNI.enumerateSourceSinks(m_handle); VideoSink[] rv = new VideoSink[handles.length]; @@ -252,6 +254,7 @@ public class VideoSource implements AutoCloseable { * Enumerate all existing sources. * @return Vector of sources. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public static VideoSource[] enumerateSources() { int[] handles = CameraServerJNI.enumerateSources(); VideoSource[] rv = new VideoSource[handles.length]; diff --git a/gen/wpilibj_frcnetcomm.py b/gen/wpilibj_frcnetcomm.py index da8ff98848..664bfd1e69 100755 --- a/gen/wpilibj_frcnetcomm.py +++ b/gen/wpilibj_frcnetcomm.py @@ -140,12 +140,12 @@ public class FRCNetComm extends JNIWrapper { for i in range(1, len(enumCamel)): temp.write(enumCamel[i][0].lower() + \ enumCamel[i][1:len(enumCamel[i])] + " ") - temp.write("from " + os.path.basename(fileName) + "\n" - " */\n" - " @SuppressWarnings(\"TypeName\")\n" - " public static final class " + enumName + - " {\n" - " private " + enumName + "() {\n }\n\n") + temp.write( + "from " + os.path.basename(fileName) + "\n" + " */\n" + " @SuppressWarnings({\"TypeName\", \"PMD.ConstantsInInterface\"})\n" + " public static final class " + enumName + " {\n" + " private " + enumName + "() {\n }\n\n") # Write enum values count = 0 diff --git a/hal/src/dev/java/DevMain.java b/hal/src/dev/java/DevMain.java index 9a9bb0c764..8cdb8bad40 100644 --- a/hal/src/dev/java/DevMain.java +++ b/hal/src/dev/java/DevMain.java @@ -5,8 +5,11 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -public class DevMain { +public final class DevMain { public static void main(String[] args) { } + + private DevMain() { + } } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/CANData.java b/hal/src/main/java/edu/wpi/first/wpilibj/CANData.java index 7e0fc6e35b..bbe4eaa968 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/CANData.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/CANData.java @@ -18,6 +18,7 @@ public class CANData { /** * API used from JNI to set the data. */ + @SuppressWarnings("PMD.MethodReturnsInternalArray") public byte[] setData(int length, long timestamp) { this.length = length; this.timestamp = timestamp; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java b/hal/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java index 79670cf0cc..b05b5e019e 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java @@ -10,14 +10,14 @@ package edu.wpi.first.wpilibj.can; import edu.wpi.first.wpilibj.communication.NIRioStatus; import edu.wpi.first.wpilibj.util.UncleanStatusException; -public class CANExceptionFactory { +public final class CANExceptionFactory { // FRC Error codes static final int ERR_CANSessionMux_InvalidBuffer = -44086; static final int ERR_CANSessionMux_MessageNotFound = -44087; static final int ERR_CANSessionMux_NotAllowed = -44088; static final int ERR_CANSessionMux_NotInitialized = -44089; - @SuppressWarnings("JavadocMethod") + @SuppressWarnings({"JavadocMethod", "PMD.CyclomaticComplexity"}) public static void checkStatus(int status, int messageID) throws CANInvalidBufferException, CANMessageNotAllowedException, CANNotInitializedException, UncleanStatusException { switch (status) { @@ -41,4 +41,8 @@ public class CANExceptionFactory { status)); } } + + private CANExceptionFactory() { + + } } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java b/hal/src/main/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java index 4371826881..148d4ca3ed 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java @@ -17,7 +17,7 @@ public class FRCNetComm extends JNIWrapper { /** * Module type from LoadOut.h */ - @SuppressWarnings("TypeName") + @SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"}) public static final class tModuleType { private tModuleType() { } @@ -31,7 +31,7 @@ public class FRCNetComm extends JNIWrapper { /** * Target class from LoadOut.h */ - @SuppressWarnings("TypeName") + @SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"}) public static final class tTargetClass { private tTargetClass() { } @@ -51,7 +51,7 @@ public class FRCNetComm extends JNIWrapper { /** * Resource type from UsageReporting.h */ - @SuppressWarnings("TypeName") + @SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"}) public static final class tResourceType { private tResourceType() { } @@ -132,7 +132,7 @@ public class FRCNetComm extends JNIWrapper { /** * Instances from UsageReporting.h */ - @SuppressWarnings("TypeName") + @SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"}) public static final class tInstances { private tInstances() { } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/hal/HAL.java b/hal/src/main/java/edu/wpi/first/wpilibj/hal/HAL.java index bb590a5da6..9be5a503c6 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/hal/HAL.java @@ -12,8 +12,8 @@ import java.nio.ByteBuffer; /** * JNI Wrapper for HAL
. */ -@SuppressWarnings({"AbbreviationAsWordInName", "MethodName"}) -public class HAL extends JNIWrapper { +@SuppressWarnings({"AbbreviationAsWordInName", "MethodName", "PMD.TooManyMethods"}) +public final class HAL extends JNIWrapper { public static native void waitForDSData(); public static native boolean initialize(int timeout, int mode); @@ -127,4 +127,8 @@ public class HAL extends JNIWrapper { public static native int getPortWithModule(byte module, byte channel); public static native int getPort(byte channel); + + private HAL() { + + } } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java b/hal/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java index a68255c3f2..05f6f4ceb3 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java @@ -8,7 +8,7 @@ package edu.wpi.first.wpilibj.hal; @SuppressWarnings("AbbreviationAsWordInName") -public class HALUtil extends JNIWrapper { +public final class HALUtil extends JNIWrapper { public static final int NULL_PARAMETER = -1005; public static final int SAMPLE_RATE_TOO_HIGH = 1001; public static final int VOLTAGE_OUT_OF_RANGE = 1002; @@ -37,4 +37,8 @@ public class HALUtil extends JNIWrapper { public static String getHALstrerror() { return getHALstrerror(getHALErrno()); } + + private HALUtil() { + + } } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AccelerometerSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AccelerometerSim.java index 97409e6997..ff011d7bf2 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AccelerometerSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AccelerometerSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.AccelerometerDataJNI; public class AccelerometerSim { - private int m_index; + private final int m_index; public AccelerometerSim() { m_index = 0; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogGyroSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogGyroSim.java index 10f555b2d2..72f30007a7 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogGyroSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogGyroSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.AnalogGyroDataJNI; public class AnalogGyroSim { - private int m_index; + private final int m_index; public AnalogGyroSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogInSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogInSim.java index 40135e9fcb..ca3bd7154f 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogInSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogInSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.AnalogInDataJNI; public class AnalogInSim { - private int m_index; + private final int m_index; public AnalogInSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogOutSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogOutSim.java index 643563e355..980d5a17b5 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogOutSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogOutSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.AnalogOutDataJNI; public class AnalogOutSim { - private int m_index; + private final int m_index; public AnalogOutSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogTriggerSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogTriggerSim.java index a4d5f9c448..b445671341 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogTriggerSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/AnalogTriggerSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.AnalogTriggerDataJNI; public class AnalogTriggerSim { - private int m_index; + private final int m_index; public AnalogTriggerSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java index ca3bb53d49..57939d834c 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java @@ -43,7 +43,7 @@ public class CallbackStore implements AutoCloseable { private int index; private int channel; - private int uid; + private final int uid; private CancelCallbackFunc cancelCallback; private CancelCallbackChannelFunc cancelCallbackChannel; private CancelCallbackNoIndexFunc cancelCallbackNoIndex; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/DIOSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/DIOSim.java index 8817e07a8f..11320c5358 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/DIOSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/DIOSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.DIODataJNI; public class DIOSim { - private int m_index; + private final int m_index; public DIOSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/DigitalPWMSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/DigitalPWMSim.java index 0ebd1a55a3..6eb89a7284 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/DigitalPWMSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/DigitalPWMSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.DigitalPWMDataJNI; public class DigitalPWMSim { - private int m_index; + private final int m_index; public DigitalPWMSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/EncoderSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/EncoderSim.java index d9b6aef877..f2161163e2 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/EncoderSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/EncoderSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.EncoderDataJNI; public class EncoderSim { - private int m_index; + private final int m_index; public EncoderSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/I2CSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/I2CSim.java index a88dfe78a7..4f4502afd7 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/I2CSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/I2CSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.I2CDataJNI; public class I2CSim { - private int m_index; + private final int m_index; public I2CSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/NotifyCallback.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/NotifyCallback.java index ab1150808f..1742df1803 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/NotifyCallback.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/NotifyCallback.java @@ -14,21 +14,22 @@ public interface NotifyCallback { switch(type) { case 0x01: callback(name, SimValue.makeBoolean(value1 != 0)); - break; + break; case 0x02: callback(name, SimValue.makeDouble(value2)); - break; + break; case 0x16: callback(name, SimValue.makeEnum((int)value1)); - break; + break; case 0x32: callback(name, SimValue.makeInt((int)value1)); - break; + break; case 0x64: callback(name, SimValue.makeLong(value1)); break; default: callback(name, SimValue.makeUnassigned()); + break; } } } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PCMSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PCMSim.java index 7582dd00fd..f3790d4707 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PCMSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PCMSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.PCMDataJNI; public class PCMSim { - private int m_index; + private final int m_index; public PCMSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PDPSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PDPSim.java index 3cdda0f5f2..565a34347c 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PDPSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PDPSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.PDPDataJNI; public class PDPSim { - private int m_index; + private final int m_index; public PDPSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PWMSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PWMSim.java index 82711bfe5a..81ede7e6d0 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/PWMSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/PWMSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.PWMDataJNI; public class PWMSim { - private int m_index; + private final int m_index; public PWMSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/RelaySim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/RelaySim.java index d897876063..e6aff38262 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/RelaySim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/RelaySim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.RelayDataJNI; public class RelaySim { - private int m_index; + private final int m_index; public RelaySim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/RoboRioSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/RoboRioSim.java index 125407d1ee..45012fee19 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/RoboRioSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/RoboRioSim.java @@ -9,8 +9,9 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.RoboRioDataJNI; +@SuppressWarnings({"PMD.ExcessivePublicCount", "PMD.TooManyMethods"}) public class RoboRioSim { - private int m_index; + private final int m_index; public RoboRioSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPIAccelerometerSim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPIAccelerometerSim.java index c0f4681c68..103928135a 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPIAccelerometerSim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPIAccelerometerSim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.SPIAccelerometerDataJNI; public class SPIAccelerometerSim { - private int m_index; + private final int m_index; public SPIAccelerometerSim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPISim.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPISim.java index 0a5c19fdc3..0a6d3bbe65 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPISim.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SPISim.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.SPIDataJNI; public class SPISim { - private int m_index; + private final int m_index; public SPISim(int index) { m_index = index; diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimHooks.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimHooks.java index ac6b7aff23..f8d5950485 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimHooks.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimHooks.java @@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj.sim; import edu.wpi.first.hal.sim.mockdata.SimulatorJNI; -public class SimHooks { +public final class SimHooks { private SimHooks() { } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimValue.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimValue.java index aa3550dc7b..3d8976324a 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimValue.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/SimValue.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj.sim; -public class SimValue { +public final class SimValue { private boolean v_boolean; private long v_long; private double v_double; diff --git a/ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java b/ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java index 289a3eefd8..547af0ad71 100644 --- a/ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java +++ b/ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java @@ -10,7 +10,7 @@ package edu.wpi.first.ntcore; import edu.wpi.first.networktables.NetworkTablesJNI; import edu.wpi.first.wpiutil.RuntimeDetector; -public class DevMain { +public final class DevMain { /** * Main method. */ @@ -19,4 +19,7 @@ public class DevMain { System.out.println(RuntimeDetector.getPlatformPath()); NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance()); } + + private DevMain() { + } } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java index c880d534df..d59dd212cd 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java @@ -134,6 +134,7 @@ public final class NetworkTable { return m_inst; } + @Override public String toString() { return "NetworkTable: " + m_path; } diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java index 28c933cc0f..b64a7b3daf 100644 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java +++ b/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java @@ -298,6 +298,7 @@ public class NetworkTable implements ITable, IRemote { this.inst = inst; } + @Override public String toString() { return "NetworkTable: " + path; } private final ConcurrentMap entries = new ConcurrentHashMap(); @@ -331,6 +332,7 @@ public class NetworkTable implements ITable, IRemote { * @return True if connected, false if not connected. * @deprecated Use {@link NetworkTableInstance#isConnected()} instead. */ + @Override @Deprecated public boolean isConnected() { return inst.isConnected(); @@ -341,6 +343,7 @@ public class NetworkTable implements ITable, IRemote { * @return True if operating as a server, false otherwise. * @deprecated Use {@link NetworkTableInstance#getNetworkMode()} instead. */ + @Override @Deprecated public boolean isServer() { return (inst.getNetworkMode() & NetworkTableInstance.kNetModeServer) != 0; @@ -369,16 +372,20 @@ public class NetworkTable implements ITable, IRemote { private static final HashMap globalConnectionListenerMap = new HashMap(); private static IRemote staticRemote = new IRemote() { + @Override public void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify) { NetworkTable.addGlobalConnectionListener(listener, immediateNotify); } + @Override public void removeConnectionListener(IRemoteConnectionListener listener) { NetworkTable.removeGlobalConnectionListener(listener); } + @Override public boolean isConnected() { ConnectionInfo[] conns = NetworkTableInstance.getDefault().getConnections(); return conns.length > 0; } + @Override public boolean isServer() { return (NetworkTableInstance.getDefault().getNetworkMode() & NetworkTableInstance.kNetModeServer) != 0; } @@ -420,6 +427,7 @@ public class NetworkTable implements ITable, IRemote { * @param immediateNotify call listener immediately for all existing connections * @deprecated Use {@link NetworkTableInstance#addConnectionListener(Consumer, boolean)} instead. */ + @Override @Deprecated public synchronized void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify) { @@ -435,6 +443,7 @@ public class NetworkTable implements ITable, IRemote { * @param listener connection listener * @deprecated Use {@link NetworkTableInstance#removeConnectionListener(int)} instead. */ + @Override @Deprecated public synchronized void removeConnectionListener(IRemoteConnectionListener listener) { ConnectionListenerAdapter adapter = connectionListenerMap.get(listener); @@ -657,6 +666,7 @@ public class NetworkTable implements ITable, IRemote { return getEntry(key).exists(); } + @Override public boolean containsSubTable(String key) { int[] handles = NetworkTablesJNI.getEntries(inst.getHandle(), pathWithSep + key + PATH_SEPARATOR, 0); return handles.length != 0; @@ -666,6 +676,7 @@ public class NetworkTable implements ITable, IRemote { * @param types bitmask of types; 0 is treated as a "don't care". * @return keys currently in the table */ + @Override public Set getKeys(int types) { Set keys = new HashSet(); int prefixLen = path.length() + 1; @@ -718,6 +729,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultNumber(String key, double defaultValue) { return getEntry(key).setDefaultDouble(defaultValue); } @@ -741,6 +753,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultString(String key, String defaultValue) { return getEntry(key).setDefaultString(defaultValue); } @@ -764,6 +777,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultBoolean(String key, boolean defaultValue) { return getEntry(key).setDefaultBoolean(defaultValue); } @@ -795,6 +809,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultBooleanArray(String key, boolean[] defaultValue) { return getEntry(key).setDefaultBooleanArray(defaultValue); } @@ -802,6 +817,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue) { return getEntry(key).setDefaultBooleanArray(defaultValue); } @@ -841,6 +857,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultNumberArray(String key, double[] defaultValue) { return getEntry(key).setDefaultDoubleArray(defaultValue); } @@ -848,6 +865,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultNumberArray(String key, Double[] defaultValue) { return getEntry(key).setDefaultNumberArray(defaultValue); } @@ -879,6 +897,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultStringArray(String key, String[] defaultValue) { return getEntry(key).setDefaultStringArray(defaultValue); } @@ -902,6 +921,7 @@ public class NetworkTable implements ITable, IRemote { /** * {@inheritDoc} */ + @Override public boolean setDefaultRaw(String key, byte[] defaultValue) { return getEntry(key).setDefaultRaw(defaultValue); } @@ -957,6 +977,7 @@ public class NetworkTable implements ITable, IRemote { * instead, e.g. `NetworkTable.getEntry(key).setValue(NetworkTableEntry.makeBoolean(false));` * or `NetworkTable.getEntry(key).setValue(new Boolean(false));` */ + @Override @Deprecated public boolean putValue(String key, Object value) throws IllegalArgumentException { if (value instanceof Boolean) diff --git a/shared/java/javacommon.gradle b/shared/java/javacommon.gradle index 1140edf806..e614892a69 100644 --- a/shared/java/javacommon.gradle +++ b/shared/java/javacommon.gradle @@ -2,7 +2,6 @@ apply plugin: 'maven-publish' apply plugin: 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' apply plugin: 'java' apply plugin: 'net.ltgt.errorprone' -apply plugin: 'pmd' if (!hasProperty('releaseType')) { WPILibVersion { @@ -98,14 +97,6 @@ if (project.hasProperty('onlyAthena')) { test.enabled = false } -pmd { - sourceSets = [sourceSets.main] - consoleOutput = true - reportsDir = file("$project.buildDir/reports/pmd") - ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml")) - ruleSets = [] -} - repositories { mavenCentral() } diff --git a/shared/java/javastyle.gradle b/shared/java/javastyle.gradle new file mode 100644 index 0000000000..63be640a30 --- /dev/null +++ b/shared/java/javastyle.gradle @@ -0,0 +1,16 @@ + +apply plugin: 'checkstyle' +apply plugin: 'pmd' + +checkstyle { + toolVersion = "8.10" + configFile = new File(rootDir, "styleguide/checkstyle.xml") +} + +pmd { + toolVersion = '6.3.0' + consoleOutput = true + reportsDir = file("$project.buildDir/reports/pmd") + ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml")) + ruleSets = [] +} diff --git a/styleguide/pmd-ruleset.xml b/styleguide/pmd-ruleset.xml index e4ee34d5ef..1656e00fce 100644 --- a/styleguide/pmd-ruleset.xml +++ b/styleguide/pmd-ruleset.xml @@ -4,6 +4,64 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> + PMD Ruleset for WPILib + + .*/*JNI.* + .*/*Test.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The single DriverStation instance is created statically with the instance static member * variable. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private DriverStation() { HAL.initialize(500, 0); m_waitForDataCount = 0; @@ -277,12 +283,12 @@ public class DriverStation implements RobotState.Interface { } else { locString = ""; } - String traceString = ""; + StringBuilder traceString = new StringBuilder(""); if (printTrace) { boolean haveLoc = false; for (int i = stackTraceFirst; i < stackTrace.length; i++) { String loc = stackTrace[i].toString(); - traceString += "\tat " + loc + "\n"; + traceString.append("\tat ").append(loc).append('\n'); // get first user function if (!haveLoc && !loc.startsWith("edu.wpi.first")) { locString = loc; @@ -290,7 +296,7 @@ public class DriverStation implements RobotState.Interface { } } } - HAL.sendError(isError, code, false, error, locString, traceString, true); + HAL.sendError(isError, code, false, error, locString, traceString.toString(), true); } /** @@ -302,7 +308,7 @@ public class DriverStation implements RobotState.Interface { */ public boolean getStickButton(final int stick, final int button) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-3"); } if (button <= 0) { reportJoystickUnpluggedError("Button indexes begin at 1 in WPILib for C++ and Java\n"); @@ -338,7 +344,7 @@ public class DriverStation implements RobotState.Interface { return false; } if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-3"); } boolean error = false; boolean retVal = false; @@ -377,7 +383,7 @@ public class DriverStation implements RobotState.Interface { return false; } if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-3"); } boolean error = false; boolean retVal = false; @@ -412,10 +418,10 @@ public class DriverStation implements RobotState.Interface { */ public double getStickAxis(int stick, int axis) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } if (axis >= HAL.kMaxJoystickAxes) { - throw new RuntimeException("Joystick axis is out of range"); + throw new IllegalArgumentException("Joystick axis is out of range"); } m_cacheDataMutex.lock(); @@ -443,10 +449,10 @@ public class DriverStation implements RobotState.Interface { */ public int getStickPOV(int stick, int pov) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } if (pov >= HAL.kMaxJoystickPOVs) { - throw new RuntimeException("Joystick POV is out of range"); + throw new IllegalArgumentException("Joystick POV is out of range"); } m_cacheDataMutex.lock(); @@ -474,7 +480,7 @@ public class DriverStation implements RobotState.Interface { */ public int getStickButtons(final int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-3"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-3"); } m_cacheDataMutex.lock(); @@ -493,7 +499,7 @@ public class DriverStation implements RobotState.Interface { */ public int getStickAxisCount(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -512,7 +518,7 @@ public class DriverStation implements RobotState.Interface { */ public int getStickPOVCount(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -531,7 +537,7 @@ public class DriverStation implements RobotState.Interface { */ public int getStickButtonCount(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -550,7 +556,7 @@ public class DriverStation implements RobotState.Interface { */ public boolean getJoystickIsXbox(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -569,7 +575,7 @@ public class DriverStation implements RobotState.Interface { */ public int getJoystickType(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -588,7 +594,7 @@ public class DriverStation implements RobotState.Interface { */ public String getJoystickName(int stick) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -608,7 +614,7 @@ public class DriverStation implements RobotState.Interface { */ public int getJoystickAxisType(int stick, int axis) { if (stick < 0 || stick >= kJoystickPorts) { - throw new RuntimeException("Joystick index is out of range, should be 0-5"); + throw new IllegalArgumentException("Joystick index is out of range, should be 0-5"); } m_cacheDataMutex.lock(); @@ -624,6 +630,7 @@ public class DriverStation implements RobotState.Interface { * * @return True if the robot is enabled, false otherwise. */ + @Override public boolean isEnabled() { synchronized (m_controlWordMutex) { updateControlWord(false); @@ -636,6 +643,7 @@ public class DriverStation implements RobotState.Interface { * * @return True if the robot should be disabled, false otherwise. */ + @Override public boolean isDisabled() { return !isEnabled(); } @@ -646,6 +654,7 @@ public class DriverStation implements RobotState.Interface { * * @return True if autonomous mode should be enabled, false otherwise. */ + @Override public boolean isAutonomous() { synchronized (m_controlWordMutex) { updateControlWord(false); @@ -659,6 +668,7 @@ public class DriverStation implements RobotState.Interface { * * @return True if operator-controlled mode should be enabled, false otherwise. */ + @Override public boolean isOperatorControl() { return !(isAutonomous() || isTest()); } @@ -669,6 +679,7 @@ public class DriverStation implements RobotState.Interface { * * @return True if test mode should be enabled, false otherwise. */ + @Override public boolean isTest() { synchronized (m_controlWordMutex) { updateControlWord(false); @@ -1139,7 +1150,8 @@ public class DriverStation implements RobotState.Interface { safetyCounter = 0; } - if (++safetyCounter >= 4) { + safetyCounter++; + if (safetyCounter >= 4) { MotorSafetyHelper.checkMotors(); safetyCounter = 0; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java index 5feeae8ba2..52ef0622d9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -53,7 +53,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { /** * The index source. */ - protected DigitalSource m_indexSource = null; // Index on some encoders + protected DigitalSource m_indexSource; // Index on some encoders private boolean m_allocatedA; private boolean m_allocatedB; private boolean m_allocatedI; @@ -329,6 +329,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * * @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor. */ + @Override public int get() { return EncoderJNI.getEncoder(m_encoder); } @@ -336,6 +337,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { /** * Reset the Encoder distance to zero. Resets the current count to zero on the encoder. */ + @Override public void reset() { EncoderJNI.resetEncoder(m_encoder); } @@ -350,6 +352,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * @return Period in seconds of the most recent pulse. * @deprecated Use getRate() in favor of this method. */ + @Override @Deprecated public double getPeriod() { return EncoderJNI.getEncoderPeriod(m_encoder); @@ -364,6 +367,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * @param maxPeriod The maximum time between rising and falling edges before the FPGA will report * the device stopped. This is expressed in seconds. */ + @Override public void setMaxPeriod(double maxPeriod) { EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod); } @@ -375,6 +379,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * * @return True if the encoder is considered stopped. */ + @Override public boolean getStopped() { return EncoderJNI.getEncoderStopped(m_encoder); } @@ -384,6 +389,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * * @return The last direction the encoder value changed. */ + @Override public boolean getDirection() { return EncoderJNI.getEncoderDirection(m_encoder); } @@ -478,6 +484,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * * @param pidSource An enum to select the parameter. */ + @Override public void setPIDSourceType(PIDSourceType pidSource) { m_pidSource = pidSource; } @@ -492,6 +499,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource { * * @return The current value of the selected source parameter. */ + @Override public double pidGet() { switch (m_pidSource) { case kDisplacement: diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GamepadBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GamepadBase.java index 0d3387da37..8e878eab1d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GamepadBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GamepadBase.java @@ -18,6 +18,7 @@ public abstract class GamepadBase extends GenericHID { super(port); } + @Override public abstract double getRawAxis(int axis); /** @@ -43,19 +44,27 @@ public abstract class GamepadBase extends GenericHID { return getStickButton(Hand.kRight); } + @Override public abstract boolean getRawButton(int button); + @Override public abstract int getPOV(int pov); + @Override public abstract int getPOVCount(); + @Override public abstract HIDType getType(); + @Override public abstract String getName(); + @Override public abstract void setOutput(int outputNumber, boolean value); + @Override public abstract void setOutputs(int value); + @Override public abstract void setRumble(RumbleType type, double value); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GenericHID.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GenericHID.java index 6b3ef31cfe..43eee587e2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GenericHID.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GenericHID.java @@ -44,6 +44,7 @@ public abstract class GenericHID { @SuppressWarnings("MemberName") public final int value; + @SuppressWarnings("PMD.UseConcurrentHashMap") private static final Map map = new HashMap<>(); HIDType(int value) { @@ -57,7 +58,7 @@ public abstract class GenericHID { } public static HIDType of(int value) { - return (HIDType) map.get(value); + return map.get(value); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java index 3eca63b929..8b4d9d240d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; * Support for high level usage reporting. */ @SuppressWarnings("JavadocMethod") -public class HLUsageReporting { +public final class HLUsageReporting { private static Interface impl; @SuppressWarnings("MethodName") @@ -54,14 +54,20 @@ public class HLUsageReporting { } public static class Null implements Interface { + @Override public void reportScheduler() { } + @Override @SuppressWarnings("PMD.UnusedFormalParameter") public void reportPIDController(int num) { } + @Override public void reportSmartDashboard() { } } + + private HLUsageReporting() { + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java index ee1d226e66..f9c5921f83 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java @@ -22,6 +22,7 @@ import static java.util.Objects.requireNonNull; *

This class is intended to be used by sensor (and other I2C device) drivers. It probably should * not be used directly. */ +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) public class I2C implements AutoCloseable { public enum Port { kOnboard(0), kMXP(1); @@ -99,6 +100,7 @@ public class I2C implements AutoCloseable { * @param receiveSize Number of bytes to read from the device. * @return Transfer Aborted... false for success, true for aborted. */ + @SuppressWarnings("PMD.CyclomaticComplexity") public synchronized boolean transaction(ByteBuffer dataToSend, int sendSize, ByteBuffer dataReceived, int receiveSize) { if (dataToSend.hasArray() && dataReceived.hasArray()) { @@ -231,7 +233,7 @@ public class I2C implements AutoCloseable { return transaction(registerAddressArray, registerAddressArray.length, buffer, count); } - private ByteBuffer m_readDataToSendBuffer = null; + private ByteBuffer m_readDataToSendBuffer; /** * Execute a read transaction with the device. @@ -352,12 +354,11 @@ public class I2C implements AutoCloseable { byte[] dataToSend = new byte[1]; byte[] deviceData = new byte[4]; - for (int i = 0, curRegisterAddress = registerAddress; - i < count; i += 4, curRegisterAddress += 4) { + for (int i = 0; i < count; i += 4) { int toRead = count - i < 4 ? count - i : 4; // Read the chunk of data. Return false if the sensor does not // respond. - dataToSend[0] = (byte) curRegisterAddress; + dataToSend[0] = (byte) (registerAddress + i); if (transaction(dataToSend, 1, deviceData, toRead)) { return false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java index d6627c610f..b4c0631b39 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java @@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.util.AllocationException; /** * Base for sensors to be used with interrupts. */ +@SuppressWarnings("PMD.TooManyMethods") public abstract class InterruptableSensorBase extends SendableBase { @SuppressWarnings("JavadocMethod") public enum WaitResult { @@ -35,7 +36,7 @@ public abstract class InterruptableSensorBase extends SendableBase { /** * Flags if the interrupt being allocated is synchronous. */ - protected boolean m_isSynchronousInterrupt = false; + protected boolean m_isSynchronousInterrupt; /** * Create a new InterrupatableSensorBase. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java index 10ddd4bdc9..9473e9db3c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -27,6 +27,7 @@ public class IterativeRobot extends IterativeRobotBase { /** * Provide an alternate "main loop" via startCompetition(). */ + @Override public void startCompetition() { robotInit(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java index 16d5b13021..31d86e9e7b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java @@ -40,6 +40,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; * - teleopPeriodic() * - testPeriodic() */ +@SuppressWarnings("PMD.TooManyMethods") public abstract class IterativeRobotBase extends RobotBase { private enum Mode { kNone, @@ -54,6 +55,7 @@ public abstract class IterativeRobotBase extends RobotBase { /** * Provide an alternate "main loop" via startCompetition(). */ + @Override public abstract void startCompetition(); /* ----------- Overridable initialization code ----------------- */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java index ff75e5ef2e..bf972c911a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java @@ -21,6 +21,7 @@ public interface NamedSendable extends Sendable { * * @return the name of the subtable of SmartDashboard that the Sendable object will use. */ + @Override String getName(); @Override diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java index 0fa0422935..98e2ddeb49 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java @@ -16,11 +16,11 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; */ public class NidecBrushless extends SendableBase implements SpeedController, MotorSafety, Sendable { private final MotorSafetyHelper m_safetyHelper; - private boolean m_isInverted = false; - private DigitalOutput m_dio; - private PWM m_pwm; - private volatile double m_speed = 0.0; - private volatile boolean m_disabled = false; + private boolean m_isInverted; + private final DigitalOutput m_dio; + private final PWM m_pwm; + private volatile double m_speed; + private volatile boolean m_disabled; /** * Constructor. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java index f1d33aac90..aca531229e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java @@ -22,15 +22,15 @@ public class Notifier implements AutoCloseable { private final AtomicInteger m_notifier = new AtomicInteger(); // The time, in microseconds, at which the corresponding handler should be // called. Has the same zero as Utility.getFPGATime(). - private double m_expirationTime = 0; + private double m_expirationTime; // The handler passed in by the user which should be called at the // appropriate interval. private Runnable m_handler; // Whether we are calling the handler just once or periodically. - private boolean m_periodic = false; + private boolean m_periodic; // If periodic, the period of the calling; if just once, stores how long it // is until we call the handler. - private double m_period = 0; + private double m_period; @Override @SuppressWarnings("NoFinalizer") diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java index c4e3dbc8d1..ace6027031 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java @@ -25,9 +25,10 @@ import static java.util.Objects.requireNonNull; * and derivative calculations. Therefore, the sample rate affects the controller's behavior for a * given set of PID constants. */ +@SuppressWarnings("PMD.TooManyFields") public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { public static final double kDefaultPeriod = 0.05; - private static int instances = 0; + private static int instances; // Factor for "proportional" control @SuppressWarnings("MemberName") @@ -52,34 +53,34 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { private double m_minimumOutput = -1.0; // Maximum input - limit setpoint to this - private double m_maximumInput = 0.0; + private double m_maximumInput; // Minimum input - limit setpoint to this - private double m_minimumInput = 0.0; + private double m_minimumInput; // Input range - difference between maximum and minimum - private double m_inputRange = 0.0; + private double m_inputRange; // Do the endpoints wrap around? (e.g., absolute encoder) - private boolean m_continuous = false; + private boolean m_continuous; // Is the PID controller enabled - protected boolean m_enabled = false; + protected boolean m_enabled; // The prior error (used to compute velocity) - private double m_prevError = 0.0; + private double m_prevError; // The sum of the errors for use in the integral calc - private double m_totalError = 0.0; + private double m_totalError; // The tolerance object used to check if on target private Tolerance m_tolerance; - private double m_setpoint = 0.0; - private double m_prevSetpoint = 0.0; + private double m_setpoint; + private double m_prevSetpoint; @SuppressWarnings("PMD.UnusedPrivateField") - private double m_error = 0.0; - private double m_result = 0.0; + private double m_error; + private double m_result; private PIDSource m_origSource; private LinearDigitalFilter m_filter; @@ -110,7 +111,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { public class NullTolerance implements Tolerance { @Override public boolean onTarget() { - throw new RuntimeException("No tolerance value set when calling onTarget()."); + throw new IllegalStateException("No tolerance value set when calling onTarget()."); } } @@ -198,7 +199,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * Read the input, calculate the output accordingly, and write to the output. This should only be * called by the PIDTask and is created during initialization. */ - @SuppressWarnings("LocalVariableName") + @SuppressWarnings({"LocalVariableName", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) protected void calculate() { if (m_origSource == null || m_pidOutput == null) { return; @@ -334,6 +335,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * @param i Integral coefficient * @param d Differential coefficient */ + @Override @SuppressWarnings("ParameterName") public void setPID(double p, double i, double d) { m_thisMutex.lock(); @@ -433,6 +435,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @return proportional coefficient */ + @Override public double getP() { m_thisMutex.lock(); try { @@ -447,6 +450,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @return integral coefficient */ + @Override public double getI() { m_thisMutex.lock(); try { @@ -461,6 +465,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @return differential coefficient */ + @Override public double getD() { m_thisMutex.lock(); try { @@ -508,7 +513,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { */ public void setContinuous(boolean continuous) { if (continuous && m_inputRange <= 0) { - throw new RuntimeException("No input range set when calling setContinuous()."); + throw new IllegalStateException("No input range set when calling setContinuous()."); } m_thisMutex.lock(); try { @@ -573,6 +578,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @param setpoint the desired setpoint */ + @Override public void setSetpoint(double setpoint) { m_thisMutex.lock(); try { @@ -597,6 +603,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @return the current setpoint */ + @Override public double getSetpoint() { m_thisMutex.lock(); try { @@ -625,6 +632,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { * * @return the current error */ + @Override public double getError() { m_thisMutex.lock(); try { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java index 668dcdae16..cdc016d796 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java @@ -43,7 +43,7 @@ public class PWM extends SendableBase { k4X } - private int m_channel; + private final int m_channel; private int m_handle; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java index 01466dfb13..d0c5777c0c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * Common base class for all PWM Speed Controllers. */ public abstract class PWMSpeedController extends SafePWM implements SpeedController { - private boolean m_isInverted = false; + private boolean m_isInverted; /** * Constructor. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java index 4af3b053c6..d519ca024d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java @@ -31,7 +31,7 @@ import static java.util.Objects.requireNonNull; *

This will also interact with {@link NetworkTable} by creating a table called "Preferences" * with all the key-value pairs.

*/ -public class Preferences { +public final class Preferences { /** * The Preferences table name. */ @@ -75,6 +75,7 @@ public class Preferences { * Gets the vector of keys. * @return a vector of the keys */ + @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"}) public Vector getKeys() { return new Vector<>(m_table.getKeys()); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java index 8615b79afc..c8dfff1746 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java @@ -90,8 +90,8 @@ public class Relay extends SendableBase implements MotorSafety { private final int m_channel; - private int m_forwardHandle = 0; - private int m_reverseHandle = 0; + private int m_forwardHandle; + private int m_reverseHandle; private Direction m_direction; @@ -150,12 +150,12 @@ public class Relay extends SendableBase implements MotorSafety { private void freeRelay() { try { RelayJNI.setRelay(m_forwardHandle, false); - } catch (UncleanStatusException ex) { + } catch (UncleanStatusException ignored) { // do nothing. Ignore } try { RelayJNI.setRelay(m_reverseHandle, false); - } catch (UncleanStatusException ex) { + } catch (UncleanStatusException ignored) { // do nothing. Ignore } @@ -179,6 +179,7 @@ public class Relay extends SendableBase implements MotorSafety { * * @param value The state to set the relay. */ + @SuppressWarnings("PMD.CyclomaticComplexity") public void set(Value value) { switch (value) { case kOff: diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Resource.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Resource.java index 4e9ebb1860..aa82bbc35d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Resource.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Resource.java @@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException; * unload/reload. */ public final class Resource { - private static Resource resourceList = null; + private static Resource resourceList; private final boolean[] m_numAllocated; private final int m_size; private final Resource m_nextResource; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index d3fe384c50..5a54a7d2f4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -8,9 +8,10 @@ package edu.wpi.first.wpilibj; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.URL; +import java.nio.file.Files; import java.util.Enumeration; import java.util.jar.Manifest; @@ -188,9 +189,9 @@ public abstract class RobotBase implements AutoCloseable { if (propVal == null) { return defaultValue; } - if (propVal.equalsIgnoreCase("false")) { + if ("false".equalsIgnoreCase(propVal)) { return false; - } else if (propVal.equalsIgnoreCase("true")) { + } else if ("true".equalsIgnoreCase(propVal)) { return true; } else { throw new IllegalStateException(propVal); @@ -218,7 +219,8 @@ public abstract class RobotBase implements AutoCloseable { /** * Starting point for the applications. */ - @SuppressWarnings("PMD.UnusedFormalParameter") + @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable", + "PMD.CyclomaticComplexity", "PMD.NPathComplexity"}) public static void main(String... args) { if (!HAL.initialize(500, 0)) { throw new IllegalStateException("Failed to initialize. Terminating"); @@ -232,7 +234,8 @@ public abstract class RobotBase implements AutoCloseable { } else { Enumeration resources = null; try { - resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); + resources = Thread.currentThread() + .getContextClassLoader().getResources("META-INF/MANIFEST.MF"); } catch (IOException ex) { ex.printStackTrace(); } @@ -273,7 +276,7 @@ public abstract class RobotBase implements AutoCloseable { file.createNewFile(); - try (FileOutputStream output = new FileOutputStream(file)) { + try (OutputStream output = Files.newOutputStream(file.toPath())) { output.write("Java ".getBytes()); output.write(WPILibVersion.Version.getBytes()); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java index 8c69eff9b7..114592d40a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java @@ -25,6 +25,7 @@ import static java.util.Objects.requireNonNull; * or {@link edu.wpi.first.wpilibj.drive.MecanumDrive} classes instead. */ @Deprecated +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) public class RobotDrive implements MotorSafety, AutoCloseable { protected MotorSafetyHelper m_safetyHelper; @@ -53,11 +54,11 @@ public class RobotDrive implements MotorSafety, AutoCloseable { protected SpeedController m_rearLeftMotor; protected SpeedController m_rearRightMotor; protected boolean m_allocatedSpeedControllers; - protected static boolean kArcadeRatioCurve_Reported = false; - protected static boolean kTank_Reported = false; - protected static boolean kArcadeStandard_Reported = false; - protected static boolean kMecanumCartesian_Reported = false; - protected static boolean kMecanumPolar_Reported = false; + protected static boolean kArcadeRatioCurve_Reported; + protected static boolean kTank_Reported; + protected static boolean kArcadeStandard_Reported; + protected static boolean kMecanumCartesian_Reported; + protected static boolean kMecanumPolar_Reported; /** * Constructor for RobotDrive with 2 motors specified with channel numbers. Set up parameters for diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java index 98d847f79f..652106859b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; @SuppressWarnings("JavadocMethod") -public class RobotState { +public final class RobotState { private static Interface m_impl; @SuppressWarnings("MethodName") @@ -69,4 +69,7 @@ public class RobotState { boolean isTest(); } + + private RobotState() { + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java index 525a5d6913..aebfec7a78 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java @@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.hal.SPIJNI; /** * Represents a SPI bus port. */ +@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.TooManyMethods"}) public class SPI implements AutoCloseable { public enum Port { kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4); @@ -28,7 +29,7 @@ public class SPI implements AutoCloseable { } } - private static int devices = 0; + private static int devices; private int m_port; private int m_bitOrder; @@ -268,6 +269,7 @@ public class SPI implements AutoCloseable { * @param dataReceived Buffer to receive data from the device. * @param size The length of the transaction, in bytes */ + @SuppressWarnings("PMD.CyclomaticComplexity") public int transaction(ByteBuffer dataToSend, ByteBuffer dataReceived, int size) { if (dataToSend.hasArray() && dataReceived.hasArray()) { return transaction(dataToSend.array(), dataReceived.array(), size); @@ -420,6 +422,7 @@ public class SPI implements AutoCloseable { private static final int kAccumulateDepth = 2048; + @SuppressWarnings("PMD.TooManyFields") private static class Accumulator implements AutoCloseable { Accumulator(int port, int xferSize, int validMask, int validValue, int dataShift, int dataSize, boolean isSigned, boolean bigEndian) { @@ -462,6 +465,7 @@ public class SPI implements AutoCloseable { final boolean m_bigEndian; // is response big endian? final int m_port; + @SuppressWarnings("PMD.CyclomaticComplexity") void update() { synchronized (m_mutex) { boolean done = false; @@ -527,7 +531,7 @@ public class SPI implements AutoCloseable { } } - private Accumulator m_accum = null; + private Accumulator m_accum; /** * Initialize the accumulator. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SafePWM.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SafePWM.java index f48ddb1848..a0a692a5cc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SafePWM.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SafePWM.java @@ -32,6 +32,7 @@ public class SafePWM extends PWM implements MotorSafety { * * @param timeout The timeout (in seconds) for this motor object */ + @Override public void setExpiration(double timeout) { m_safetyHelper.setExpiration(timeout); } @@ -41,6 +42,7 @@ public class SafePWM extends PWM implements MotorSafety { * * @return The expiration time value. */ + @Override public double getExpiration() { return m_safetyHelper.getExpiration(); } @@ -50,6 +52,7 @@ public class SafePWM extends PWM implements MotorSafety { * * @return a bool value that is true if the motor has NOT timed out and should still be running. */ + @Override public boolean isAlive() { return m_safetyHelper.isAlive(); } @@ -58,6 +61,7 @@ public class SafePWM extends PWM implements MotorSafety { * Stop the motor associated with this PWM object. This is called by the MotorSafetyHelper object * when it has a timeout for this PWM and needs to stop it from running. */ + @Override public void stopMotor() { disable(); } @@ -67,6 +71,7 @@ public class SafePWM extends PWM implements MotorSafety { * * @return True if motor safety is enforced for this object */ + @Override public boolean isSafetyEnabled() { return m_safetyHelper.isSafetyEnabled(); } @@ -91,10 +96,12 @@ public class SafePWM extends PWM implements MotorSafety { m_safetyHelper.feed(); } + @Override public void setSafetyEnabled(boolean enabled) { m_safetyHelper.setSafetyEnabled(enabled); } + @Override public String getDescription() { return "PWM " + getChannel(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java index 2ff7c2dee7..d35ee19dd7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java @@ -114,6 +114,8 @@ public class SampleRobot extends RobotBase { * state to change, either the other mode starts or the robot is disabled. Then go back and wait * for the robot to be enabled again. */ + @SuppressWarnings("PMD.CyclomaticComplexity") + @Override public void startCompetition() { robotInit(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java index 0999360e3b..ba35220789 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -24,6 +24,7 @@ import edu.wpi.first.wpilibj.hal.SerialPortJNI; * .com/pdf/manuals/370423a.pdf and the NI-VISA Programmer's Reference Manual here: * http://www.ni.com/pdf/manuals/370132c.pdf */ +@SuppressWarnings("PMD.TooManyMethods") public class SerialPort implements AutoCloseable { private byte m_port; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java index 75dff5892d..774761363e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java @@ -13,15 +13,16 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * Allows multiple {@link SpeedController} objects to be linked together. */ public class SpeedControllerGroup extends SendableBase implements SpeedController { - private boolean m_isInverted = false; + private boolean m_isInverted; private final SpeedController[] m_speedControllers; - private static int instances = 0; + private static int instances; /** * Create a new SpeedControllerGroup with the provided SpeedControllers. * * @param speedControllers The SpeedControllers to add */ + @SuppressWarnings("PMD.AvoidArrayLoops") public SpeedControllerGroup(SpeedController speedController, SpeedController... speedControllers) { m_speedControllers = new SpeedController[speedControllers.length + 1]; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Threads.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Threads.java index 5d455e2f55..6a396a633a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Threads.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Threads.java @@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.hal.ThreadsJNI; -public class Threads { +public final class Threads { /** * Get the thread priority for the current thread. * @return The current thread priority. Scaled 1-99. @@ -39,4 +39,7 @@ public class Threads { public static boolean setCurrentThreadPriority(boolean realTime, int priority) { return ThreadsJNI.setCurrentThreadPriority(realTime, priority); } + + private Threads() { + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java index fda5d1b24c..5ad6011142 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java @@ -23,14 +23,14 @@ public class TimedRobot extends IterativeRobotBase { public static final double kDefaultPeriod = 0.02; // Prevents loop from starting if user calls setPeriod() in robotInit() - private boolean m_startLoop = false; + private boolean m_startLoop; // The C pointer to the notifier object. We don't use it directly, it is // just passed to the JNI bindings. private final int m_notifier = NotifierJNI.initializeNotifier(); // The absolute expiration time - private double m_expirationTime = 0; + private double m_expirationTime; private double m_period = kDefaultPeriod; @@ -49,6 +49,7 @@ public class TimedRobot extends IterativeRobotBase { /** * Provide an alternate "main loop" via startCompetition(). */ + @Override public void startCompetition() { robotInit(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java index 4b30a36800..dd8129a1c3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java @@ -41,19 +41,19 @@ public class Ultrasonic extends SendableBase implements PIDSource { private static final double kPingTime = 10 * 1e-6; private static final double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0; // head of the ultrasonic sensor list - private static Ultrasonic m_firstSensor = null; + private static Ultrasonic m_firstSensor; // automatic round robin mode - private static boolean m_automaticEnabled = false; + private static boolean m_automaticEnabled; private DigitalInput m_echoChannel; - private DigitalOutput m_pingChannel = null; + private DigitalOutput m_pingChannel; private boolean m_allocatedChannels; - private boolean m_enabled = false; - private Counter m_counter = null; - private Ultrasonic m_nextSensor = null; + private boolean m_enabled; + private Counter m_counter; + private Ultrasonic m_nextSensor; // task doing the round-robin automatic sensing - private static Thread m_task = null; + private static Thread m_task; private Unit m_units; - private static int m_instances = 0; + private static int m_instances; protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; /** @@ -190,6 +190,7 @@ public class Ultrasonic extends SendableBase implements PIDSource { * stopped, then started again after this sensor is removed (provided this wasn't the last * sensor). */ + @SuppressWarnings("PMD.CyclomaticComplexity") @Override public synchronized void close() { super.close(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java index 140ce369d2..308a4d8cb2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java @@ -33,7 +33,7 @@ public class XboxController extends GenericHID { kBack(7), kStart(8); - @SuppressWarnings("MemberName") + @SuppressWarnings({"MemberName", "PMD.SingularField"}) private int value; Button(int value) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java index a44df17cd5..bb1eff7d63 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java @@ -40,6 +40,7 @@ public class InternalButton extends Button { m_pressed = pressed; } + @Override public boolean get() { return m_pressed ^ m_inverted; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java index 516f6ad2c4..db0d4c65fc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java @@ -33,6 +33,7 @@ public class JoystickButton extends Button { * * @return The value of the joystick button */ + @Override public boolean get() { return m_joystick.getRawButton(m_buttonNumber); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java index 90a1593025..2fa79247bf 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java @@ -25,6 +25,7 @@ public class NetworkButton extends Button { m_entry = table.getEntry(field); } + @Override public boolean get() { return m_entry.getInstance().isConnected() && m_entry.getBoolean(false); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java index 1e686950d4..51f4a9d858 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java @@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * the full functionality of the Trigger class. */ public abstract class Trigger extends SendableBase { - private volatile boolean m_sendablePressed = false; + private volatile boolean m_sendablePressed; /** * Returns whether or not the trigger is active. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java index ab8c9835b7..57db307961 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java @@ -39,6 +39,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * @see CommandGroup * @see IllegalUseOfCommandException */ +@SuppressWarnings("PMD.TooManyMethods") public abstract class Command extends SendableBase { /** * The time since this command was initialized. @@ -53,7 +54,7 @@ public abstract class Command extends SendableBase { /** * Whether or not this command has been initialized. */ - private boolean m_initialized = false; + private boolean m_initialized; /** * The required subsystems. @@ -63,7 +64,7 @@ public abstract class Command extends SendableBase { /** * Whether or not it is running. */ - private boolean m_running = false; + private boolean m_running; /** * Whether or not it is interruptible. @@ -73,22 +74,22 @@ public abstract class Command extends SendableBase { /** * Whether or not it has been canceled. */ - private boolean m_canceled = false; + private boolean m_canceled; /** * Whether or not it has been locked. */ - private boolean m_locked = false; + private boolean m_locked; /** * Whether this command should run when the robot is disabled. */ - private boolean m_runWhenDisabled = false; + private boolean m_runWhenDisabled; /** * Whether or not this command has completed running. */ - private boolean m_completed = false; + private boolean m_completed; /** * The {@link CommandGroup} this is in. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java index 4e251bc316..53b62eebdc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java @@ -31,10 +31,12 @@ import static java.util.Objects.requireNonNull; * @see Subsystem * @see IllegalUseOfCommandException */ +@SuppressWarnings("PMD.TooManyMethods") public class CommandGroup extends Command { /** * The commands in this group (stored in entries). */ + @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"}) private final Vector m_commands = new Vector<>(); /* * Intentionally package private @@ -42,6 +44,7 @@ public class CommandGroup extends Command { /** * The active children in this group (stored in entries). */ + @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"}) final Vector m_children = new Vector<>(); /** * The current command, -1 signifies that none have been run. @@ -206,12 +209,14 @@ public class CommandGroup extends Command { } } + @Override @SuppressWarnings("MethodName") void _initialize() { m_currentCommandIndex = -1; } - @SuppressWarnings("MethodName") + @Override + @SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"}) void _execute() { Entry entry = null; Command cmd = null; @@ -278,6 +283,7 @@ public class CommandGroup extends Command { } } + @Override @SuppressWarnings("MethodName") void _end() { // Theoretically, we don't have to check this, but we do if teams override @@ -297,6 +303,7 @@ public class CommandGroup extends Command { m_children.removeAllElements(); } + @Override @SuppressWarnings("MethodName") void _interrupted() { _end(); @@ -311,23 +318,28 @@ public class CommandGroup extends Command { * * @return whether this {@link CommandGroup} is finished */ + @Override protected boolean isFinished() { return m_currentCommandIndex >= m_commands.size() && m_children.isEmpty(); } // Can be overwritten by teams + @Override protected void initialize() { } // Can be overwritten by teams + @Override protected void execute() { } // Can be overwritten by teams + @Override protected void end() { } // Can be overwritten by teams + @Override protected void interrupted() { } @@ -338,6 +350,7 @@ public class CommandGroup extends Command { * * @return whether or not this {@link CommandGroup} is interruptible. */ + @Override public synchronized boolean isInterruptible() { if (!super.isInterruptible()) { return false; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java index 9d06d3d439..3c64ef9ef2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java @@ -45,7 +45,7 @@ public abstract class ConditionalCommand extends Command { /** * Stores command chosen by condition. */ - private Command m_chosenCommand = null; + private Command m_chosenCommand; private void requireAll() { if (m_onTrue != null) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java index ca27472664..389b78fcc8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java @@ -25,6 +25,7 @@ public class InstantCommand extends Command { super(name); } + @Override protected boolean isFinished() { return true; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java index b6a89dd0b4..99d37a6d50 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java @@ -33,13 +33,16 @@ public abstract class PIDCommand extends Command { * A source which calls {@link PIDCommand#returnPIDInput()}. */ private final PIDSource m_source = new PIDSource() { + @Override public void setPIDSourceType(PIDSourceType pidSource) { } + @Override public PIDSourceType getPIDSourceType() { return PIDSourceType.kDisplacement; } + @Override public double pidGet() { return returnPIDInput(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java index 754e233347..3c53e008a0 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java @@ -35,13 +35,16 @@ public abstract class PIDSubsystem extends Subsystem { * A source which calls {@link PIDCommand#returnPIDInput()}. */ private final PIDSource m_source = new PIDSource() { + @Override public void setPIDSourceType(PIDSourceType pidSource) { } + @Override public PIDSourceType getPIDSourceType() { return PIDSourceType.kDisplacement; } + @Override public double pidGet() { return returnPIDInput(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java index 35826708c4..6199c6d2fc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java @@ -16,7 +16,7 @@ public class PrintCommand extends InstantCommand { /** * The message to print out. */ - private String m_message; + private final String m_message; /** * Instantiates a {@link PrintCommand} which will print the given message when it is run. @@ -28,6 +28,7 @@ public class PrintCommand extends InstantCommand { m_message = message; } + @Override protected void initialize() { System.out.println(m_message); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java index a213f95d00..a71e477374 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java @@ -29,7 +29,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * * @see Command */ -public class Scheduler extends SendableBase { +public final class Scheduler extends SendableBase { /** * The Singleton Instance. */ @@ -50,11 +50,12 @@ public class Scheduler extends SendableBase { /** * A hashtable of active {@link Command Commands} to their {@link LinkedListElement}. */ - private Hashtable m_commandTable = new Hashtable<>(); + @SuppressWarnings("PMD.LooseCoupling") + private final Hashtable m_commandTable = new Hashtable<>(); /** * The {@link Set} of all {@link Subsystem Subsystems}. */ - private Set m_subsystems = new Set(); + private final Set m_subsystems = new Set(); /** * The first {@link Command} in the list. */ @@ -66,15 +67,16 @@ public class Scheduler extends SendableBase { /** * Whether or not we are currently adding a command. */ - private boolean m_adding = false; + private boolean m_adding; /** * Whether or not we are currently disabled. */ - private boolean m_disabled = false; + private boolean m_disabled; /** * A list of all {@link Command Commands} which need to be added. */ - private Vector m_additions = new Vector<>(); + @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"}) + private final Vector m_additions = new Vector<>(); private NetworkTableEntry m_namesEntry; private NetworkTableEntry m_idsEntry; private NetworkTableEntry m_cancelEntry; @@ -82,6 +84,7 @@ public class Scheduler extends SendableBase { * A list of all {@link edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler Buttons}. It is * created lazily. */ + @SuppressWarnings("PMD.LooseCoupling") private Vector m_buttons; private boolean m_runningCommandsChanged; @@ -115,6 +118,7 @@ public class Scheduler extends SendableBase { * * @param button the button to add */ + @SuppressWarnings("PMD.UseArrayListInsteadOfVector") public void addButton(ButtonScheduler button) { if (m_buttons == null) { m_buttons = new Vector<>(); @@ -129,7 +133,7 @@ public class Scheduler extends SendableBase { * * @param command the {@link Command} to add */ - @SuppressWarnings("MethodName") + @SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity"}) private void _add(Command command) { if (command == null) { return; @@ -189,6 +193,7 @@ public class Scheduler extends SendableBase { *
  1. Poll the Buttons
  2. Execute/Remove the Commands
  3. Send values to * SmartDashboard
  4. Add Commands
  5. Add Defaults
*/ + @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"}) public void run() { m_runningCommandsChanged = false; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java index dcd720033d..6dd7db836f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java @@ -15,7 +15,7 @@ public class StartCommand extends InstantCommand { /** * The command to fork. */ - private Command m_commandToFork; + private final Command m_commandToFork; /** * Instantiates a {@link StartCommand} which will start the given command whenever its {@link @@ -28,6 +28,7 @@ public class StartCommand extends InstantCommand { m_commandToFork = commandToStart; } + @Override protected void initialize() { m_commandToFork.start(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java index 046ac3e1ad..5dc30e5716 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java @@ -32,7 +32,7 @@ public abstract class Subsystem extends SendableBase { /** * Whether or not getDefaultCommand() was called. */ - private boolean m_initializedDefaultCommand = false; + private boolean m_initializedDefaultCommand; /** * The current command. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java index abd3b91edd..a05e70498c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java @@ -34,6 +34,7 @@ public class TimedCommand extends Command { /** * Ends command when timed out. */ + @Override protected boolean isFinished() { return isTimedOut(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java index 3fc3da22b5..27795c0a62 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java @@ -16,6 +16,7 @@ package edu.wpi.first.wpilibj.command; * to finish, before continuing in the main {@link CommandGroup} sequence. */ public class WaitForChildren extends Command { + @Override protected boolean isFinished() { return getGroup() == null || getGroup().m_children.isEmpty(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java index 508b0e0e56..799fa8c601 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java @@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.Timer; * some value, then continue to the next command. */ public class WaitUntilCommand extends Command { - private double m_time; + private final double m_time; public WaitUntilCommand(double time) { super("WaitUntil(" + time + ")"); @@ -24,6 +24,7 @@ public class WaitUntilCommand extends Command { /** * Check if we've reached the actual finish time. */ + @Override public boolean isFinished() { return Timer.getMatchTime() >= m_time; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java index 08bf753282..d39965a76c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java @@ -95,16 +95,16 @@ public class DifferentialDrive extends RobotDriveBase { public static final double kDefaultQuickStopThreshold = 0.2; public static final double kDefaultQuickStopAlpha = 0.1; - private static int instances = 0; + private static int instances; - private SpeedController m_leftMotor; - private SpeedController m_rightMotor; + private final SpeedController m_leftMotor; + private final SpeedController m_rightMotor; private double m_quickStopThreshold = kDefaultQuickStopThreshold; private double m_quickStopAlpha = kDefaultQuickStopAlpha; - private double m_quickStopAccumulator = 0.0; + private double m_quickStopAccumulator; private double m_rightSideInvertMultiplier = -1.0; - private boolean m_reported = false; + private boolean m_reported; /** * Construct a DifferentialDrive. @@ -207,7 +207,7 @@ public class DifferentialDrive extends RobotDriveBase { * @param isQuickTurn If set, overrides constant-curvature turning for * turn-in-place maneuvers. */ - @SuppressWarnings("ParameterName") + @SuppressWarnings({"ParameterName", "PMD.CyclomaticComplexity"}) public void curvatureDrive(double xSpeed, double zRotation, boolean isQuickTurn) { if (!m_reported) { // HAL.report(tResourceType.kResourceType_RobotDrive, 2, tInstances.kRobotDrive_Curvature); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java index 558e0e7ac7..fce52b7638 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java @@ -42,7 +42,7 @@ public class KilloughDrive extends RobotDriveBase { public static final double kDefaultRightMotorAngle = 120.0; public static final double kDefaultBackMotorAngle = 270.0; - private static int instances = 0; + private static int instances; private SpeedController m_leftMotor; private SpeedController m_rightMotor; @@ -52,7 +52,7 @@ public class KilloughDrive extends RobotDriveBase { private Vector2d m_rightVec; private Vector2d m_backVec; - private boolean m_reported = false; + private boolean m_reported; /** * Construct a Killough drive with the given motors and default motor angles. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java index 958f37a74c..2602ccdbbd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java @@ -57,15 +57,15 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; * deadband of 0 is used. */ public class MecanumDrive extends RobotDriveBase { - private static int instances = 0; + private static int instances; - private SpeedController m_frontLeftMotor; - private SpeedController m_rearLeftMotor; - private SpeedController m_frontRightMotor; - private SpeedController m_rearRightMotor; + private final SpeedController m_frontLeftMotor; + private final SpeedController m_rearLeftMotor; + private final SpeedController m_frontRightMotor; + private final SpeedController m_rearRightMotor; private double m_rightSideInvertMultiplier = -1.0; - private boolean m_reported = false; + private boolean m_reported; /** * Construct a MecanumDrive. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/Vector2d.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/Vector2d.java index fb27fb110e..2b1f839581 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/Vector2d.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/Vector2d.java @@ -12,8 +12,8 @@ package edu.wpi.first.wpilibj.drive; */ @SuppressWarnings("MemberName") public class Vector2d { - public double x = 0.0; - public double y = 0.0; + public double x; + public double y; public Vector2d() {} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java index 9e174b5145..26312f899f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java @@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.PIDSourceType; * Superclass for filters. */ public abstract class Filter implements PIDSource { - private PIDSource m_source; + private final PIDSource m_source; public Filter(PIDSource source) { m_source = source; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java index 7bc0377276..08c0e1bdb8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java @@ -50,10 +50,10 @@ import edu.wpi.first.wpilibj.PIDSource; * to make sure PIDGet() gets called at the desired, constant frequency! */ public class LinearDigitalFilter extends Filter { - private CircularBuffer m_inputs; - private CircularBuffer m_outputs; - private double[] m_inputGains; - private double[] m_outputGains; + private final CircularBuffer m_inputs; + private final CircularBuffer m_outputs; + private final double[] m_inputGains; + private final double[] m_outputGains; /** * Create a linear FIR or IIR filter. @@ -62,8 +62,8 @@ public class LinearDigitalFilter extends Filter { * @param ffGains The "feed forward" or FIR gains * @param fbGains The "feed back" or IIR gains */ - public LinearDigitalFilter(PIDSource source, double[] ffGains, - double[] fbGains) { + public LinearDigitalFilter(PIDSource source, double[] ffGains, //NOPMD - PR1105 will fix this + double[] fbGains) { //NOPMD - PR1105 will fix this super(source); m_inputs = new CircularBuffer(ffGains.length); m_outputs = new CircularBuffer(fbGains.length); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java index 19b09f4632..35e29689a2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java @@ -80,6 +80,7 @@ public class HardwareTimer implements Timer.StaticInterface { * * @return Current time value for this timer in seconds */ + @Override public synchronized double get() { if (m_running) { return ((getMsClock() - m_startTime) + m_accumulatedTime) / 1000.0; @@ -92,6 +93,7 @@ public class HardwareTimer implements Timer.StaticInterface { * Reset the timer by setting the time to 0. Make the timer start time the current time so new * requests will be relative now */ + @Override public synchronized void reset() { m_accumulatedTime = 0; m_startTime = getMsClock(); @@ -101,6 +103,7 @@ public class HardwareTimer implements Timer.StaticInterface { * Start the timer running. Just set the running flag to true indicating that all time * requests should be relative to the system clock. */ + @Override public synchronized void start() { m_startTime = getMsClock(); m_running = true; @@ -111,6 +114,7 @@ public class HardwareTimer implements Timer.StaticInterface { * subsequent time requests to be read from the accumulated time rather than looking at the * system clock. */ + @Override public synchronized void stop() { final double temp = get(); m_accumulatedTime = temp; @@ -125,6 +129,7 @@ public class HardwareTimer implements Timer.StaticInterface { * @param period The period to check for (in seconds). * @return If the period has passed. */ + @Override public synchronized boolean hasPeriodPassed(double period) { if (get() > period) { // Advance the start time by the period. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java index 5ed193258c..f0cdc0a738 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java @@ -22,6 +22,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl; * The LiveWindow class is the public interface for putting sensors and actuators on the * LiveWindow. */ +@SuppressWarnings("PMD.TooManyMethods") public class LiveWindow { private static class Component { Component(Sendable sendable, Sendable parent) { @@ -36,13 +37,14 @@ public class LiveWindow { boolean m_telemetryEnabled = true; } + @SuppressWarnings("PMD.UseConcurrentHashMap") private static final Map components = new HashMap<>(); private static final NetworkTable liveWindowTable = NetworkTableInstance.getDefault().getTable("LiveWindow"); private static final NetworkTable statusTable = liveWindowTable.getSubTable(".status"); private static final NetworkTableEntry enabledEntry = statusTable.getEntry("LW Enabled"); - private static boolean startLiveWindow = false; - private static boolean liveWindowEnabled = false; + private static boolean startLiveWindow; + private static boolean liveWindowEnabled; private static boolean telemetryEnabled = true; private LiveWindow() { @@ -245,6 +247,7 @@ public class LiveWindow { *

Actuators are handled through callbacks on their value changing from the * SmartDashboard widgets. */ + @SuppressWarnings("PMD.CyclomaticComplexity") public static synchronized void updateValues() { // Only do this if either LiveWindow mode or telemetry is enabled. if (!liveWindowEnabled && !telemetryEnabled) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java index 0b16c403f9..7f78eeb716 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java @@ -21,6 +21,7 @@ import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableEntry; import edu.wpi.first.networktables.NetworkTableValue; +@SuppressWarnings("PMD.TooManyMethods") public class SendableBuilderImpl implements SendableBuilder { private static class Property { Property(NetworkTable table, String key) { @@ -29,7 +30,7 @@ public class SendableBuilderImpl implements SendableBuilder { @Override @SuppressWarnings("NoFinalizer") - public synchronized void finalize() { + protected synchronized void finalize() { stopListener(); } @@ -47,7 +48,7 @@ public class SendableBuilderImpl implements SendableBuilder { } final NetworkTableEntry m_entry; - int m_listener = 0; + int m_listener; Consumer m_update; Function m_createListener; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java index 4a4329b823..b44c6283c0 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java @@ -43,6 +43,7 @@ public class SendableChooser extends SendableBase { /** * A map linking strings to the objects the represent. */ + @SuppressWarnings("PMD.LooseCoupling") private final LinkedHashMap m_map = new LinkedHashMap<>(); private String m_defaultChoice = ""; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java index 791c47709f..d8a64722eb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java @@ -25,6 +25,7 @@ import edu.wpi.first.wpilibj.Sendable; *

When a value is put into the SmartDashboard here, it pops up on the SmartDashboard on the * laptop. Users can put values into and get values from the SmartDashboard. */ +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) public class SmartDashboard { /** * The {@link NetworkTable} used by {@link SmartDashboard}. @@ -45,6 +46,7 @@ public class SmartDashboard { * A table linking tables in the SmartDashboard to the {@link Sendable} objects they * came from. */ + @SuppressWarnings("PMD.UseConcurrentHashMap") private static final Map tablesToData = new HashMap<>(); static { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java index 904087d3e6..5af237e3eb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java @@ -47,6 +47,7 @@ public class SortedVector extends Vector { * * @param element The element to add to the Vector */ + @Override public void addElement(E element) { int highBound = size(); int lowBound = 0; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java index cbb5c61508..d1837234d8 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java @@ -8,8 +8,8 @@ package edu.wpi.first.wpilibj; public class MockSpeedController implements SpeedController { - private double m_speed = 0.0; - private boolean m_isInverted = false; + private double m_speed; + private boolean m_isInverted; @Override public void set(double speed) { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/AbstractCommandTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/AbstractCommandTest.java index 3485784caa..b6ff039589 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/AbstractCommandTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/AbstractCommandTest.java @@ -28,6 +28,7 @@ public abstract class AbstractCommandTest { public class ASubsystem extends Subsystem { Command m_command; + @Override protected void initDefaultCommand() { if (m_command != null) { setDefaultCommand(m_command); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockCommand.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockCommand.java index 1b7b7c530b..00503046c5 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockCommand.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockCommand.java @@ -12,12 +12,12 @@ package edu.wpi.first.wpilibj.command; * called. */ public class MockCommand extends Command { - private int m_initializeCount = 0; - private int m_executeCount = 0; - private int m_isFinishedCount = 0; - private boolean m_hasFinished = false; - private int m_endCount = 0; - private int m_interruptedCount = 0; + private int m_initializeCount; + private int m_executeCount; + private int m_isFinishedCount; + private boolean m_hasFinished; + private int m_endCount; + private int m_interruptedCount; public MockCommand(Subsystem subsys) { super(); @@ -28,23 +28,28 @@ public class MockCommand extends Command { super(); } + @Override protected void initialize() { ++m_initializeCount; } + @Override protected void execute() { ++m_executeCount; } + @Override protected boolean isFinished() { ++m_isFinishedCount; return isHasFinished(); } + @Override protected void end() { ++m_endCount; } + @Override protected void interrupted() { ++m_interruptedCount; } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockConditionalCommand.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockConditionalCommand.java index ebb6340cb8..876f1c5964 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockConditionalCommand.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockConditionalCommand.java @@ -8,12 +8,12 @@ package edu.wpi.first.wpilibj.command; public class MockConditionalCommand extends ConditionalCommand { - private boolean m_condition = false; - private int m_initializeCount = 0; - private int m_executeCount = 0; - private int m_isFinishedCount = 0; - private int m_endCount = 0; - private int m_interruptedCount = 0; + private boolean m_condition; + private int m_initializeCount; + private int m_executeCount; + private int m_isFinishedCount; + private int m_endCount; + private int m_interruptedCount; public MockConditionalCommand(MockCommand onTrue, MockCommand onFalse) { super(onTrue, onFalse); @@ -28,23 +28,28 @@ public class MockConditionalCommand extends ConditionalCommand { this.m_condition = condition; } + @Override protected void initialize() { ++m_initializeCount; } + @Override protected void execute() { ++m_executeCount; } + @Override protected boolean isFinished() { ++m_isFinishedCount; return super.isFinished(); } + @Override protected void end() { ++m_endCount; } + @Override protected void interrupted() { ++m_interruptedCount; } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockSubsystem.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockSubsystem.java index f20be37884..df39cd110e 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockSubsystem.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/command/MockSubsystem.java @@ -11,5 +11,6 @@ package edu.wpi.first.wpilibj.command; * A class to simulate a simple subsystem. */ public class MockSubsystem extends Subsystem { + @Override protected void initDefaultCommand() {} } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java index 8b8229b334..c17ea2dd1f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java @@ -38,6 +38,7 @@ public class ReplaceMeCommand extends Command { // Called when another command which requires one or more of the same // subsystems is scheduled to run + @Override protected void interrupted() { } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/OI.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/OI.java index b6135623b7..2a2469f89d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/OI.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/OI.java @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.examples.gearsbot.commands.SetWristSetpoint; * interface to the commands and command groups that allow control of the robot. */ public class OI { - private Joystick m_joystick = new Joystick(0); + private final Joystick m_joystick = new Joystick(0); /** * Construct the OI and all of the buttons on it. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/DriveStraight.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/DriveStraight.java index 4f4640018a..ba8feeb450 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/DriveStraight.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/DriveStraight.java @@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * encoders. */ public class DriveStraight extends Command { - private PIDController m_pid; + private final PIDController m_pid; /** * Create a new DriveStraight command. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetDistanceToBox.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetDistanceToBox.java index fd8d1bd74b..71f03dce8a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetDistanceToBox.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetDistanceToBox.java @@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * encoders. */ public class SetDistanceToBox extends Command { - private PIDController m_pid; + private final PIDController m_pid; /** * Create a new set distance to box command. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetElevatorSetpoint.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetElevatorSetpoint.java index 34fc769198..0ee5193c59 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetElevatorSetpoint.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetElevatorSetpoint.java @@ -18,7 +18,7 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * PID! */ public class SetElevatorSetpoint extends Command { - private double m_setpoint; + private final double m_setpoint; public SetElevatorSetpoint(double setpoint) { m_setpoint = setpoint; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetWristSetpoint.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetWristSetpoint.java index 496a1df36a..62e7a7f496 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetWristSetpoint.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/SetWristSetpoint.java @@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * commands using the wrist should make sure they disable PID! */ public class SetWristSetpoint extends Command { - private double m_setpoint; + private final double m_setpoint; public SetWristSetpoint(double setpoint) { m_setpoint = setpoint; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java index b484d88e12..550db9ad5e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java @@ -17,8 +17,8 @@ import edu.wpi.first.wpilibj.command.Subsystem; * don't stall. */ public class Claw extends Subsystem { - private Victor m_motor = new Victor(7); - private DigitalInput m_contact = new DigitalInput(5); + private final Victor m_motor = new Victor(7); + private final DigitalInput m_contact = new DigitalInput(5); /** * Create a new claw subsystem. @@ -48,6 +48,7 @@ public class Claw extends Subsystem { /** * Set the claw motor to move in the close direction. */ + @Override public void close() { m_motor.set(1); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java index fed14f8d34..899e3d5352 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java @@ -27,18 +27,18 @@ import edu.wpi.first.wpilibj.examples.gearsbot.commands.TankDriveWithJoystick; * and a gyro. */ public class DriveTrain extends Subsystem { - private SpeedController m_leftMotor + private final SpeedController m_leftMotor = new SpeedControllerGroup(new Spark(0), new Spark(1)); - private SpeedController m_rightMotor + private final SpeedController m_rightMotor = new SpeedControllerGroup(new Spark(2), new Spark(3)); - private DifferentialDrive m_drive + private final DifferentialDrive m_drive = new DifferentialDrive(m_leftMotor, m_rightMotor); - private Encoder m_leftEncoder = new Encoder(1, 2); - private Encoder m_rightEncoder = new Encoder(3, 4); - private AnalogInput m_rangefinder = new AnalogInput(6); - private AnalogGyro m_gyro = new AnalogGyro(1); + private final Encoder m_leftEncoder = new Encoder(1, 2); + private final Encoder m_rightEncoder = new Encoder(3, 4); + private final AnalogInput m_rangefinder = new AnalogInput(6); + private final AnalogGyro m_gyro = new AnalogGyro(1); /** * Create a new drive train subsystem. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java index b7ebb491f7..02d308c3e3 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java @@ -20,8 +20,8 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * world do to minor differences. */ public class Elevator extends PIDSubsystem { - private Victor m_motor; - private AnalogPotentiometer m_pot; + private final Victor m_motor; + private final AnalogPotentiometer m_pot; private static final double kP_real = 4; private static final double kI_real = 0.07; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java index f268c11bc1..30fa38e11d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java @@ -19,8 +19,8 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot; * of a linear joint. */ public class Wrist extends PIDSubsystem { - private Victor m_motor; - private AnalogPotentiometer m_pot; + private final Victor m_motor; + private final AnalogPotentiometer m_pot; private static final double kP_real = 1; private static final double kP_simulation = 0.05; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java index 906cf25a51..5afe17f071 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java @@ -21,10 +21,10 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive; * directory. */ public class Robot extends IterativeRobot { - private DifferentialDrive m_robotDrive + private final DifferentialDrive m_robotDrive = new DifferentialDrive(new Spark(0), new Spark(1)); - private Joystick m_stick = new Joystick(0); - private Timer m_timer = new Timer(); + private final Joystick m_stick = new Joystick(0); + private final Timer m_timer = new Timer(); /** * This function is run when the robot is first started up and should be diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java index baa252ca06..8d1175278b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java @@ -31,11 +31,11 @@ public class Robot extends IterativeRobot { private static final int kGyroPort = 0; private static final int kJoystickPort = 0; - private DifferentialDrive m_myRobot + private final DifferentialDrive m_myRobot = new DifferentialDrive(new Spark(kLeftMotorPort), new Spark(kRightMotorPort)); - private AnalogGyro m_gyro = new AnalogGyro(kGyroPort); - private Joystick m_joystick = new Joystick(kJoystickPort); + private final AnalogGyro m_gyro = new AnalogGyro(kGyroPort); + private final Joystick m_joystick = new Joystick(kJoystickPort); @Override public void robotInit() { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java index 0b7f8ef260..463967b6e5 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java @@ -31,8 +31,8 @@ public class Robot extends IterativeRobot { private static final int kJoystickPort = 0; private MecanumDrive m_robotDrive; - private AnalogGyro m_gyro = new AnalogGyro(kGyroPort); - private Joystick m_joystick = new Joystick(kJoystickPort); + private final AnalogGyro m_gyro = new AnalogGyro(kGyroPort); + private final Joystick m_joystick = new Joystick(kJoystickPort); @Override public void robotInit() { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/DriveForward.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/DriveForward.java index faa93bc04e..219233b39d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/DriveForward.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/DriveForward.java @@ -16,8 +16,8 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot; * control This command will drive a given distance limiting to a maximum speed. */ public class DriveForward extends Command { - private double m_driveForwardSpeed; - private double m_distance; + private final double m_driveForwardSpeed; + private final double m_distance; private double m_error; private static final double kTolerance = 0.1; private static final double kP = -1.0 / 5.0; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetCollectionSpeed.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetCollectionSpeed.java index 4b9f8ac80b..172905d83b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetCollectionSpeed.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetCollectionSpeed.java @@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot; * the spinners may still be adjusting their speed. */ public class SetCollectionSpeed extends InstantCommand { - private double m_speed; + private final double m_speed; public SetCollectionSpeed(double speed) { requires(Robot.collector); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetPivotSetpoint.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetPivotSetpoint.java index 088852c446..74a81a0ca4 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetPivotSetpoint.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/commands/SetPivotSetpoint.java @@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot; * commands using the pivot should make sure they disable PID! */ public class SetPivotSetpoint extends Command { - private double m_setpoint; + private final double m_setpoint; public SetPivotSetpoint(double setpoint) { this.m_setpoint = setpoint; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java index 1c895d0629..6bff9ff24f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java @@ -25,10 +25,10 @@ public class Collector extends Subsystem { public static final double kReverse = -1; // Subsystem devices - private SpeedController m_rollerMotor = new Victor(6); - private DigitalInput m_ballDetector = new DigitalInput(10); - private DigitalInput m_openDetector = new DigitalInput(6); - private Solenoid m_piston = new Solenoid(1, 1); + private final SpeedController m_rollerMotor = new Victor(6); + private final DigitalInput m_ballDetector = new DigitalInput(10); + private final DigitalInput m_openDetector = new DigitalInput(6); + private final Solenoid m_piston = new Solenoid(1, 1); /** * Create a new collector subsystem. @@ -89,6 +89,7 @@ public class Collector extends Subsystem { /** * Close the claw (For collecting and driving). */ + @Override public void close() { m_piston.set(false); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java index 20dc654126..a1e74691a6 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java @@ -27,18 +27,18 @@ import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveWithJoystick; */ public class DriveTrain extends Subsystem { // Subsystem devices - private SpeedController m_frontLeftCIM = new Victor(1); - private SpeedController m_frontRightCIM = new Victor(2); - private SpeedController m_rearLeftCIM = new Victor(3); - private SpeedController m_rearRightCIM = new Victor(4); - private SpeedControllerGroup m_leftCIMs = new SpeedControllerGroup( + private final SpeedController m_frontLeftCIM = new Victor(1); + private final SpeedController m_frontRightCIM = new Victor(2); + private final SpeedController m_rearLeftCIM = new Victor(3); + private final SpeedController m_rearRightCIM = new Victor(4); + private final SpeedControllerGroup m_leftCIMs = new SpeedControllerGroup( m_frontLeftCIM, m_rearLeftCIM); - private SpeedControllerGroup m_rightCIMs = new SpeedControllerGroup( + private final SpeedControllerGroup m_rightCIMs = new SpeedControllerGroup( m_frontRightCIM, m_rearRightCIM); - private DifferentialDrive m_drive; - private Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X); - private Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X); - private AnalogGyro m_gyro = new AnalogGyro(2); + private final DifferentialDrive m_drive; + private final Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X); + private final Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X); + private final AnalogGyro m_gyro = new AnalogGyro(2); /** * Create a new drive train subsystem. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java index 23e2b2c6ec..44e197cae9 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java @@ -28,15 +28,15 @@ public class Pivot extends PIDSubsystem { public static final double kShootNear = 30; // Sensors for measuring the position of the pivot. - private DigitalInput m_upperLimitSwitch = new DigitalInput(13); - private DigitalInput m_lowerLimitSwitch = new DigitalInput(12); + private final DigitalInput m_upperLimitSwitch = new DigitalInput(13); + private final DigitalInput m_lowerLimitSwitch = new DigitalInput(12); // 0 degrees is vertical facing up. // Angle increases the more forward the pivot goes. - private Potentiometer m_pot = new AnalogPotentiometer(1); + private final Potentiometer m_pot = new AnalogPotentiometer(1); // Motor to move the pivot. - private SpeedController m_motor = new Victor(5); + private final SpeedController m_motor = new Victor(5); /** * Create a new pivot subsystem. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Shooter.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Shooter.java index 93c44ccf8a..c5306ad481 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Shooter.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Shooter.java @@ -22,6 +22,7 @@ import edu.wpi.first.wpilibj.command.Subsystem; *

NOTE: Simulation currently approximates this as as single pneumatic * cylinder and ignores the latch. */ +@SuppressWarnings("PMD.TooManyMethods") public class Shooter extends Subsystem { // Devices DoubleSolenoid m_piston1 = new DoubleSolenoid(1, 3, 4); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/triggers/DoubleButton.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/triggers/DoubleButton.java index 0533dc7cff..e795593f0e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/triggers/DoubleButton.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/triggers/DoubleButton.java @@ -15,9 +15,9 @@ import edu.wpi.first.wpilibj.buttons.Trigger; * simultaneously pressed. */ public class DoubleButton extends Trigger { - private Joystick m_joy; - private int m_button1; - private int m_button2; + private final Joystick m_joy; + private final int m_button1; + private final int m_button2; /** * Create a new double button trigger. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java index bbd72f7af0..42664dc0cb 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java @@ -36,12 +36,14 @@ public class Robot extends IterativeRobot { private static final double kD = -2.0; private PIDController m_pidController; + @SuppressWarnings("PMD.SingularField") private AnalogInput m_potentiometer; + @SuppressWarnings("PMD.SingularField") private SpeedController m_elevatorMotor; private Joystick m_joystick; - private int m_index = 0; - private boolean m_previousButtonValue = false; + private int m_index; + private boolean m_previousButtonValue; @Override public void robotInit() { @@ -49,8 +51,7 @@ public class Robot extends IterativeRobot { m_elevatorMotor = new Spark(kMotorChannel); m_joystick = new Joystick(kJoystickChannel); - m_pidController - = new PIDController(kP, kI, kD, m_potentiometer, m_elevatorMotor); + m_pidController = new PIDController(kP, kI, kD, m_potentiometer, m_elevatorMotor); m_pidController.setInputRange(0, 5); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java index e2fe3a7e05..42d11ac48a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java @@ -31,8 +31,8 @@ public class Robot extends IterativeRobot { private static final int kRightMotorPort = 1; private static final int kUltrasonicPort = 0; - private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort); - private DifferentialDrive m_robotDrive + private final AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort); + private final DifferentialDrive m_robotDrive = new DifferentialDrive(new Spark(kLeftMotorPort), new Spark(kRightMotorPort)); @@ -40,6 +40,7 @@ public class Robot extends IterativeRobot { * Tells the robot to drive to a set distance (in inches) from an object * using proportional control. */ + @Override public void teleopPeriodic() { // sensor returns a value from 0-4095 that is scaled to inches double currentDistance = m_ultrasonic.getValue() * kValueToInches; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java index 1f83606ebb..ad655e09dc 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java @@ -41,11 +41,11 @@ public class Robot extends IterativeRobot { private static final int kRightMotorPort = 1; private static final int kUltrasonicPort = 0; - private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort); - private DifferentialDrive m_robotDrive + private final AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort); + private final DifferentialDrive m_robotDrive = new DifferentialDrive(new Spark(kLeftMotorPort), new Spark(kRightMotorPort)); - private PIDController m_pidController + private final PIDController m_pidController = new PIDController(kP, kI, kD, m_ultrasonic, new MyPidOutput()); /** diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java index 6a8035f925..a03b73f0ca 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java @@ -16,6 +16,7 @@ public class ExampleSubsystem extends Subsystem { // Put methods for controlling this subsystem // here. Call these from Commands. + @Override public void initDefaultCommand() { // Set the default command for a subsystem here. // setDefaultCommand(new MySpecialCommand()); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Robot.java index f96fb2a212..e2a7b25245 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Robot.java @@ -22,7 +22,7 @@ public class Robot extends IterativeRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; private String m_autoSelected; - private SendableChooser m_chooser = new SendableChooser<>(); + private final SendableChooser m_chooser = new SendableChooser<>(); /** * This function is run when the robot is first started up and should be diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Robot.java index b07a15022f..135da9fc31 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Robot.java @@ -36,10 +36,10 @@ public class Robot extends SampleRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; - private DifferentialDrive m_robotDrive + private final DifferentialDrive m_robotDrive = new DifferentialDrive(new Spark(0), new Spark(1)); - private Joystick m_stick = new Joystick(0); - private SendableChooser m_chooser = new SendableChooser<>(); + private final Joystick m_stick = new Joystick(0); + private final SendableChooser m_chooser = new SendableChooser<>(); public Robot() { m_robotDrive.setExpiration(0.1); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Robot.java index 4cbbb42b4a..3965bcb414 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Robot.java @@ -22,7 +22,7 @@ public class Robot extends TimedRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; private String m_autoSelected; - private SendableChooser m_chooser = new SendableChooser<>(); + private final SendableChooser m_chooser = new SendableChooser<>(); /** * This function is run when the robot is first started up and should be diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java index 260ac12231..aae16617ae 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; public class ConstantsPortsTest extends AbstractComsSetup { private static final Logger logger = Logger.getLogger(ConstantsPortsTest.class.getName()); + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java index fb9b7ff2e5..821f5ccc91 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java @@ -22,6 +22,7 @@ public class DigitalGlitchFilterTest extends AbstractComsSetup { private static final Logger logger = Logger.getLogger( DigitalGlitchFilterTest.class.getName()); + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java index 71d6f49e5e..b703138d86 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java @@ -269,6 +269,7 @@ public class PCMTest extends AbstractComsSetup { solenoid2.close(); } + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RobotDriveTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RobotDriveTest.java index b0e773634e..006c723cc8 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RobotDriveTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RobotDriveTest.java @@ -176,6 +176,7 @@ public class RobotDriveTest extends AbstractComsSetup { } } + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/SampleTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/SampleTest.java index d21206b8b2..efcea2356c 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/SampleTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/SampleTest.java @@ -30,6 +30,7 @@ public class SampleTest extends AbstractComsSetup { static SampleFixture fixture = new SampleFixture(); + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java index b82cb41973..5608491d1b 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java @@ -30,6 +30,7 @@ public class FakeCounterSource implements AutoCloseable { m_encoder = encode; } + @Override public void run() { m_encoder.m_output.set(false); try { @@ -70,6 +71,7 @@ public class FakeCounterSource implements AutoCloseable { /** * Destroy Object with minimum memory leak. */ + @Override public void close() { m_task = null; if (m_allocated) { diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java index dc85ec2ed3..bdb6886228 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java @@ -32,6 +32,7 @@ public class FakeEncoderSource implements AutoCloseable { m_encoder = encode; } + @Override public void run() { final DigitalOutput lead; final DigitalOutput lag; @@ -93,6 +94,7 @@ public class FakeEncoderSource implements AutoCloseable { /** * Frees the resource. */ + @Override public void close() { m_task = null; if (m_allocatedOutputs) { diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java index 13306d366c..63af674670 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java @@ -83,6 +83,7 @@ public class FakePotentiometerSource implements AutoCloseable { /** * Frees the resouce. */ + @Override public void close() { if (m_initOutput) { m_output.close(); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboardTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboardTest.java index cf1d827449..b7e98b1c7f 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboardTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboardTest.java @@ -24,6 +24,7 @@ public class SmartDashboardTest extends AbstractComsSetup { private static final Logger logger = Logger.getLogger(SmartDashboardTest.class.getName()); private static final NetworkTable table = NetworkTable.getTable("SmartDashboard"); + @Override protected Logger getClassLogger() { return logger; } diff --git a/wpiutil/src/dev/java/edu/wpi/first/wpiutil/DevMain.java b/wpiutil/src/dev/java/edu/wpi/first/wpiutil/DevMain.java index 51d9e40c27..c5f1754e35 100644 --- a/wpiutil/src/dev/java/edu/wpi/first/wpiutil/DevMain.java +++ b/wpiutil/src/dev/java/edu/wpi/first/wpiutil/DevMain.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpiutil; -public class DevMain { +public final class DevMain { /** * Main entry point. */ @@ -15,4 +15,7 @@ public class DevMain { System.out.println("Hello World!"); System.out.println(RuntimeDetector.getPlatformPath()); } + + private DevMain() { + } } diff --git a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java index 324a7bdc39..de4fd8bdfc 100644 --- a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java +++ b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java @@ -9,11 +9,12 @@ package edu.wpi.first.wpiutil; import java.io.File; -public class RuntimeDetector { +public final class RuntimeDetector { private static String filePrefix; private static String fileExtension; private static String filePath; + @SuppressWarnings("PMD.CyclomaticComplexity") private static synchronized void computePlatform() { if (fileExtension != null && filePath != null && filePrefix != null) { return; @@ -52,7 +53,7 @@ public class RuntimeDetector { filePath = "/linux/nativearm/"; } } else { - throw new RuntimeException("Failed to determine OS"); + throw new IllegalStateException("Failed to determine OS"); } } @@ -112,11 +113,15 @@ public class RuntimeDetector { public static boolean is32BitIntel() { String arch = System.getProperty("os.arch"); - return arch.equals("x86") || arch.equals("i386"); + return "x86".equals(arch) || "i386".equals(arch); } public static boolean is64BitIntel() { String arch = System.getProperty("os.arch"); - return arch.equals("amd64") || arch.equals("x86_64"); + return "amd64".equals(arch) || "x86_64".equals(arch); + } + + private RuntimeDetector() { + } }