Remove MagicNumber checkstyle

There are a lot of "magic numbers" that we really don't want to extract
as a constant.

Until now, many @SuppressWarnings annotations were added, but it makes
no sense to check for magic number if we silent the warnings everywhere.
pr1238
Romain Vimont 4 years ago
parent 4adf5fde6d
commit 5031b2c8ff

@ -129,11 +129,6 @@ page at http://checkstyle.sourceforge.net/config.html -->
</module> </module>
<module name="IllegalInstantiation" /> <module name="IllegalInstantiation" />
<module name="InnerAssignment" /> <module name="InnerAssignment" />
<module name="MagicNumber">
<property name="severity" value="info" />
<property name="ignoreHashCodeMethod" value="true" />
<property name="ignoreAnnotation" value="true" />
</module>
<module name="MissingSwitchDefault" /> <module name="MissingSwitchDefault" />
<module name="SimplifyBooleanExpression" /> <module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" /> <module name="SimplifyBooleanReturn" />

@ -121,7 +121,6 @@ public class ControlMessageReader {
return ControlMessage.createInjectText(text); return ControlMessage.createInjectText(text);
} }
@SuppressWarnings("checkstyle:MagicNumber")
private ControlMessage parseInjectTouchEvent() { private ControlMessage parseInjectTouchEvent() {
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) { if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
return null; return null;
@ -171,12 +170,10 @@ public class ControlMessageReader {
return new Position(x, y, screenWidth, screenHeight); return new Position(x, y, screenWidth, screenHeight);
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static int toUnsigned(short value) { private static int toUnsigned(short value) {
return value & 0xffff; return value & 0xffff;
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static int toUnsigned(byte value) { private static int toUnsigned(byte value) {
return value & 0xff; return value & 0xff;
} }

@ -47,7 +47,6 @@ public class Controller {
} }
} }
@SuppressWarnings("checkstyle:MagicNumber")
public void control() throws IOException { public void control() throws IOException {
// on start, power on the device // on start, power on the device
if (!device.isScreenOn()) { if (!device.isScreenOn()) {

@ -84,7 +84,6 @@ public final class DesktopConnection implements Closeable {
controlSocket.close(); controlSocket.close();
} }
@SuppressWarnings("checkstyle:MagicNumber")
private void send(String deviceName, int width, int height) throws IOException { private void send(String deviceName, int width, int height) throws IOException {
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4]; byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];

@ -13,7 +13,6 @@ public class DeviceMessageWriter {
private final byte[] rawBuffer = new byte[MAX_EVENT_SIZE]; private final byte[] rawBuffer = new byte[MAX_EVENT_SIZE];
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer); private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
@SuppressWarnings("checkstyle:MagicNumber")
public void writeTo(DeviceMessage msg, OutputStream output) throws IOException { public void writeTo(DeviceMessage msg, OutputStream output) throws IOException {
buffer.clear(); buffer.clear();
buffer.put((byte) DeviceMessage.TYPE_CLIPBOARD); buffer.put((byte) DeviceMessage.TYPE_CLIPBOARD);

@ -145,7 +145,6 @@ public class ScreenEncoder implements Device.RotationListener {
return MediaCodec.createEncoderByType("video/avc"); return MediaCodec.createEncoderByType("video/avc");
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) { private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) {
MediaFormat format = new MediaFormat(); MediaFormat format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, "video/avc"); format.setString(MediaFormat.KEY_MIME, "video/avc");

@ -104,7 +104,6 @@ public final class ScreenInfo {
return rect.width() + ":" + rect.height() + ":" + rect.left + ":" + rect.top; return rect.width() + ":" + rect.height() + ":" + rect.left + ":" + rect.top;
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static Size computeVideoSize(int w, int h, int maxSize) { private static Size computeVideoSize(int w, int h, int maxSize) {
// Compute the video size and the padding of the content inside this video. // Compute the video size and the padding of the content inside this video.
// Principle: // Principle:

@ -69,7 +69,6 @@ public final class Server {
}).start(); }).start();
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static Options createOptions(String... args) { private static Options createOptions(String... args) {
if (args.length < 1) { if (args.length < 1) {
throw new IllegalArgumentException("Missing client version"); throw new IllegalArgumentException("Missing client version");
@ -115,7 +114,6 @@ public final class Server {
return options; return options;
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static Rect parseCrop(String crop) { private static Rect parseCrop(String crop) {
if ("-".equals(crop)) { if ("-".equals(crop)) {
return null; return null;
@ -140,7 +138,6 @@ public final class Server {
} }
} }
@SuppressWarnings("checkstyle:MagicNumber")
private static void suggestFix(Throwable e) { private static void suggestFix(Throwable e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (e instanceof MediaCodec.CodecException) { if (e instanceof MediaCodec.CodecException) {

@ -5,7 +5,6 @@ public final class StringUtils {
// not instantiable // not instantiable
} }
@SuppressWarnings("checkstyle:MagicNumber")
public static int getUtf8TruncationIndex(byte[] utf8, int maxLength) { public static int getUtf8TruncationIndex(byte[] utf8, int maxLength) {
int len = utf8.length; int len = utf8.length;
if (len <= maxLength) { if (len <= maxLength) {

@ -80,7 +80,6 @@ public class ControlMessageReaderTest {
} }
@Test @Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseTouchEvent() throws IOException { public void testParseTouchEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader(); ControlMessageReader reader = new ControlMessageReader();
@ -116,7 +115,6 @@ public class ControlMessageReaderTest {
} }
@Test @Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseScrollEvent() throws IOException { public void testParseScrollEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader(); ControlMessageReader reader = new ControlMessageReader();

@ -8,7 +8,6 @@ import java.nio.charset.StandardCharsets;
public class StringUtilsTest { public class StringUtilsTest {
@Test @Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testUtf8Truncate() { public void testUtf8Truncate() {
String s = "aÉbÔc"; String s = "aÉbÔc";
byte[] utf8 = s.getBytes(StandardCharsets.UTF_8); byte[] utf8 = s.getBytes(StandardCharsets.UTF_8);

Loading…
Cancel
Save