mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 17:47:38 +01:00
Minor: simplify CheckMessageKeyUsages task and make check more strict
This commit is contained in:
parent
610a699c95
commit
b3a191d7e2
@ -123,29 +123,13 @@ public class ClassesConsistencyTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out the field with (most of) its modifiers.
|
||||
* Prints out the field with its modifiers.
|
||||
*
|
||||
* @param field the field to format
|
||||
* @return description of the field
|
||||
*/
|
||||
private static String formatField(Field field) {
|
||||
String modifiersText = "";
|
||||
int modifiers = field.getModifiers();
|
||||
if (Modifier.isPublic(modifiers)) {
|
||||
modifiersText += "public ";
|
||||
} else if (Modifier.isProtected(modifiers)) {
|
||||
modifiersText += "protected ";
|
||||
} else if (Modifier.isPrivate(modifiers)) {
|
||||
modifiersText += "private ";
|
||||
}
|
||||
|
||||
if (Modifier.isStatic(modifiers)) {
|
||||
modifiersText += "static ";
|
||||
}
|
||||
if (Modifier.isFinal(modifiers)) {
|
||||
modifiersText += "final ";
|
||||
}
|
||||
|
||||
String modifiersText = Modifier.toString(field.getModifiers());
|
||||
return String.format("[%s] %s %s %s", field.getDeclaringClass().getSimpleName(), modifiersText.trim(),
|
||||
field.getType().getSimpleName(), field.getName());
|
||||
}
|
||||
|
@ -2,24 +2,22 @@ package tools.messages;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import tools.utils.AutoToolTask;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.ToolTask;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* Task which checks for {@link MessageKey} usages.
|
||||
*/
|
||||
public class CheckMessageKeyUsages implements ToolTask {
|
||||
public class CheckMessageKeyUsages implements AutoToolTask {
|
||||
|
||||
private static final Predicate<File> SHOULD_CHECK_FILE =
|
||||
file -> file.getName().endsWith(".java") && !file.getName().endsWith("MessageKey.java");
|
||||
@ -30,24 +28,13 @@ public class CheckMessageKeyUsages implements ToolTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Scanner scanner) {
|
||||
System.out.println("Enter a message key to find the files where it is used");
|
||||
System.out.println("Enter empty line to search for all unused message keys");
|
||||
String key = scanner.nextLine();
|
||||
|
||||
if (key.trim().isEmpty()) {
|
||||
List<MessageKey> unusedKeys = findUnusedKeys();
|
||||
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)));
|
||||
}
|
||||
public void executeDefault() {
|
||||
List<MessageKey> unusedKeys = findUnusedKeys();
|
||||
if (unusedKeys.isEmpty()) {
|
||||
System.out.println("No unused MessageKey entries found :)");
|
||||
} else {
|
||||
MessageKey messageKey = MessageKey.valueOf(key);
|
||||
List<File> filesUsingKey = findUsagesOfKey(messageKey);
|
||||
System.out.println("The following files use '" + key + "':\n- "
|
||||
+ filesUsingKey.stream().map(File::getName).collect(Collectors.joining("\n- ")));
|
||||
System.out.println("Did not find usages for keys:\n- " +
|
||||
String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +44,7 @@ public class CheckMessageKeyUsages implements ToolTask {
|
||||
|
||||
Consumer<File> fileProcessor = file -> {
|
||||
String source = FileIoUtils.readFromFile(file.toPath());
|
||||
keys.removeIf(key -> source.contains(key.name()));
|
||||
keys.removeIf(key -> source.contains("MessageKey." + key.name()));
|
||||
};
|
||||
|
||||
walkJavaFileTree(sourceFolder, fileProcessor);
|
||||
|
Loading…
Reference in New Issue
Block a user