[Test] Add nullability annotations on InTextDirectivesUtils methods
This commit is contained in:
committed by
TeamCityServer
parent
49f2ac3545
commit
9378d1ff31
+18
-18
@@ -30,7 +30,7 @@ public final class InTextDirectivesUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Integer getPrefixedInt(String fileText, String prefix) {
|
public static Integer getPrefixedInt(@NotNull String fileText, @NotNull String prefix) {
|
||||||
String[] strings = findArrayWithPrefixes(fileText, prefix);
|
String[] strings = findArrayWithPrefixes(fileText, prefix);
|
||||||
if (strings.length > 0) {
|
if (strings.length > 0) {
|
||||||
assert strings.length == 1;
|
assert strings.length == 1;
|
||||||
@@ -41,7 +41,7 @@ public final class InTextDirectivesUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Boolean getPrefixedBoolean(String fileText, String prefix) {
|
public static Boolean getPrefixedBoolean(@NotNull String fileText, @NotNull String prefix) {
|
||||||
String[] strings = findArrayWithPrefixes(fileText, prefix);
|
String[] strings = findArrayWithPrefixes(fileText, prefix);
|
||||||
if (strings.length > 0) {
|
if (strings.length > 0) {
|
||||||
assert strings.length == 1;
|
assert strings.length == 1;
|
||||||
@@ -67,7 +67,7 @@ public final class InTextDirectivesUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> splitValues(List<String> result, String line) {
|
public static List<String> splitValues(@NotNull List<String> result, @NotNull String line) {
|
||||||
String unquoted = StringUtil.unquoteString(line);
|
String unquoted = StringUtil.unquoteString(line);
|
||||||
if (!unquoted.equals(line)) {
|
if (!unquoted.equals(line)) {
|
||||||
result.add(unquoted);
|
result.add(unquoted);
|
||||||
@@ -81,12 +81,12 @@ public final class InTextDirectivesUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDirectiveDefined(String fileText, String directive) {
|
public static boolean isDirectiveDefined(@NotNull String fileText, @NotNull String directive) {
|
||||||
return !findListWithPrefixes(fileText, directive).isEmpty();
|
return !findListWithPrefixes(fileText, directive).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String findStringWithPrefixes(String fileText, String... prefixes) {
|
public static String findStringWithPrefixes(@NotNull String fileText, @NotNull String... prefixes) {
|
||||||
List<String> strings = findListWithPrefixes(fileText, prefixes);
|
List<String> strings = findListWithPrefixes(fileText, prefixes);
|
||||||
if (strings.isEmpty()) {
|
if (strings.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -103,12 +103,12 @@ public final class InTextDirectivesUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<String> findLinesWithPrefixesRemoved(String fileText, String... prefixes) {
|
public static List<String> findLinesWithPrefixesRemoved(@NotNull String fileText, @NotNull String... prefixes) {
|
||||||
return findLinesWithPrefixesRemoved(fileText, true, true, prefixes);
|
return findLinesWithPrefixesRemoved(fileText, true, true, prefixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<String> findLinesWithPrefixesRemoved(String fileText, boolean trim, boolean strict, String... prefixes) {
|
public static List<String> findLinesWithPrefixesRemoved(@NotNull String fileText, boolean trim, boolean strict, @NotNull String... prefixes) {
|
||||||
if (prefixes.length == 0) {
|
if (prefixes.length == 0) {
|
||||||
throw new IllegalArgumentException("Please specify the prefixes to check");
|
throw new IllegalArgumentException("Please specify the prefixes to check");
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ public final class InTextDirectivesUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertHasUnknownPrefixes(String fileText, Collection<String> knownPrefixes) {
|
public static void assertHasUnknownPrefixes(@NotNull String fileText, @NotNull Collection<String> knownPrefixes) {
|
||||||
Set<String> prefixes = new HashSet<>();
|
Set<String> prefixes = new HashSet<>();
|
||||||
|
|
||||||
for (String line : fileNonEmptyCommentedLines(fileText)) {
|
for (String line : fileNonEmptyCommentedLines(fileText)) {
|
||||||
@@ -151,7 +151,7 @@ public final class InTextDirectivesUtils {
|
|||||||
KtAssert.assertTrue("File contains some unexpected directives" + prefixes, prefixes.isEmpty());
|
KtAssert.assertTrue("File contains some unexpected directives" + prefixes, prefixes.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String probableDirective(String line) {
|
private static String probableDirective(@NotNull String line) {
|
||||||
String[] arr = line.split(" ", 2);
|
String[] arr = line.split(" ", 2);
|
||||||
String firstWord = arr[0];
|
String firstWord = arr[0];
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public final class InTextDirectivesUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> cleanDirectivesFromComments(Collection<String> prefixes) {
|
private static List<String> cleanDirectivesFromComments(@NotNull Collection<String> prefixes) {
|
||||||
List<String> resultPrefixes = Lists.newArrayList();
|
List<String> resultPrefixes = Lists.newArrayList();
|
||||||
|
|
||||||
for (String prefix : prefixes) {
|
for (String prefix : prefixes) {
|
||||||
@@ -179,7 +179,7 @@ public final class InTextDirectivesUtils {
|
|||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<String> fileNonEmptyCommentedLines(String fileText) {
|
private static List<String> fileNonEmptyCommentedLines(@NotNull String fileText) {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -204,7 +204,7 @@ public final class InTextDirectivesUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String textWithDirectives(File file) {
|
private static String textWithDirectives(@NotNull File file) {
|
||||||
try {
|
try {
|
||||||
String fileText;
|
String fileText;
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
@@ -222,7 +222,7 @@ public final class InTextDirectivesUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCompatibleTarget(TargetBackend targetBackend, File file) {
|
public static boolean isCompatibleTarget(@NotNull TargetBackend targetBackend, @NotNull File file) {
|
||||||
if (targetBackend == TargetBackend.ANY) return true;
|
if (targetBackend == TargetBackend.ANY) return true;
|
||||||
|
|
||||||
List<String> doNotTarget = findLinesWithPrefixesRemoved(textWithDirectives(file), "// DONT_TARGET_EXACT_BACKEND: ");
|
List<String> doNotTarget = findLinesWithPrefixesRemoved(textWithDirectives(file), "// DONT_TARGET_EXACT_BACKEND: ");
|
||||||
@@ -233,27 +233,27 @@ public final class InTextDirectivesUtils {
|
|||||||
return isCompatibleTargetExceptAny(targetBackend, backends);
|
return isCompatibleTargetExceptAny(targetBackend, backends);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCompatibleTargetExceptAny(TargetBackend targetBackend, List<String> backends) {
|
private static boolean isCompatibleTargetExceptAny(@NotNull TargetBackend targetBackend, @NotNull List<String> backends) {
|
||||||
if (targetBackend == TargetBackend.ANY) return false;
|
if (targetBackend == TargetBackend.ANY) return false;
|
||||||
return backends.isEmpty() || backends.contains(targetBackend.name()) || isCompatibleTargetExceptAny(targetBackend.getCompatibleWith(), backends);
|
return backends.isEmpty() || backends.contains(targetBackend.name()) || isCompatibleTargetExceptAny(targetBackend.getCompatibleWith(), backends);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isIgnoredTarget(TargetBackend targetBackend, File file, String ignoreBackendDirectivePrefix) {
|
public static boolean isIgnoredTarget(@NotNull TargetBackend targetBackend, @NotNull File file, @NotNull String ignoreBackendDirectivePrefix) {
|
||||||
List<String> ignoredBackends = findListWithPrefixes(textWithDirectives(file), ignoreBackendDirectivePrefix);
|
List<String> ignoredBackends = findListWithPrefixes(textWithDirectives(file), ignoreBackendDirectivePrefix);
|
||||||
return ignoredBackends.contains(targetBackend.name());
|
return ignoredBackends.contains(targetBackend.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isIgnoredTarget(TargetBackend targetBackend, File file) {
|
public static boolean isIgnoredTarget(@NotNull TargetBackend targetBackend, @NotNull File file) {
|
||||||
return isIgnoredTarget(targetBackend, file, IGNORE_BACKEND_DIRECTIVE_PREFIX);
|
return isIgnoredTarget(targetBackend, file, IGNORE_BACKEND_DIRECTIVE_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dontRunGeneratedCode(TargetBackend targetBackend, File file) {
|
public static boolean dontRunGeneratedCode(@NotNull TargetBackend targetBackend, @NotNull File file) {
|
||||||
List<String> backends = findListWithPrefixes(textWithDirectives(file), "// DONT_RUN_GENERATED_CODE: ");
|
List<String> backends = findListWithPrefixes(textWithDirectives(file), "// DONT_RUN_GENERATED_CODE: ");
|
||||||
return backends.contains(targetBackend.name());
|
return backends.contains(targetBackend.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether the target test is supposed to pass successfully on targetBackend
|
// Whether the target test is supposed to pass successfully on targetBackend
|
||||||
public static boolean isPassingTarget(TargetBackend targetBackend, File file) {
|
public static boolean isPassingTarget(@NotNull TargetBackend targetBackend, @NotNull File file) {
|
||||||
return isCompatibleTarget(targetBackend, file) && !isIgnoredTarget(targetBackend, file);
|
return isCompatibleTarget(targetBackend, file) && !isIgnoredTarget(targetBackend, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ interface TestParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KParameter.parseValue(text: String): Any? = when (type.classifier as? KClass<*>) {
|
private fun KParameter.parseValue(text: String): Any? = when (type.classifier as? KClass<*>) {
|
||||||
Boolean::class -> InTextDirectivesUtils.getPrefixedBoolean(text, name) ?: false
|
Boolean::class -> name?.let { InTextDirectivesUtils.getPrefixedBoolean(text, it) } ?: false
|
||||||
else -> error("Invalid test parameter $name with type $type")
|
else -> error("Invalid test parameter $name with type $type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user