From fddb3bf265dd0607e5e028bd20776e7670522ba3 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 11 Mar 2018 19:08:21 +0100 Subject: [PATCH] Fix minor Checkstyle violations - Mostly missing JavaDoc, some line lengths --- .../authme/debug/MySqlDefaultChanger.java | 5 +++ .../fr/xephi/authme/datasource/MySQL.java | 11 +++++++ .../fr/xephi/authme/datasource/SQLite.java | 1 + .../listener/PlayerListener19Spigot.java | 3 +- .../permission/handlers/LuckPermsHandler.java | 3 +- .../register/ProcessSyncEmailRegister.java | 9 +++++- .../register/ProcessSyncPasswordRegister.java | 6 ++++ .../xephi/authme/settings/SettingsWarner.java | 6 ++-- .../authme/task/purge/PurgeExecutor.java | 15 +++++++++ .../java/fr/xephi/authme/AuthMeMatchers.java | 1 + .../java/fr/xephi/authme/ClassCollector.java | 6 ++-- .../fr/xephi/authme/ReflectionTestUtils.java | 10 +++++- .../data/limbo/LimboPlayerMatchers.java | 4 ++- .../datasource/SqlDataSourceTestUtil.java | 9 ++++++ .../tools/dependencygraph/DrawDependency.java | 3 +- .../EncryptionMethodInfoGatherer.java | 6 ++++ .../permissions/PermissionNodesGatherer.java | 1 + .../permissions/PermissionsListWriter.java | 8 +++-- .../TranslationPageGenerator.java | 6 ++-- .../translations/TranslationsGatherer.java | 32 ++++++++++++------- .../filegeneration/GeneratePluginYml.java | 2 +- .../tools/messages/CheckMessageKeyUsages.java | 19 ++--------- src/test/java/tools/utils/FileIoUtils.java | 24 ++++++++++++++ 23 files changed, 142 insertions(+), 48 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java b/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java index 5fbd6993..4f201fa5 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java @@ -172,6 +172,11 @@ class MySqlDefaultChanger implements DebugSection { + sender.getName() + "'"); } + /** + * Outputs the current definitions of all {@link Columns} which can be migrated. + * + * @param sender command sender to output the data to + */ private void showColumnDetails(CommandSender sender) { sender.sendMessage(ChatColor.BLUE + "MySQL column details"); final String tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE); diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 01a240fe..ce46baad 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -28,6 +28,10 @@ import java.util.Set; import static fr.xephi.authme.datasource.SqlDataSourceUtils.getNullableLong; import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException; +/** + * MySQL data source. + */ +@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore public class MySQL implements DataSource { private boolean useSsl; @@ -728,6 +732,13 @@ public class MySQL implements DataSource { return players; } + /** + * Creates a {@link PlayerAuth} object with the data from the provided result set. + * + * @param row the result set to read from + * @return generated player auth object with the data from the result set + * @throws SQLException . + */ private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException { String salt = col.SALT.isEmpty() ? null : row.getString(col.SALT); int group = col.GROUP.isEmpty() ? -1 : row.getInt(col.GROUP); diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 422d57b1..ada94afb 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -28,6 +28,7 @@ import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException; /** * SQLite data source. */ +@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore public class SQLite implements DataSource { private final Settings settings; diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java b/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java index d5f46b30..1684887e 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java @@ -12,10 +12,11 @@ import javax.inject.Inject; public class PlayerListener19Spigot implements Listener { + private static boolean isPlayerSpawnLocationEventCalled = false; + @Inject private TeleportationService teleportationService; - private static boolean isPlayerSpawnLocationEventCalled = false; public static boolean isPlayerSpawnLocationEventCalled() { return isPlayerSpawnLocationEventCalled; diff --git a/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java index ad46a35c..9e52746f 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java @@ -62,7 +62,8 @@ public class LuckPermsHandler implements PermissionHandler { return false; } - DataMutateResult result = user.setPermissionUnchecked(luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build()); + DataMutateResult result = user.setPermissionUnchecked( + luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build()); if (result == DataMutateResult.FAIL) { return false; } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index b43a8563..6ab4a874 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -10,7 +10,9 @@ import org.bukkit.entity.Player; import javax.inject.Inject; - +/** + * Performs synchronous tasks after a successful {@link RegistrationType#EMAIL email registration}. + */ public class ProcessSyncEmailRegister implements SynchronousProcess { @Inject @@ -22,6 +24,11 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { ProcessSyncEmailRegister() { } + /** + * Performs sync tasks for a player which has just registered by email. + * + * @param player the recently registered player + */ public void processEmailRegister(Player player) { service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); limboService.replaceTasksAfterRegistration(player); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index ea5c028e..30e7f59a 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import javax.inject.Inject; /** + * Performs synchronous tasks after a successful {@link RegistrationType#PASSWORD password registration}. */ public class ProcessSyncPasswordRegister implements SynchronousProcess { @@ -46,6 +47,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { } } + /** + * Processes a player having registered with a password. + * + * @param player the newly registered player + */ public void processPasswordRegister(Player player) { service.send(player, MessageKey.REGISTER_SUCCESS); diff --git a/src/main/java/fr/xephi/authme/settings/SettingsWarner.java b/src/main/java/fr/xephi/authme/settings/SettingsWarner.java index ca049d56..c94b0455 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsWarner.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsWarner.java @@ -56,9 +56,9 @@ public class SettingsWarner { // Warn if spigot.yml has settings.bungeecord set to true but config.yml has Hooks.bungeecord set to false if (Utils.isSpigot() && Bukkit.spigot().getConfig().getBoolean("settings.bungeecord") && !settings.getProperty(HooksSettings.BUNGEECORD)) { - ConsoleLogger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in" + - " bungeecord mode (see your spigot.yml). In order to allow the datasource caching and the AuthMeBungee" + - " add-on to work properly you have to enable this option!"); + ConsoleLogger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in" + + " bungeecord mode (see your spigot.yml). In order to allow the datasource caching and the" + + " AuthMeBungee add-on to work properly you have to enable this option!"); } // Check if argon2 library is present and can be loaded diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index 04b7f5cc..a3e42f75 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -61,6 +61,11 @@ public class PurgeExecutor { purgePermissions(players); } + /** + * Purges data from the AntiXray plugin. + * + * @param cleared the players whose data should be cleared + */ synchronized void purgeAntiXray(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_ANTI_XRAY_FILE)) { return; @@ -95,6 +100,11 @@ public class PurgeExecutor { ConsoleLogger.info(ChatColor.GOLD + "Deleted " + names.size() + " user accounts"); } + /** + * Purges data from the LimitedCreative plugin. + * + * @param cleared the players whose data should be cleared + */ synchronized void purgeLimitedCreative(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_LIMITED_CREATIVE_INVENTORIES)) { return; @@ -191,6 +201,11 @@ public class PurgeExecutor { ConsoleLogger.info("AutoPurge: Removed " + deletedFiles + " EssentialsFiles"); } + /** + * Removes permission data (groups a user belongs to) for the given players. + * + * @param cleared the players to remove data for + */ synchronized void purgePermissions(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_PERMISSIONS)) { return; diff --git a/src/test/java/fr/xephi/authme/AuthMeMatchers.java b/src/test/java/fr/xephi/authme/AuthMeMatchers.java index 69f2ac27..33768883 100644 --- a/src/test/java/fr/xephi/authme/AuthMeMatchers.java +++ b/src/test/java/fr/xephi/authme/AuthMeMatchers.java @@ -11,6 +11,7 @@ import java.util.Objects; /** * Custom matchers for AuthMe entities. */ +@SuppressWarnings("checkstyle:JavadocMethod") // Justification: Javadoc would be huge because of the many parameters public final class AuthMeMatchers { private AuthMeMatchers() { diff --git a/src/test/java/fr/xephi/authme/ClassCollector.java b/src/test/java/fr/xephi/authme/ClassCollector.java index 886201b0..23c065e8 100644 --- a/src/test/java/fr/xephi/authme/ClassCollector.java +++ b/src/test/java/fr/xephi/authme/ClassCollector.java @@ -67,7 +67,7 @@ public class ClassCollector { public List> collectClasses(Predicate> filter) { File rootFolder = new File(root); List> collection = new ArrayList<>(); - collectClasses(rootFolder, filter, collection); + gatherClassesFromFile(rootFolder, filter, collection); return collection; } @@ -124,14 +124,14 @@ public class ClassCollector { * @param filter the class predicate * @param collection collection to add classes to */ - private void collectClasses(File folder, Predicate> filter, List> collection) { + private void gatherClassesFromFile(File folder, Predicate> filter, List> collection) { File[] files = folder.listFiles(); if (files == null) { throw new IllegalStateException("Could not read files from '" + folder + "'"); } for (File file : files) { if (file.isDirectory()) { - collectClasses(file, filter, collection); + gatherClassesFromFile(file, filter, collection); } else if (file.isFile()) { Class clazz = loadTaskClassFromFile(file); if (clazz != null && filter.test(clazz)) { diff --git a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java index 033bed27..963fbf71 100644 --- a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java +++ b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java @@ -82,7 +82,6 @@ public final class ReflectionTestUtils { * @param clazz the class to retrieve a method from * @param methodName the name of the method * @param parameterTypes the parameter types the method to retrieve has - * * @return the method of the class, set to be accessible */ public static Method getMethod(Class clazz, String methodName, Class... parameterTypes) { @@ -96,6 +95,15 @@ public final class ReflectionTestUtils { } } + /** + * Invokes the given method on the provided instance with the given parameters. + * + * @param method the method to invoke + * @param instance the instance to invoke the method on (null for static methods) + * @param parameters the parameters to pass to the method + * @param return value of the method + * @return method return value + */ @SuppressWarnings("unchecked") public static V invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java index bb5a452e..78386e2d 100644 --- a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java +++ b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java @@ -14,6 +14,7 @@ import static org.hamcrest.collection.IsIterableContainingInOrder.contains; /** * Contains matchers for LimboPlayer. */ +@SuppressWarnings("checkstyle:JavadocMethod") // Justification: Javadoc would be huge because of the many parameters public final class LimboPlayerMatchers { private LimboPlayerMatchers() { @@ -45,7 +46,8 @@ public final class LimboPlayerMatchers { @Override public void describeMismatchSafely(LimboPlayer item, Description description) { description.appendText(format("Limbo with isOp=%s, groups={%s}, canFly=%s, walkSpeed=%f, flySpeed=%f", - item.isOperator(), String.join(" ,", item.getGroups()), item.isCanFly(), item.getWalkSpeed(), item.getFlySpeed())); + item.isOperator(), String.join(" ,", item.getGroups()), item.isCanFly(), + item.getWalkSpeed(), item.getFlySpeed())); } }; } diff --git a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java index 79a938f6..dd54e39a 100644 --- a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java +++ b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java @@ -27,6 +27,15 @@ public final class SqlDataSourceTestUtil { return new MySQL(settings, hikariDataSource, extensionsFactory); } + /** + * Creates a SQLite implementation for testing purposes. Methods are overridden so the + * provided connection is never overridden. + * + * @param settings settings instance + * @param dataFolder data folder + * @param connection connection to use + * @return the created SQLite instance + */ public static SQLite createSqlite(Settings settings, File dataFolder, Connection connection) { return new SQLite(settings, dataFolder, connection) { // Override reload() so it doesn't run SQLite#connect, since we're given a specific Connection to use diff --git a/src/test/java/tools/dependencygraph/DrawDependency.java b/src/test/java/tools/dependencygraph/DrawDependency.java index 3f34197c..40a3b6b2 100644 --- a/src/test/java/tools/dependencygraph/DrawDependency.java +++ b/src/test/java/tools/dependencygraph/DrawDependency.java @@ -131,7 +131,8 @@ public class DrawDependency implements ToolTask { private Class unwrapGenericClass(Type genericType) { if (genericType == Factory.class || genericType == SingletonStore.class) { Class parameterType = ReflectionUtils.getGenericType(genericType); - Objects.requireNonNull(parameterType, "Parameter type for '" + genericType + "' should be a concrete class"); + Objects.requireNonNull(parameterType, + "Parameter type for '" + genericType + "' should be a concrete class"); return parameterType; } return InjectorUtils.convertToClass(genericType); diff --git a/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java index 86f80838..0362e26c 100644 --- a/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java +++ b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java @@ -56,6 +56,12 @@ public class EncryptionMethodInfoGatherer { } } + /** + * Creates a description of the given hash algorithm based on its annotations. + * + * @param algorithm the algorithm to describe + * @return description of the hash algorithm + */ private static MethodDescription createDescription(HashAlgorithm algorithm) { Class clazz = algorithm.getClazz(); EncryptionMethod method = createEncryptionMethod(clazz); diff --git a/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java index f177cbc6..0b17ebf6 100644 --- a/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java +++ b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java @@ -37,6 +37,7 @@ public class PermissionNodesGatherer { /** * Return a sorted collection of all permission nodes, including its JavaDoc description. * + * @param permission node enum type * @return Ordered map whose keys are the permission nodes and the values the associated JavaDoc */ @SuppressWarnings("unchecked") diff --git a/src/test/java/tools/docs/permissions/PermissionsListWriter.java b/src/test/java/tools/docs/permissions/PermissionsListWriter.java index 797e26e7..1e0e8abd 100644 --- a/src/test/java/tools/docs/permissions/PermissionsListWriter.java +++ b/src/test/java/tools/docs/permissions/PermissionsListWriter.java @@ -4,18 +4,20 @@ import tools.utils.AutoToolTask; import tools.utils.FileIoUtils; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; -import tools.utils.ToolsConstants; import java.util.Map; +import static tools.utils.ToolsConstants.DOCS_FOLDER; +import static tools.utils.ToolsConstants.TOOLS_SOURCE_ROOT; + /** * Task responsible for formatting a permissions node list and * for writing it to a file if desired. */ public class PermissionsListWriter implements AutoToolTask { - private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; - private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md"; + private static final String TEMPLATE_FILE = TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; + private static final String PERMISSIONS_OUTPUT_FILE = DOCS_FOLDER + "permission_nodes.md"; @Override public String getTaskName() { diff --git a/src/test/java/tools/docs/translations/TranslationPageGenerator.java b/src/test/java/tools/docs/translations/TranslationPageGenerator.java index dc555292..dd87973d 100644 --- a/src/test/java/tools/docs/translations/TranslationPageGenerator.java +++ b/src/test/java/tools/docs/translations/TranslationPageGenerator.java @@ -45,10 +45,10 @@ public class TranslationPageGenerator implements AutoToolTask { NestedTagValue translationValuesHolder = new NestedTagValue(); for (TranslationInfo translation : gatherer.getTranslationInfo()) { - int percentage = (int) Math.round(translation.percentTranslated * 100); - String name = firstNonNull(LANGUAGE_NAMES.get(translation.code), "?"); + int percentage = (int) Math.round(translation.getPercentTranslated() * 100); + String name = firstNonNull(LANGUAGE_NAMES.get(translation.getCode()), "?"); TagValueHolder valueHolder = TagValueHolder.create() - .put("code", translation.code) + .put("code", translation.getCode()) .put("name", name) .put("percentage", Integer.toString(percentage)) .put("color", computeColor(percentage)); diff --git a/src/test/java/tools/docs/translations/TranslationsGatherer.java b/src/test/java/tools/docs/translations/TranslationsGatherer.java index f54843a9..e42b266d 100644 --- a/src/test/java/tools/docs/translations/TranslationsGatherer.java +++ b/src/test/java/tools/docs/translations/TranslationsGatherer.java @@ -25,7 +25,7 @@ public class TranslationsGatherer { public TranslationsGatherer() { gatherTranslations(); - translationInfo.sort((e1, e2) -> getCode(e1).compareTo(getCode(e2))); + translationInfo.sort((e1, e2) -> getSortCode(e1).compareTo(getSortCode(e2))); } public List getTranslationInfo() { @@ -61,16 +61,6 @@ public class TranslationsGatherer { return null; } - public static final class TranslationInfo { - public final String code; - public final double percentTranslated; - - TranslationInfo(String code, double percentTranslated) { - this.code = code; - this.percentTranslated = percentTranslated; - } - } - /** * Returns the language code from the translation info for sorting purposes. * Returns "a" for "en" language code to sort English on top. @@ -78,8 +68,26 @@ public class TranslationsGatherer { * @param info the translation info * @return the language code for sorting */ - private static String getCode(TranslationInfo info) { + private static String getSortCode(TranslationInfo info) { return "en".equals(info.code) ? "a" : info.code; } + public static final class TranslationInfo { + private final String code; + private final double percentTranslated; + + TranslationInfo(String code, double percentTranslated) { + this.code = code; + this.percentTranslated = percentTranslated; + } + + public String getCode() { + return code; + } + + public double getPercentTranslated() { + return percentTranslated; + } + } + } diff --git a/src/test/java/tools/filegeneration/GeneratePluginYml.java b/src/test/java/tools/filegeneration/GeneratePluginYml.java index 04dba91e..cf833b00 100644 --- a/src/test/java/tools/filegeneration/GeneratePluginYml.java +++ b/src/test/java/tools/filegeneration/GeneratePluginYml.java @@ -67,7 +67,7 @@ public class GeneratePluginYml implements AutoToolTask { List pluginYmlLines = FileIoUtils.readLinesFromFile(Paths.get(PLUGIN_YML_FILE)); int lineNr = 0; for (String line : pluginYmlLines) { - if (line.equals("commands:")) { + if ("commands:".equals(line)) { break; } ++lineNr; diff --git a/src/test/java/tools/messages/CheckMessageKeyUsages.java b/src/test/java/tools/messages/CheckMessageKeyUsages.java index d43ad5d0..7387f002 100644 --- a/src/test/java/tools/messages/CheckMessageKeyUsages.java +++ b/src/test/java/tools/messages/CheckMessageKeyUsages.java @@ -33,8 +33,8 @@ public class CheckMessageKeyUsages implements AutoToolTask { if (unusedKeys.isEmpty()) { System.out.println("No unused MessageKey entries found :)"); } else { - System.out.println("Did not find usages for keys:\n- " + - String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name))); + System.out.println("Did not find usages for keys:\n- " + + String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name))); } } @@ -51,21 +51,6 @@ public class CheckMessageKeyUsages implements AutoToolTask { return keys; } - private List findUsagesOfKey(MessageKey key) { - List filesUsingKey = new ArrayList<>(); - File sourceFolder = new File(ToolsConstants.MAIN_SOURCE_ROOT); - - Consumer usagesCollector = file -> { - String source = FileIoUtils.readFromFile(file.toPath()); - if (source.contains(key.name())) { - filesUsingKey.add(file); - } - }; - - walkJavaFileTree(sourceFolder, usagesCollector); - return filesUsingKey; - } - private static void walkJavaFileTree(File folder, Consumer javaFileConsumer) { for (File file : FileIoUtils.listFilesOrThrow(folder)) { if (file.isDirectory()) { diff --git a/src/test/java/tools/utils/FileIoUtils.java b/src/test/java/tools/utils/FileIoUtils.java index eadefd2d..995c71a0 100644 --- a/src/test/java/tools/utils/FileIoUtils.java +++ b/src/test/java/tools/utils/FileIoUtils.java @@ -27,6 +27,12 @@ public final class FileIoUtils { writeToFile(Paths.get(outputFile), contents); } + /** + * Writes the given contents to the file, overriding any existing content. + * + * @param path the file to write to + * @param contents the contents to write + */ public static void writeToFile(Path path, String contents) { try { Files.write(path, contents.getBytes()); @@ -35,6 +41,12 @@ public final class FileIoUtils { } } + /** + * Adds the given contents to the file while keeping any existing content. + * + * @param outputFile the file to write to + * @param contents the contents to append + */ public static void appendToFile(String outputFile, String contents) { try { Files.write(Paths.get(outputFile), contents.getBytes(), StandardOpenOption.APPEND); @@ -47,6 +59,12 @@ public final class FileIoUtils { return readFromFile(Paths.get(file)); } + /** + * Returns the given file's contents as string. + * + * @param file the file to read + * @return the file's contents + */ public static String readFromFile(Path file) { try { return new String(Files.readAllBytes(file), StandardCharsets.UTF_8); @@ -55,6 +73,12 @@ public final class FileIoUtils { } } + /** + * Returns the lines of the given file. + * + * @param path the path of the file to read + * @return the lines of the file + */ public static List readLinesFromFile(Path path) { try { return Files.readAllLines(path, StandardCharsets.UTF_8);