Use multimap for directives
This commit is contained in:
@@ -70,7 +70,6 @@ import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.parseDirectivesAndFlags;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
|
||||
|
||||
@@ -161,11 +160,10 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
List<String> kotlinConfigurationFlags = new ArrayList<>(0);
|
||||
for (TestFile testFile : testFilesWithConfigurationDirectives) {
|
||||
String content = testFile.content;
|
||||
Directives directives = usePreparsedDirectives ? testFile.directives : parseDirectivesAndFlags(content);
|
||||
|
||||
String configurationFlags = directives.get("KOTLIN_CONFIGURATION_FLAGS");
|
||||
if (configurationFlags != null) {
|
||||
kotlinConfigurationFlags.addAll(InTextDirectivesUtils.splitValues(new ArrayList<>(), configurationFlags));
|
||||
Directives directives = usePreparsedDirectives ? testFile.directives : KotlinTestUtils.parseDirectives(content);
|
||||
List<String> flags = directives.listValues("KOTLIN_CONFIGURATION_FLAGS");
|
||||
if (flags != null) {
|
||||
kotlinConfigurationFlags.addAll(flags);
|
||||
}
|
||||
|
||||
String targetString = directives.get("JVM_TARGET");
|
||||
|
||||
@@ -25,8 +25,6 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinBaseTest
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
@@ -172,7 +170,7 @@ object InlineTestUtil {
|
||||
): ArrayList<NotInlinedParameter> {
|
||||
val skipMethods =
|
||||
files.flatMap {
|
||||
it.getListDirectiveIfPresent("SKIP_INLINE_CHECK_IN") ?: emptyList()
|
||||
it.directives.listValues("SKIP_INLINE_CHECK_IN") ?: emptyList()
|
||||
}.toSet()
|
||||
|
||||
val inlinedMethods = inlineInfo.inlineMethods
|
||||
|
||||
@@ -7,18 +7,33 @@ package org.jetbrains.kotlin.test
|
||||
|
||||
class Directives {
|
||||
|
||||
private val directives = mutableMapOf<String, String?>()
|
||||
private val directives = mutableMapOf<String, MutableList<String>?>()
|
||||
|
||||
operator fun contains(key: String): Boolean {
|
||||
return key in directives
|
||||
}
|
||||
|
||||
operator fun get(key: String): String? {
|
||||
return directives[key]
|
||||
return directives[key]?.single()
|
||||
}
|
||||
|
||||
fun put(key: String, value: String?): String? {
|
||||
return directives.put(key, value)
|
||||
fun put(key: String, value: String?) {
|
||||
if (value == null) {
|
||||
directives[key] = null
|
||||
} else {
|
||||
directives.getOrPut(key, { arrayListOf() })!!.add(value)
|
||||
}
|
||||
}
|
||||
|
||||
// Such values could be defined several times, e.g
|
||||
// MY_DIRECTIVE: XXX
|
||||
// MY_DIRECTIVE: YYY
|
||||
// or
|
||||
// MY_DIRECTIVE: XXX, YYY
|
||||
fun listValues(name: String): List<String>? {
|
||||
return directives[name]?.let { values ->
|
||||
values.flatMap { InTextDirectivesUtils.splitValues(arrayListOf(), it) }
|
||||
}
|
||||
}
|
||||
|
||||
public fun asMapOfSingleValues(): Map<String, String?> {
|
||||
|
||||
@@ -91,11 +91,6 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
|
||||
return name
|
||||
}
|
||||
|
||||
fun getListDirectiveIfPresent(name: String): List<String>? {
|
||||
return directives[name]?.let {
|
||||
InTextDirectivesUtils.splitValues(arrayListOf(), it)
|
||||
} ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
open class TestModule(
|
||||
|
||||
@@ -97,8 +97,7 @@ public class KotlinTestUtils {
|
||||
|
||||
private static final List<File> filesToDelete = new ArrayList<>();
|
||||
|
||||
static final Pattern DIRECTIVE_PATTERN = Pattern.compile("^//\\s*!([\\w_]+)(:\\s*(.*)$)?", Pattern.MULTILINE);
|
||||
static final Pattern BACKEND_DIRECTIVE_PATTERN = Pattern.compile("^//\\s*(FULL_JDK|JVM_TARGET|KOTLIN_CONFIGURATION_FLAGS|LANGUAGE_VERSION|COMMON_COROUTINES_TEST|COROUTINES_PACKAGE|WITH_RUNTIME|WITH_REFLECT|NO_CHECK_LAMBDA_INLINING|SKIP_INLINE_CHECK_IN)(:[ \\t]*(.*)$)?", Pattern.MULTILINE);
|
||||
private static final Pattern DIRECTIVE_PATTERN = Pattern.compile("^//\\s*[!]?([A-Z_]+)(:[ \\t]*(.*))?$", Pattern.MULTILINE);
|
||||
|
||||
private KotlinTestUtils() {
|
||||
}
|
||||
@@ -531,27 +530,15 @@ public class KotlinTestUtils {
|
||||
|
||||
@NotNull
|
||||
public static Directives parseDirectives(String expectedText, @NotNull Directives directives) {
|
||||
return parseByRegexp(DIRECTIVE_PATTERN, expectedText, directives);
|
||||
}
|
||||
|
||||
private static Directives parseByRegexp(Pattern pattern, String expectedText, Directives directives) {
|
||||
Matcher directiveMatcher = pattern.matcher(expectedText);
|
||||
Matcher directiveMatcher = DIRECTIVE_PATTERN.matcher(expectedText);
|
||||
while (directiveMatcher.find()) {
|
||||
String name = directiveMatcher.group(1);
|
||||
String value = directiveMatcher.group(3);
|
||||
String oldValue = directives.put(name, value);
|
||||
Assert.assertNull("Directive or flag overwritten: " + name + " old value: " + oldValue + " new value: " + value, oldValue);
|
||||
directives.put(name, value);
|
||||
}
|
||||
return directives;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Directives parseDirectivesAndFlags(String expectedText) {
|
||||
Directives directiveAndFlags = parseDirectives(expectedText);
|
||||
parseByRegexp(BACKEND_DIRECTIVE_PATTERN, expectedText, directiveAndFlags);
|
||||
return directiveAndFlags;
|
||||
}
|
||||
|
||||
public static List<String> loadBeforeAfterText(String filePath) {
|
||||
String content;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isDirectiveDefined;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.parseDirectives;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.parseDirectivesAndFlags;
|
||||
|
||||
public class TestFiles {
|
||||
/**
|
||||
@@ -67,11 +66,11 @@ public class TestFiles {
|
||||
if (!matcher.find()) {
|
||||
assert testFileName != null : "testFileName should not be null if no FILE directive defined";
|
||||
// One file
|
||||
testFiles.add(factory.createFile(null, testFileName, expectedText, parseDirectivesAndFlags(expectedText)));
|
||||
testFiles.add(factory.createFile(null, testFileName, expectedText, parseDirectives(expectedText)));
|
||||
commonPrefixOrWholeFile = expectedText;
|
||||
}
|
||||
else {
|
||||
Directives allFilesOrCommonPrefixDirectives = parseDirectivesPerFile ? null : parseDirectivesAndFlags(expectedText);
|
||||
Directives allFilesOrCommonPrefixDirectives = parseDirectivesPerFile ? null : parseDirectives(expectedText);
|
||||
int processedChars = 0;
|
||||
M module = null;
|
||||
boolean firstFileProcessed = false;
|
||||
@@ -106,9 +105,10 @@ public class TestFiles {
|
||||
expectedText.substring(start,end);
|
||||
|
||||
|
||||
String expectedText1 = firstFileProcessed ? commonPrefixOrWholeFile + fileText : fileText;
|
||||
testFiles.add(factory.createFile(module, fileName, fileText,
|
||||
parseDirectivesPerFile ?
|
||||
parseDirectivesAndFlags(firstFileProcessed ? commonPrefixOrWholeFile + fileText : fileText)
|
||||
parseDirectives(expectedText1)
|
||||
: allFilesOrCommonPrefixDirectives));
|
||||
processedChars = end;
|
||||
firstFileProcessed = true;
|
||||
|
||||
Reference in New Issue
Block a user