mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless. Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
@@ -4,14 +4,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import edu.wpi.cscore.CameraServerJNI;
|
||||
import edu.wpi.first.cameraserver.CameraServerShared;
|
||||
import edu.wpi.first.cameraserver.CameraServerSharedStore;
|
||||
@@ -26,6 +18,13 @@ import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
|
||||
import edu.wpi.first.wpilibj.util.WPILibVersion;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Implement a Robot Program framework. The RobotBase class is intended to be subclassed by a user
|
||||
@@ -35,94 +34,93 @@ import edu.wpi.first.wpilibj.util.WPILibVersion;
|
||||
* might be spawned as a task, then killed at the end of the Autonomous period.
|
||||
*/
|
||||
public abstract class RobotBase implements AutoCloseable {
|
||||
/**
|
||||
* The ID of the main Java thread.
|
||||
*/
|
||||
/** The ID of the main Java thread. */
|
||||
// This is usually 1, but it is best to make sure
|
||||
private static long m_threadId = -1;
|
||||
|
||||
private static void setupCameraServerShared() {
|
||||
CameraServerShared shared = new CameraServerShared() {
|
||||
CameraServerShared shared =
|
||||
new CameraServerShared() {
|
||||
|
||||
@Override
|
||||
public void reportVideoServer(int id) {
|
||||
HAL.report(tResourceType.kResourceType_PCVideoServer, id + 1);
|
||||
}
|
||||
@Override
|
||||
public void reportVideoServer(int id) {
|
||||
HAL.report(tResourceType.kResourceType_PCVideoServer, id + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportUsbCamera(int id) {
|
||||
HAL.report(tResourceType.kResourceType_UsbCamera, id + 1);
|
||||
}
|
||||
@Override
|
||||
public void reportUsbCamera(int id) {
|
||||
HAL.report(tResourceType.kResourceType_UsbCamera, id + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportDriverStationError(String error) {
|
||||
DriverStation.reportError(error, true);
|
||||
}
|
||||
@Override
|
||||
public void reportDriverStationError(String error) {
|
||||
DriverStation.reportError(error, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAxisCamera(int id) {
|
||||
HAL.report(tResourceType.kResourceType_AxisCamera, id + 1);
|
||||
}
|
||||
@Override
|
||||
public void reportAxisCamera(int id) {
|
||||
HAL.report(tResourceType.kResourceType_AxisCamera, id + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRobotMainThreadId() {
|
||||
return RobotBase.getMainThreadId();
|
||||
}
|
||||
@Override
|
||||
public Long getRobotMainThreadId() {
|
||||
return RobotBase.getMainThreadId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoboRIO() {
|
||||
return RobotBase.isReal();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public boolean isRoboRIO() {
|
||||
return RobotBase.isReal();
|
||||
}
|
||||
};
|
||||
|
||||
CameraServerSharedStore.setCameraServerShared(shared);
|
||||
}
|
||||
|
||||
private static void setupMathShared() {
|
||||
MathSharedStore.setMathShared(new MathShared() {
|
||||
@Override
|
||||
public void reportError(String error, StackTraceElement[] stackTrace) {
|
||||
DriverStation.reportError(error, stackTrace);
|
||||
}
|
||||
MathSharedStore.setMathShared(
|
||||
new MathShared() {
|
||||
@Override
|
||||
public void reportError(String error, StackTraceElement[] stackTrace) {
|
||||
DriverStation.reportError(error, stackTrace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportUsage(MathUsageId id, int count) {
|
||||
switch (id) {
|
||||
case kKinematics_DifferentialDrive:
|
||||
HAL.report(tResourceType.kResourceType_Kinematics,
|
||||
tInstances.kKinematics_DifferentialDrive);
|
||||
break;
|
||||
case kKinematics_MecanumDrive:
|
||||
HAL.report(tResourceType.kResourceType_Kinematics,
|
||||
tInstances.kKinematics_MecanumDrive);
|
||||
break;
|
||||
case kKinematics_SwerveDrive:
|
||||
HAL.report(tResourceType.kResourceType_Kinematics,
|
||||
tInstances.kKinematics_SwerveDrive);
|
||||
break;
|
||||
case kTrajectory_TrapezoidProfile:
|
||||
HAL.report(tResourceType.kResourceType_TrapezoidProfile, count);
|
||||
break;
|
||||
case kFilter_Linear:
|
||||
HAL.report(tResourceType.kResourceType_LinearFilter, count);
|
||||
break;
|
||||
case kOdometry_DifferentialDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry,
|
||||
tInstances.kOdometry_DifferentialDrive);
|
||||
break;
|
||||
case kOdometry_SwerveDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry,
|
||||
tInstances.kOdometry_SwerveDrive);
|
||||
break;
|
||||
case kOdometry_MecanumDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry,
|
||||
tInstances.kOdometry_MecanumDrive);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void reportUsage(MathUsageId id, int count) {
|
||||
switch (id) {
|
||||
case kKinematics_DifferentialDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics,
|
||||
tInstances.kKinematics_DifferentialDrive);
|
||||
break;
|
||||
case kKinematics_MecanumDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_MecanumDrive);
|
||||
break;
|
||||
case kKinematics_SwerveDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_SwerveDrive);
|
||||
break;
|
||||
case kTrajectory_TrapezoidProfile:
|
||||
HAL.report(tResourceType.kResourceType_TrapezoidProfile, count);
|
||||
break;
|
||||
case kFilter_Linear:
|
||||
HAL.report(tResourceType.kResourceType_LinearFilter, count);
|
||||
break;
|
||||
case kOdometry_DifferentialDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Odometry, tInstances.kOdometry_DifferentialDrive);
|
||||
break;
|
||||
case kOdometry_SwerveDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry, tInstances.kOdometry_SwerveDrive);
|
||||
break;
|
||||
case kOdometry_MecanumDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry, tInstances.kOdometry_MecanumDrive);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected final DriverStation m_ds;
|
||||
@@ -133,8 +131,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
* completion before Autonomous is entered.
|
||||
*
|
||||
* <p>This must be used to ensure that the communications code starts. In the future it would be
|
||||
* nice
|
||||
* to put this code into it's own task that loads on boot so ensure that it runs.
|
||||
* nice to put this code into it's own task that loads on boot so ensure that it runs.
|
||||
*/
|
||||
protected RobotBase() {
|
||||
final NetworkTableInstance inst = NetworkTableInstance.getDefault();
|
||||
@@ -159,8 +156,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
public void close() {}
|
||||
|
||||
/**
|
||||
* Get if the robot is a simulation.
|
||||
@@ -199,8 +195,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the robot is currently in Autonomous mode as determined by the field
|
||||
* controls.
|
||||
* Determine if the robot is currently in Autonomous mode as determined by the field controls.
|
||||
*
|
||||
* @return True if the robot is currently operating Autonomously.
|
||||
*/
|
||||
@@ -209,8 +204,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the robot is current in Autonomous mode and enabled as determined by
|
||||
* the field controls.
|
||||
* Determine if the robot is current in Autonomous mode and enabled as determined by the field
|
||||
* controls.
|
||||
*
|
||||
* @return True if the robot is currently operating autonomously while enabled.
|
||||
*/
|
||||
@@ -219,8 +214,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the robot is currently in Test mode as determined by the driver
|
||||
* station.
|
||||
* Determine if the robot is currently in Test mode as determined by the driver station.
|
||||
*
|
||||
* @return True if the robot is currently operating in Test mode.
|
||||
*/
|
||||
@@ -239,8 +233,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the robot is current in Operator Control mode and enabled as determined by
|
||||
* the field controls.
|
||||
* Determine if the robot is current in Operator Control mode and enabled as determined by the
|
||||
* field controls.
|
||||
*
|
||||
* @return True if the robot is currently operating in Tele-Op mode while enabled.
|
||||
*/
|
||||
@@ -257,14 +251,10 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
return m_ds.isNewControlData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
/** Provide an alternate "main loop" via startCompetition(). */
|
||||
public abstract void startCompetition();
|
||||
|
||||
/**
|
||||
* Ends the main loop in startCompetition().
|
||||
*/
|
||||
/** Ends the main loop in startCompetition(). */
|
||||
public abstract void endCompetition();
|
||||
|
||||
@SuppressWarnings("MissingJavadocMethod")
|
||||
@@ -286,11 +276,11 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
private static RobotBase m_robotCopy;
|
||||
private static boolean m_suppressExitWarning;
|
||||
|
||||
/**
|
||||
* Run the robot main loop.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable",
|
||||
"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
/** Run the robot main loop. */
|
||||
@SuppressWarnings({
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable",
|
||||
"PMD.CyclomaticComplexity", "PMD.NPathComplexity"
|
||||
})
|
||||
private static <T extends RobotBase> void runRobot(Supplier<T> robotSupplier) {
|
||||
System.out.println("********** Robot program starting **********");
|
||||
|
||||
@@ -307,8 +297,9 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
if (elements.length > 0) {
|
||||
robotName = elements[0].getClassName();
|
||||
}
|
||||
DriverStation.reportError("Unhandled exception instantiating robot " + robotName + " "
|
||||
+ throwable.toString(), elements);
|
||||
DriverStation.reportError(
|
||||
"Unhandled exception instantiating robot " + robotName + " " + throwable.toString(),
|
||||
elements);
|
||||
DriverStation.reportWarning("Robots should not quit, but yours did!", false);
|
||||
DriverStation.reportError("Could not instantiate robot " + robotName + "!", false);
|
||||
return;
|
||||
@@ -334,8 +325,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
DriverStation.reportError("Could not write FRC_Lib_Version.ini: " + ex.toString(),
|
||||
ex.getStackTrace());
|
||||
DriverStation.reportError(
|
||||
"Could not write FRC_Lib_Version.ini: " + ex.toString(), ex.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,8 +338,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
if (cause != null) {
|
||||
throwable = cause;
|
||||
}
|
||||
DriverStation.reportError("Unhandled exception: " + throwable.toString(),
|
||||
throwable.getStackTrace());
|
||||
DriverStation.reportError(
|
||||
"Unhandled exception: " + throwable.toString(), throwable.getStackTrace());
|
||||
errorOnExit = true;
|
||||
} finally {
|
||||
m_runMutex.lock();
|
||||
@@ -360,7 +351,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
if (errorOnExit) {
|
||||
DriverStation.reportError(
|
||||
"The startCompetition() method (or methods called by it) should have "
|
||||
+ "handled the exception above.", false);
|
||||
+ "handled the exception above.",
|
||||
false);
|
||||
} else {
|
||||
DriverStation.reportError("Unexpected return from startCompetition() method.", false);
|
||||
}
|
||||
@@ -368,18 +360,14 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppress the "Robots should not quit" message.
|
||||
*/
|
||||
/** Suppress the "Robots should not quit" message. */
|
||||
public static void suppressExitWarning(boolean value) {
|
||||
m_runMutex.lock();
|
||||
m_suppressExitWarning = value;
|
||||
m_runMutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starting point for the applications.
|
||||
*/
|
||||
/** Starting point for the applications. */
|
||||
public static <T extends RobotBase> void startRobot(Supplier<T> robotSupplier) {
|
||||
if (!HAL.initialize(500, 0)) {
|
||||
throw new IllegalStateException("Failed to initialize. Terminating");
|
||||
@@ -389,14 +377,17 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
// Needed because all the OpenCV JNI functions don't have built in loading
|
||||
CameraServerJNI.enumerateSinks();
|
||||
|
||||
HAL.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java, 0,
|
||||
WPILibVersion.Version);
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Language, tInstances.kLanguage_Java, 0, WPILibVersion.Version);
|
||||
|
||||
if (HAL.hasMain()) {
|
||||
Thread thread = new Thread(() -> {
|
||||
runRobot(robotSupplier);
|
||||
HAL.exitMain();
|
||||
}, "robot main");
|
||||
Thread thread =
|
||||
new Thread(
|
||||
() -> {
|
||||
runRobot(robotSupplier);
|
||||
HAL.exitMain();
|
||||
},
|
||||
"robot main");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
HAL.runMain();
|
||||
|
||||
Reference in New Issue
Block a user