mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-25 01:57:48 +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
|
* @param field the field to format
|
||||||
* @return description of the field
|
* @return description of the field
|
||||||
*/
|
*/
|
||||||
private static String formatField(Field field) {
|
private static String formatField(Field field) {
|
||||||
String modifiersText = "";
|
String modifiersText = Modifier.toString(field.getModifiers());
|
||||||
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 ";
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.format("[%s] %s %s %s", field.getDeclaringClass().getSimpleName(), modifiersText.trim(),
|
return String.format("[%s] %s %s %s", field.getDeclaringClass().getSimpleName(), modifiersText.trim(),
|
||||||
field.getType().getSimpleName(), field.getName());
|
field.getType().getSimpleName(), field.getName());
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,22 @@ package tools.messages;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileIoUtils;
|
import tools.utils.FileIoUtils;
|
||||||
import tools.utils.ToolTask;
|
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task which checks for {@link MessageKey} usages.
|
* 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 =
|
private static final Predicate<File> SHOULD_CHECK_FILE =
|
||||||
file -> file.getName().endsWith(".java") && !file.getName().endsWith("MessageKey.java");
|
file -> file.getName().endsWith(".java") && !file.getName().endsWith("MessageKey.java");
|
||||||
@ -30,12 +28,7 @@ public class CheckMessageKeyUsages implements ToolTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Scanner scanner) {
|
public void executeDefault() {
|
||||||
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();
|
List<MessageKey> unusedKeys = findUnusedKeys();
|
||||||
if (unusedKeys.isEmpty()) {
|
if (unusedKeys.isEmpty()) {
|
||||||
System.out.println("No unused MessageKey entries found :)");
|
System.out.println("No unused MessageKey entries found :)");
|
||||||
@ -43,12 +36,6 @@ public class CheckMessageKeyUsages implements ToolTask {
|
|||||||
System.out.println("Did not find usages for keys:\n- " +
|
System.out.println("Did not find usages for keys:\n- " +
|
||||||
String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name)));
|
String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name)));
|
||||||
}
|
}
|
||||||
} 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- ")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MessageKey> findUnusedKeys() {
|
private List<MessageKey> findUnusedKeys() {
|
||||||
@ -57,7 +44,7 @@ public class CheckMessageKeyUsages implements ToolTask {
|
|||||||
|
|
||||||
Consumer<File> fileProcessor = file -> {
|
Consumer<File> fileProcessor = file -> {
|
||||||
String source = FileIoUtils.readFromFile(file.toPath());
|
String source = FileIoUtils.readFromFile(file.toPath());
|
||||||
keys.removeIf(key -> source.contains(key.name()));
|
keys.removeIf(key -> source.contains("MessageKey." + key.name()));
|
||||||
};
|
};
|
||||||
|
|
||||||
walkJavaFileTree(sourceFolder, fileProcessor);
|
walkJavaFileTree(sourceFolder, fileProcessor);
|
||||||
|
Loading…
Reference in New Issue
Block a user