Skip to content

Commit

Permalink
Remove MagicNumber checkstyle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rom1v committed Mar 28, 2020
1 parent 4adf5fd commit 5031b2c
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 20 deletions.
5 changes: 0 additions & 5 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ page at http://checkstyle.sourceforge.net/config.html -->
</module>
<module name="IllegalInstantiation" />
<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="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private ControlMessage parseInjectText() {
return ControlMessage.createInjectText(text);
}

@SuppressWarnings("checkstyle:MagicNumber")
private ControlMessage parseInjectTouchEvent() {
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
return null;
Expand Down Expand Up @@ -171,12 +170,10 @@ private static Position readPosition(ByteBuffer buffer) {
return new Position(x, y, screenWidth, screenHeight);
}

@SuppressWarnings("checkstyle:MagicNumber")
private static int toUnsigned(short value) {
return value & 0xffff;
}

@SuppressWarnings("checkstyle:MagicNumber")
private static int toUnsigned(byte value) {
return value & 0xff;
}
Expand Down
1 change: 0 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void initPointers() {
}
}

@SuppressWarnings("checkstyle:MagicNumber")
public void control() throws IOException {
// on start, power on the device
if (!device.isScreenOn()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void close() throws IOException {
controlSocket.close();
}

@SuppressWarnings("checkstyle:MagicNumber")
private void send(String deviceName, int width, int height) throws IOException {
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class DeviceMessageWriter {
private final byte[] rawBuffer = new byte[MAX_EVENT_SIZE];
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);

@SuppressWarnings("checkstyle:MagicNumber")
public void writeTo(DeviceMessage msg, OutputStream output) throws IOException {
buffer.clear();
buffer.put((byte) DeviceMessage.TYPE_CLIPBOARD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private static MediaCodec createCodec() throws IOException {
return MediaCodec.createEncoderByType("video/avc");
}

@SuppressWarnings("checkstyle:MagicNumber")
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) {
MediaFormat format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, "video/avc");
Expand Down
1 change: 0 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/ScreenInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ private static String formatCrop(Rect rect) {
return rect.width() + ":" + rect.height() + ":" + rect.left + ":" + rect.top;
}

@SuppressWarnings("checkstyle:MagicNumber")
private static Size computeVideoSize(int w, int h, int maxSize) {
// Compute the video size and the padding of the content inside this video.
// Principle:
Expand Down
3 changes: 0 additions & 3 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void run() {
}).start();
}

@SuppressWarnings("checkstyle:MagicNumber")
private static Options createOptions(String... args) {
if (args.length < 1) {
throw new IllegalArgumentException("Missing client version");
Expand Down Expand Up @@ -115,7 +114,6 @@ private static Options createOptions(String... args) {
return options;
}

@SuppressWarnings("checkstyle:MagicNumber")
private static Rect parseCrop(String crop) {
if ("-".equals(crop)) {
return null;
Expand All @@ -140,7 +138,6 @@ private static void unlinkSelf() {
}
}

@SuppressWarnings("checkstyle:MagicNumber")
private static void suggestFix(Throwable e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (e instanceof MediaCodec.CodecException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ private StringUtils() {
// not instantiable
}

@SuppressWarnings("checkstyle:MagicNumber")
public static int getUtf8TruncationIndex(byte[] utf8, int maxLength) {
int len = utf8.length;
if (len <= maxLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void testParseLongTextEvent() throws IOException {
}

@Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseTouchEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader();

Expand Down Expand Up @@ -116,7 +115,6 @@ public void testParseTouchEvent() throws IOException {
}

@Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseScrollEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
public class StringUtilsTest {

@Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testUtf8Truncate() {
String s = "aÉbÔc";
byte[] utf8 = s.getBytes(StandardCharsets.UTF_8);
Expand Down

0 comments on commit 5031b2c

Please sign in to comment.