Add additional checkstyle checks

This commit is contained in:
md_5 2020-01-24 17:37:30 +11:00
parent 612fd8e1c2
commit 85e683b7eb
35 changed files with 227 additions and 202 deletions

View file

@ -50,9 +50,34 @@
<module name="RedundantImport"/> <module name="RedundantImport"/>
<module name="UnusedImports"/> <module name="UnusedImports"/>
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoLineWrap"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true"/>
</module>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="SingleSpaceSeparator"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<property name="allowEmptyCatches" value="true"/>
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
</module>
<!-- See http://checkstyle.sourceforge.net/config_modifiers.html --> <!-- See http://checkstyle.sourceforge.net/config_modifiers.html -->
<module name="ModifierOrder"/> <module name="ModifierOrder"/>
<!-- See https://checkstyle.org/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly"/>
<module name="RightCurly"/>
<!-- See http://checkstyle.sourceforge.net/config_design.html --> <!-- See http://checkstyle.sourceforge.net/config_design.html -->
<module name="FinalClass"/> <module name="FinalClass"/>
<module name="InterfaceIsType"/> <module name="InterfaceIsType"/>

View file

@ -73,8 +73,9 @@ public class TimingsCommand extends BukkitCommand {
if (separate) { if (separate) {
fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName()); fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName());
fileTimings.println("Plugin " + pluginIdx); fileTimings.println("Plugin " + pluginIdx);
} else {
fileTimings.println(plugin.getDescription().getFullName());
} }
else fileTimings.println(plugin.getDescription().getFullName());
for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) { for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
if (listener instanceof TimedRegisteredListener) { if (listener instanceof TimedRegisteredListener) {
TimedRegisteredListener trl = (TimedRegisteredListener) listener; TimedRegisteredListener trl = (TimedRegisteredListener) listener;

View file

@ -826,10 +826,10 @@ public class MemorySection implements ConfigurationSection {
} }
protected boolean isPrimitiveWrapper(@Nullable Object input) { protected boolean isPrimitiveWrapper(@Nullable Object input) {
return input instanceof Integer || input instanceof Boolean || return input instanceof Integer || input instanceof Boolean
input instanceof Character || input instanceof Byte || || input instanceof Character || input instanceof Byte
input instanceof Short || input instanceof Double || || input instanceof Short || input instanceof Double
input instanceof Long || input instanceof Float; || input instanceof Long || input instanceof Float;
} }
@Nullable @Nullable

View file

@ -9,6 +9,7 @@ public class MinecraftFont extends MapFont {
private static final int spaceSize = 2; private static final int spaceSize = 2;
// CHECKSTYLE:OFF
private static final String fontChars = private static final String fontChars =
" !\"#$%&'()*+,-./0123456789:;<=>?" + " !\"#$%&'()*+,-./0123456789:;<=>?" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" +
@ -278,6 +279,7 @@ public class MinecraftFont extends MapFont {
/* 254 */ {0,0,60,60,60,60,0,0}, /* 254 */ {0,0,60,60,60,60,0,0},
/* 255 */ {0,0,0,0,0,0,0,0}, /* 255 */ {0,0,0,0,0,0,0,0},
}; };
// CHECKSTYLE:ON
/** /**
* A static non-malleable MinecraftFont. * A static non-malleable MinecraftFont.

View file

@ -49,7 +49,7 @@ import org.yaml.snakeyaml.error.YAMLException;
*/ */
public final class JavaPluginLoader implements PluginLoader { public final class JavaPluginLoader implements PluginLoader {
final Server server; final Server server;
private final Pattern[] fileFilters = new Pattern[] { Pattern.compile("\\.jar$"), }; private final Pattern[] fileFilters = new Pattern[]{Pattern.compile("\\.jar$")};
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>(); private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>(); private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>();
@ -288,8 +288,7 @@ public final class JavaPluginLoader implements PluginLoader {
plugin.getLogger().log( plugin.getLogger().log(
Level.WARNING, Level.WARNING,
String.format( String.format(
"\"%s\" has registered a listener for %s on method \"%s\", but the event is Deprecated." + "\"%s\" has registered a listener for %s on method \"%s\", but the event is Deprecated. \"%s\"; please notify the authors %s.",
" \"%s\"; please notify the authors %s.",
plugin.getDescription().getFullName(), plugin.getDescription().getFullName(),
clazz.getName(), clazz.getName(),
method.toGenericString(), method.toGenericString(),

View file

@ -1,3 +1,4 @@
// CHECKSTYLE:OFF
package org.bukkit.util.noise; package org.bukkit.util.noise;
import java.util.Random; import java.util.Random;

View file

@ -22,23 +22,23 @@ public class YamlConfigurationTest extends FileConfigurationTest {
@Override @Override
public String getTestValuesString() { public String getTestValuesString() {
return "integer: -2147483648\n" + return "integer: -2147483648\n"
"string: String Value\n" + + "string: String Value\n"
"long: 9223372036854775807\n" + + "long: 9223372036854775807\n"
"true-boolean: true\n" + + "true-boolean: true\n"
"false-boolean: false\n" + + "false-boolean: false\n"
"vector:\n" + + "vector:\n"
" ==: Vector\n" + + " ==: Vector\n"
" x: 12345.67\n" + + " x: 12345.67\n"
" y: 64.0\n" + + " y: 64.0\n"
" z: -12345.6789\n" + + " z: -12345.6789\n"
"list:\n" + + "list:\n"
"- 1\n" + + "- 1\n"
"- 2\n" + + "- 2\n"
"- 3\n" + + "- 3\n"
"- 4\n" + + "- 4\n"
"- 5\n" + + "- 5\n"
"'42': The Answer\n"; + "'42': The Answer\n";
} }
@Test @Test

View file

@ -25,8 +25,7 @@ import org.junit.Test;
public class MaterialDataTest { public class MaterialDataTest {
@Test @Test
public void testDoor() public void testDoor() {
{
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
Door door = new Door(); Door door = new Door();
assertThat("Constructed with default door type", door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR)); assertThat("Constructed with default door type", door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR));
@ -41,19 +40,16 @@ public class MaterialDataTest {
BlockFace[] directions = new BlockFace[]{BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH}; BlockFace[] directions = new BlockFace[]{BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH};
boolean[] openStates = new boolean[]{false, true}; boolean[] openStates = new boolean[]{false, true};
boolean[] hingeStates = new boolean[]{false, true}; boolean[] hingeStates = new boolean[]{false, true};
for(Material type : types) for (Material type : types) {
{
// Test bottom half // Test bottom half
for(BlockFace facing : directions) for (BlockFace facing : directions) {
{
door = new Door(type, facing); door = new Door(type, facing);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat("Constructed with correct door type", door.getItemType(), equalTo(type));
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false));
assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing));
assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); assertThat("Constructed with default open state", door.isOpen(), equalTo(false));
for(boolean openState : openStates) for (boolean openState : openStates) {
{
door = new Door(type, facing, openState); door = new Door(type, facing, openState);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat("Constructed with correct door type", door.getItemType(), equalTo(type));
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false));
@ -63,8 +59,7 @@ public class MaterialDataTest {
} }
// Test top half // Test top half
for(boolean hingeState : hingeStates) for (boolean hingeState : hingeStates) {
{
door = new Door(type, hingeState); door = new Door(type, hingeState);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat("Constructed with correct door type", door.getItemType(), equalTo(type));
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(true)); assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(true));

View file

@ -71,7 +71,9 @@ public class PluginManagerTest {
} catch (Throwable ex) { } catch (Throwable ex) {
store.value = ex; store.value = ex;
} }
}}); }
}
);
secondThread.start(); secondThread.start();
secondThread.join(); secondThread.join();
if (store.value != null) { if (store.value != null) {

View file

@ -38,7 +38,7 @@ public class StringUtilTest {
@Test @Test
public void copyTokenTest() { public void copyTokenTest() {
String token = "ab"; String token = "ab";
Iterable<String> original = ImmutableList.of("ab12", "aC561", "AB5195", "Ab76", "", "a"); List<String> original = ImmutableList.of("ab12", "aC561", "AB5195", "Ab76", "", "a");
List<String> expected = ImmutableList.of("ab12", "AB5195", "Ab76"); List<String> expected = ImmutableList.of("ab12", "AB5195", "Ab76");
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
assertThat(StringUtil.copyPartialMatches(token, original, list), is(expected)); assertThat(StringUtil.copyPartialMatches(token, original, list), is(expected));