mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
Some valid warnings like throwing NullPointerException or using a for loop instead of System.arraycopy() were fixed. Abstract classes marked with PMD.AbstractClassWithoutAbstractMethod were made concrete because they already had protected constructors. Fixes #1697.
This commit is contained in:
@@ -23,7 +23,6 @@ import org.ejml.simple.SimpleMatrix;
|
||||
* @param <R> The number of rows in this matrix.
|
||||
* @param <C> The number of columns in this matrix.
|
||||
*/
|
||||
@SuppressWarnings("PMD.ExcessivePublicCount")
|
||||
public class Matrix<R extends Num, C extends Num> {
|
||||
protected final SimpleMatrix m_storage;
|
||||
|
||||
@@ -531,7 +530,6 @@ public class Matrix<R extends Num, C extends Num> {
|
||||
* @throws RuntimeException if the matrix could not be decomposed(ie. is not positive
|
||||
* semidefinite).
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
|
||||
public Matrix<R, C> lltDecompose(boolean lowerTriangular) {
|
||||
SimpleMatrix temp = m_storage.copy();
|
||||
|
||||
|
||||
@@ -216,7 +216,6 @@ public final class SimpleMatrixUtils {
|
||||
* @throws RuntimeException if the matrix could not be decomposed (ie. is not positive
|
||||
* semidefinite).
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
|
||||
public static SimpleMatrix lltDecompose(SimpleMatrix src, boolean lowerTriangular) {
|
||||
SimpleMatrix temp = src.copy();
|
||||
|
||||
|
||||
@@ -171,7 +171,6 @@ public class VecBuilder<N extends Num> extends MatBuilder<N, N1> {
|
||||
* @param n9 the ninth element.
|
||||
* @param n10 the tenth element.
|
||||
*/
|
||||
@SuppressWarnings("PMD.ExcessiveParameterList")
|
||||
public static Vector<N10> fill(
|
||||
double n1,
|
||||
double n2,
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ExtendedKalmanFilter<States extends Num, Inputs extends Num, Output
|
||||
* @param addFuncX A function that adds two state vectors.
|
||||
* @param dtSeconds Nominal discretization timestep.
|
||||
*/
|
||||
@SuppressWarnings({"ParameterName", "PMD.ExcessiveParameterList"})
|
||||
@SuppressWarnings("ParameterName")
|
||||
public ExtendedKalmanFilter(
|
||||
Nat<States> states,
|
||||
Nat<Inputs> inputs,
|
||||
|
||||
@@ -60,7 +60,7 @@ public class KalmanFilterLatencyCompensator<S extends Num, I extends Num, O exte
|
||||
* @param globalMeasurementCorrect The function take calls correct() on the observer.
|
||||
* @param timestampSeconds The timestamp of the measurement.
|
||||
*/
|
||||
@SuppressWarnings({"ParameterName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("ParameterName")
|
||||
public <R extends Num> void applyPastGlobalMeasurement(
|
||||
Nat<R> rows,
|
||||
KalmanTypeFilter<S, I, O> observer,
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.ejml.simple.SimpleMatrix;
|
||||
* an estimate of the true covariance (as opposed to a linearized version of it). This means that
|
||||
* the UKF works with nonlinear systems.
|
||||
*/
|
||||
@SuppressWarnings({"MemberName", "ClassTypeParameterName", "PMD.TooManyFields"})
|
||||
@SuppressWarnings({"MemberName", "ClassTypeParameterName"})
|
||||
public class UnscentedKalmanFilter<States extends Num, Inputs extends Num, Outputs extends Num>
|
||||
implements KalmanTypeFilter<States, Inputs, Outputs> {
|
||||
|
||||
@@ -108,7 +108,7 @@ public class UnscentedKalmanFilter<States extends Num, Inputs extends Num, Outpu
|
||||
* @param addFuncX A function that adds two state vectors.
|
||||
* @param nominalDtSeconds Nominal discretization timestep.
|
||||
*/
|
||||
@SuppressWarnings({"ParameterName", "PMD.ExcessiveParameterList"})
|
||||
@SuppressWarnings("ParameterName")
|
||||
public UnscentedKalmanFilter(
|
||||
Nat<States> states,
|
||||
Nat<Outputs> outputs,
|
||||
@@ -144,7 +144,7 @@ public class UnscentedKalmanFilter<States extends Num, Inputs extends Num, Outpu
|
||||
reset();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"ParameterName", "LocalVariableName", "PMD.CyclomaticComplexity"})
|
||||
@SuppressWarnings({"ParameterName", "LocalVariableName"})
|
||||
static <S extends Num, C extends Num> Pair<Matrix<C, N1>, Matrix<C, C>> unscentedTransform(
|
||||
Nat<S> s,
|
||||
Nat<C> dim,
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SwerveDriveKinematics {
|
||||
* attainable max velocity. Use the {@link #normalizeWheelSpeeds(SwerveModuleState[], double)
|
||||
* normalizeWheelSpeeds} function to rectify this issue.
|
||||
*/
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public SwerveModuleState[] toSwerveModuleStates(
|
||||
ChassisSpeeds chassisSpeeds, Translation2d centerOfRotationMeters) {
|
||||
if (!centerOfRotationMeters.equals(m_prevCoR)) {
|
||||
|
||||
@@ -48,7 +48,6 @@ public final class SplineHelper {
|
||||
* @param waypoints The waypoints
|
||||
* @return List of splines.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public static QuinticHermiteSpline[] getQuinticSplinesFromWaypoints(List<Pose2d> waypoints) {
|
||||
QuinticHermiteSpline[] splines = new QuinticHermiteSpline[waypoints.size() - 1];
|
||||
for (int i = 0; i < waypoints.size() - 1; ++i) {
|
||||
@@ -79,11 +78,7 @@ public final class SplineHelper {
|
||||
* @return A vector of cubic hermite splines that interpolate through the provided waypoints and
|
||||
* control vectors.
|
||||
*/
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.ExcessiveMethodLength",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public static CubicHermiteSpline[] getCubicSplinesFromControlVectors(
|
||||
Spline.ControlVector start, Translation2d[] waypoints, Spline.ControlVector end) {
|
||||
|
||||
@@ -208,7 +203,7 @@ public final class SplineHelper {
|
||||
* @param controlVectors The control vectors.
|
||||
* @return A vector of quintic hermite splines that interpolate through the provided waypoints.
|
||||
*/
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public static QuinticHermiteSpline[] getQuinticSplinesFromControlVectors(
|
||||
Spline.ControlVector[] controlVectors) {
|
||||
QuinticHermiteSpline[] splines = new QuinticHermiteSpline[controlVectors.length - 1];
|
||||
|
||||
@@ -96,7 +96,6 @@ public final class SplineParameterizer {
|
||||
* @throws MalformedSplineException When the spline is malformed (e.g. has close adjacent points
|
||||
* with approximately opposing headings)
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public static List<PoseWithCurvature> parameterize(Spline spline, double t0, double t1) {
|
||||
var splinePoints = new ArrayList<PoseWithCurvature>();
|
||||
|
||||
|
||||
@@ -152,7 +152,6 @@ public class Trajectory {
|
||||
* @param transform The transform to transform the trajectory by.
|
||||
* @return The transformed trajectory.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public Trajectory transformBy(Transform2d transform) {
|
||||
var firstState = m_states.get(0);
|
||||
var firstPose = firstState.poseMeters;
|
||||
@@ -214,7 +213,6 @@ public class Trajectory {
|
||||
* @param other The trajectory to concatenate.
|
||||
* @return The concatenated trajectory.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public Trajectory concatenate(Trajectory other) {
|
||||
// If this is a default constructed trajectory with no states, then we can
|
||||
// simply return the rhs trajectory.
|
||||
|
||||
@@ -138,7 +138,6 @@ public final class TrajectoryGenerator {
|
||||
* @param config The configuration for the trajectory.
|
||||
* @return The generated trajectory.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public static Trajectory generateTrajectory(
|
||||
ControlVectorList controlVectors, TrajectoryConfig config) {
|
||||
final var flip = new Transform2d(new Translation2d(), Rotation2d.fromDegrees(180.0));
|
||||
|
||||
@@ -54,12 +54,6 @@ public final class TrajectoryParameterizer {
|
||||
* from a -> b -> ... -> z as defined in the waypoints.
|
||||
* @return The trajectory.
|
||||
*/
|
||||
@SuppressWarnings({
|
||||
"PMD.ExcessiveMethodLength",
|
||||
"PMD.CyclomaticComplexity",
|
||||
"PMD.NPathComplexity",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops"
|
||||
})
|
||||
public static Trajectory timeParameterizeTrajectory(
|
||||
List<PoseWithCurvature> points,
|
||||
List<TrajectoryConstraint> constraints,
|
||||
|
||||
@@ -23,7 +23,6 @@ public final class TrajectoryUtil {
|
||||
* @param elements A double[] containing the raw elements of the trajectory.
|
||||
* @return A trajectory created from the elements.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
private static Trajectory createTrajectoryFromElements(double[] elements) {
|
||||
// Make sure that the elements have the correct length.
|
||||
if (elements.length % 7 != 0) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LinearSystemLoopTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public void testStateSpaceEnabled() {
|
||||
|
||||
m_loop.reset(VecBuilder.fill(0, 0));
|
||||
@@ -82,7 +82,7 @@ public class LinearSystemLoopTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public void testFlywheelEnabled() {
|
||||
|
||||
LinearSystem<N1, N1, N1> plant =
|
||||
|
||||
@@ -21,7 +21,6 @@ class RamseteControllerTest {
|
||||
private static final double kAngularTolerance = Math.toRadians(2);
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
void testReachesReference() {
|
||||
final var controller = new RamseteController(2.0, 0.7);
|
||||
var robotPose = new Pose2d(2.7, 23.0, Rotation2d.fromDegrees(0.0));
|
||||
|
||||
@@ -22,11 +22,7 @@ import java.util.Random;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DifferentialDrivePoseEstimatorTest {
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.ExcessiveMethodLength",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@Test
|
||||
public void testAccuracy() {
|
||||
var estimator =
|
||||
|
||||
@@ -98,11 +98,7 @@ public class ExtendedKalmanFilterTest {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops",
|
||||
"PMD.ExcessiveMethodLength"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@Test
|
||||
public void testConvergence() {
|
||||
double dtSeconds = 0.00505;
|
||||
|
||||
@@ -72,7 +72,6 @@ public class KalmanFilterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public void testSwerveKFStationary() {
|
||||
|
||||
var random = new Random();
|
||||
@@ -121,7 +120,6 @@ public class KalmanFilterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public void testSwerveKFMovingWithoutAccelerating() {
|
||||
|
||||
var random = new Random();
|
||||
@@ -178,7 +176,7 @@ public class KalmanFilterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public void testSwerveKFMovingOverTrajectory() {
|
||||
|
||||
var random = new Random();
|
||||
|
||||
@@ -20,11 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MecanumDrivePoseEstimatorTest {
|
||||
@Test
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops",
|
||||
"PMD.ExcessiveMethodLength"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public void testAccuracy() {
|
||||
var kinematics =
|
||||
new MecanumDriveKinematics(
|
||||
|
||||
@@ -20,11 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SwerveDrivePoseEstimatorTest {
|
||||
@Test
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops",
|
||||
"PMD.ExcessiveMethodLength"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
public void testAccuracy() {
|
||||
var kinematics =
|
||||
new SwerveDriveKinematics(
|
||||
|
||||
@@ -103,11 +103,7 @@ public class UnscentedKalmanFilterTest {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({
|
||||
"LocalVariableName",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops",
|
||||
"PMD.ExcessiveMethodLength"
|
||||
})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@Test
|
||||
public void testConvergence() {
|
||||
double dtSeconds = 0.00505;
|
||||
@@ -293,7 +289,7 @@ public class UnscentedKalmanFilterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"LocalVariableName", "ParameterName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings({"LocalVariableName", "ParameterName"})
|
||||
public void testLinearUKF() {
|
||||
var dt = 0.020;
|
||||
var plant = LinearSystemId.identifyVelocitySystem(0.02, 0.006);
|
||||
|
||||
@@ -23,7 +23,7 @@ class CubicHermiteSplineTest {
|
||||
private static final double kMaxDy = 0.00127;
|
||||
private static final double kMaxDtheta = 0.0872;
|
||||
|
||||
@SuppressWarnings({"ParameterName", "PMD.UnusedLocalVariable"})
|
||||
@SuppressWarnings("ParameterName")
|
||||
private void run(Pose2d a, List<Translation2d> waypoints, Pose2d b) {
|
||||
// Start the timer.
|
||||
// var start = System.nanoTime();
|
||||
|
||||
@@ -20,7 +20,7 @@ class QuinticHermiteSplineTest {
|
||||
private static final double kMaxDy = 0.00127;
|
||||
private static final double kMaxDtheta = 0.0872;
|
||||
|
||||
@SuppressWarnings({"ParameterName", "PMD.UnusedLocalVariable"})
|
||||
@SuppressWarnings("ParameterName")
|
||||
private void run(Pose2d a, Pose2d b) {
|
||||
// Start the timer.
|
||||
// var start = System.nanoTime();
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class DifferentialDriveKinematicsConstraintTest {
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@Test
|
||||
void testDifferentialDriveKinematicsConstraint() {
|
||||
double maxVelocity = Units.feetToMeters(12.0); // 12 feet per second
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class DifferentialDriveVoltageConstraintTest {
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@Test
|
||||
void testDifferentialDriveVoltageConstraint() {
|
||||
// Pick an unreasonably large kA to ensure the constraint has to do some work
|
||||
|
||||
@@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
class TrapezoidProfileTest {
|
||||
private static final double kDt = 0.01;
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
// Declaring this class abstract prevents UtilityClassTest from running on itself and throwing the
|
||||
// following exception:
|
||||
//
|
||||
// org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered
|
||||
// for parameter [java.lang.Class<T> arg0] in constructor [protected
|
||||
// edu.wpi.first.wpilibj.UtilityClassTest(java.lang.Class<T>)].
|
||||
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
|
||||
public abstract class UtilityClassTest<T> {
|
||||
private final Class<T> m_clazz;
|
||||
|
||||
Reference in New Issue
Block a user