Cleanup in compiler modules

This commit is contained in:
Ilya Gorbunov
2015-12-26 12:49:22 +03:00
parent 911adfd04d
commit 80916d5ed7
132 changed files with 322 additions and 322 deletions
@@ -69,22 +69,22 @@ public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
.mapNotNull { (it as? InstructionWithValue)?.outputValue }
.filter { it.element == null }
.sortedBy { it.debugName }
val allValues = elementToValues.values() + unboundValues
val allValues = elementToValues.values + unboundValues
if (allValues.isEmpty()) return
val valueDescriptions = LinkedHashMap<Pair<PseudoValue, KtElement?>, String>()
for (value in unboundValues) {
valueDescriptions[value to null] = valueDescription(null, value)
}
for ((element, value) in elementToValues.entrySet()) {
for ((element, value) in elementToValues.entries) {
valueDescriptions[value to element] = valueDescription(element, value)
}
val elementColumnWidth = elementToValues.keySet().map { elementText(it).length() }.max() ?: 1
val valueColumnWidth = allValues.map { valueDecl(it).length() }.max()!!
val valueDescColumnWidth = valueDescriptions.values().map { it.length() }.max()!!
val elementColumnWidth = elementToValues.keys.map { elementText(it).length }.max() ?: 1
val valueColumnWidth = allValues.map { valueDecl(it).length }.max()!!
val valueDescColumnWidth = valueDescriptions.values.map { it.length }.max()!!
for ((ve, description) in valueDescriptions.entrySet()) {
for ((ve, description) in valueDescriptions.entries) {
val (value, element) = ve
out
.append("%1$-${elementColumnWidth}s".format(elementText(element)))
@@ -45,7 +45,7 @@ class LazyOperationsLog(
val stringSanitizer: (String) -> String
) {
val ids = IdentityHashMap<Any, Int>()
private fun objectId(o: Any): Int = ids.getOrPut(o, { ids.size() })
private fun objectId(o: Any): Int = ids.getOrPut(o, { ids.size })
private class Record(
val lambda: Any,
@@ -62,7 +62,7 @@ class LazyOperationsLog(
public fun getText(): String {
val groupedByOwner = records.groupByTo(IdentityHashMap()) {
it.data.fieldOwner
}.map { Pair(it.getKey(), it.getValue()) }
}.map { Pair(it.key, it.value) }
return groupedByOwner.map {
val (owner, records) = it
@@ -79,7 +79,7 @@ class LazyOperationsLog(
private fun String.renumberObjects(): String {
val ids = HashMap<String, String>()
fun newId(objectId: String): String {
return ids.getOrPut(objectId, { "@" + ids.size() })
return ids.getOrPut(objectId, { "@" + ids.size })
}
val m = Pattern.compile("@\\d+").matcher(this)
@@ -181,10 +181,10 @@ class LazyOperationsLog(
}
}
o is KotlinTypeImpl -> {
StringBuilder {
StringBuilder().apply {
append(o.getConstructor())
if (!o.getArguments().isEmpty()) {
append("<${o.getArguments().size()}>")
append("<${o.getArguments().size}>")
}
}.appendQuoted()
}
@@ -109,15 +109,15 @@ public class CodeConformanceTest : TestCase() {
}
if (tests.flatMap { it.result }.isNotEmpty()) {
fail(StringBuilder {
fail(buildString {
for (test in tests) {
if (test.result.isNotEmpty()) {
append(test.message.format(test.result.size(), test.result.joinToString("\n")))
append(test.message.format(test.result.size, test.result.joinToString("\n")))
appendln()
appendln()
}
}
}.toString())
})
}
}
}
@@ -44,7 +44,7 @@ class BridgeTest : TestCase() {
}
private fun v(text: String): Fun {
assert(text.length() == 3) { "Function vertex representation should consist of 3 characters: $text" }
assert(text.length == 3) { "Function vertex representation should consist of 3 characters: $text" }
assert(text[0] in setOf('-', '+')) { "First character should be '-' for abstract functions or '+' for concrete ones: $text" }
assert(text[1] in setOf('D', 'F')) { "Second character should be 'D' for declarations or 'F' for fake overrides: $text" }
assert(text[2].isDigit()) {
@@ -95,7 +95,7 @@ class BridgeTest : TestCase() {
for (vertex in vertices) {
val directConcreteSuperFunctions = vertex.overriddenFunctions.filter { !it.isAbstract }
assert(directConcreteSuperFunctions.size() <= 1) {
assert(directConcreteSuperFunctions.size <= 1) {
"Incorrect test data: function $vertex has more than one direct concrete super-function: ${vertex.overriddenFunctions}\n" +
"This is not allowed because only classes can contain implementations (concrete functions), and having more than one " +
"concrete super-function means having more than one superclass, which is prohibited in Kotlin"
@@ -118,7 +118,7 @@ class BridgeTest : TestCase() {
assert(concreteDeclarations.isNotEmpty()) {
"Incorrect test data: concrete fake override vertex $vertex has no concrete super-declarations"
}
assert(concreteDeclarations.size() == 1) {
assert(concreteDeclarations.size == 1) {
"Incorrect test data: concrete fake override vertex $vertex has more than one concrete super-declaration: " +
"$concreteDeclarations"
}
@@ -65,7 +65,7 @@ public interface AbstractSMAPBaseTest {
val compiledData = extractSMAPFromClasses(outputFiles).groupBy {
it.sourceFile
}.map {
val smap = it.getValue().mapNotNull { it.smap?.replaceHash() }.joinToString("\n")
val smap = it.value.mapNotNull { it.smap?.replaceHash() }.joinToString("\n")
SMAPAndFile(if (smap.isNotEmpty()) smap else null, it.key)
}.toMapBy { it.sourceFile }
@@ -91,7 +91,7 @@ public abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
fun check() {
Assert.assertTrue(classSuitesByClassName.isNotEmpty())
classSuitesByClassName.values().forEach { it.check() }
classSuitesByClassName.values.forEach { it.check() }
}
}
@@ -135,7 +135,7 @@ public abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
methodExpectations.filterNotTo(uncheckedExpectations) { it.isChecked() }
fieldExpectations.filterNotTo(uncheckedExpectations) { it.isChecked() }
Assert.assertTrue(
"Unchecked expectations (${uncheckedExpectations.size()} total):\n " + uncheckedExpectations.joinToString("\n "),
"Unchecked expectations (${uncheckedExpectations.size} total):\n " + uncheckedExpectations.joinToString("\n "),
uncheckedExpectations.isEmpty())
}
@@ -185,7 +185,7 @@ public abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
val lines = Files.readLines(ktFile, Charset.forName("utf-8"))
var lineNo = 0
while (lineNo < lines.size()) {
while (lineNo < lines.size) {
val line = lines[lineNo]
val expectationMatch = expectationRegex.matchExact(line)
@@ -102,7 +102,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
}
}
}
return modules.values().toList()
return modules.values.toList()
}
private fun performChecks(resolverForProject: ResolverForProject<TestModule>, modules: List<TestModule>) {
@@ -85,7 +85,7 @@ private fun ValueArgument.getText() = this.getArgumentExpression()?.getText()?.r
private fun ArgumentMapping.getText() = when (this) {
is ArgumentMatch -> {
val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.getType())
"${status.name()} ${valueParameter.getName()} : ${parameterType} ="
"${status.name} ${valueParameter.getName()} : ${parameterType} ="
}
else -> "ARGUMENT UNMAPPED: "
}
@@ -96,7 +96,7 @@ private fun DeclarationDescriptor.getText(): String = when (this) {
}
private fun ResolvedCall<*>.renderToText(): String {
return StringBuilder {
return buildString {
appendln("Resolved call:")
appendln()
@@ -123,5 +123,5 @@ private fun ResolvedCall<*>.renderToText(): String {
appendln("$argumentMappingText $argumentText")
}
}
}.toString()
}
}
@@ -44,7 +44,7 @@ public class ConstraintSystemTestData(
init {
val functions = context.getSliceContents(BindingContext.FUNCTION)
functionFoo = findFunctionByName(functions.values(), "foo")
functionFoo = findFunctionByName(functions.values, "foo")
val function = DescriptorToSourceUtils.descriptorToDeclaration(functionFoo) as KtFunction
val fooBody = function.getBodyExpression()
scopeToResolveTypeParameters = context.get(BindingContext.LEXICAL_SCOPE, fooBody)!!
@@ -43,8 +43,8 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
public fun doTest(filePath: String, vararg substitutions: String) {
assert(substitutions.size() in 1..2) { "Captured type approximation test requires substitutions for (T) or (T, R)" }
val oneTypeVariable = substitutions.size() == 1
assert(substitutions.size in 1..2) { "Captured type approximation test requires substitutions for (T) or (T, R)" }
val oneTypeVariable = substitutions.size == 1
val declarationsText = KotlinTestUtils.doLoadFile(File(getTestDataPath() + "/declarations.kt"))
@@ -53,7 +53,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
val testFile = KtPsiFactory(getProject()).createFile(test)
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(testFile).bindingContext
val functions = bindingContext.getSliceContents(BindingContext.FUNCTION)
val functionFoo = functions.values().firstOrNull { it.getName().asString() == "foo" } ?:
val functionFoo = functions.values.firstOrNull { it.getName().asString() == "foo" } ?:
throw AssertionError("Function 'foo' is not declared")
Pair(bindingContext, functionFoo)
}
@@ -90,7 +90,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
}
val testTypes = if (oneTypeVariable) getTestTypesForOneTypeVariable() else getTestTypesForTwoTypeVariables()
val result = StringBuilder {
val result = buildString {
for ((index, testTypeWithUnsubstitutedTypeVars) in testTypes.withIndex()) {
val testType = createTestType(testTypeWithUnsubstitutedTypeVars)
val (bindingContext, functionFoo) = analyzeTestFile(testType)
@@ -115,8 +115,8 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
TypeProjectionImpl(INVARIANT, typeWithCapturedType), approximateContravariant = false)
append(" ")
for (typeParameter in testSubstitution.keySet()) {
if (testSubstitution.size() > 1) append("${typeParameter.getName()} = ")
for (typeParameter in testSubstitution.keys) {
if (testSubstitution.size > 1) append("${typeParameter.getName()} = ")
append("${testSubstitution[typeParameter]}. ")
}
appendln("lower: $lower; upper: $upper; substitution: $substitution")
@@ -125,7 +125,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
}
}
KotlinTestUtils.assertEqualsToFile(File(getTestDataPath() + "/" + filePath), result.toString())
KotlinTestUtils.assertEqualsToFile(File(getTestDataPath() + "/" + filePath), result)
}
private fun getTypePatternsForOneTypeVariable() = listOf("In<#T#>", "Out<#T#>", "Inv<#T#>", "Inv<in #T#>", "Inv<out #T#>")
@@ -142,7 +142,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
fun addRandomVariants(vararg randomVariants: String) {
variants.addAll(randomVariants.map { digits -> digits.map { digit -> digit - '0' } })
}
assert(typePatterns.size() == 5) { "Generated random variants below depend on size 5" }
assert(typePatterns.size == 5) { "Generated random variants below depend on size 5" }
//From 021 the following is generated: In<Inv<Out<T>>>, where In = typePatterns[0], Inv = typePatterns[2], Out = typePatterns[1]
addRandomVariants("021", "111", "230", "421", "322", "120", "411", "102", "401", "012")
addRandomVariants("4243", "3103", "3043", "2003", "4442", "4143", "1440", "0303", "1302", "1332")
@@ -47,7 +47,7 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
val classFile = tmpdir.walkTopDown().singleOrNull { it.path.endsWith("$classNameSuffix.class") }
?: error("Local class with suffix `$classNameSuffix` is not found in: ${tmpdir.listFiles().toList()}")
val clazz = classLoader.loadClass(classFile.relativeTo(tmpdir).substringBeforeLast(".class").replace('/', '.').replace('\\', '.'))
val clazz = classLoader.loadClass(classFile.toRelativeString(tmpdir).substringBeforeLast(".class").replace('/', '.').replace('\\', '.'))
assertHasAnnotationData(clazz)
val environment = KotlinCoreEnvironment.createForTests(
@@ -80,7 +80,7 @@ public class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
private fun deserialize(metaFile: File): ModuleDescriptorImpl {
val module = KotlinTestUtils.createEmptyModule("<$MODULE_NAME>", JsPlatform)
val metadata = KotlinJavascriptMetadataUtils.loadMetadata(metaFile)
assert(metadata.size() == 1)
assert(metadata.size == 1)
val provider = KotlinJavascriptSerializationUtil.createPackageFragmentProvider(module, metadata[0].body, LockBasedStorageManager())
.sure { "No package fragment provider was created" }
@@ -48,7 +48,7 @@ public fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg ex
}
public fun PsiFile.findElementByCommentPrefix(commentText: String): PsiElement? =
findElementsByCommentPrefix(commentText).keySet().singleOrNull()
findElementsByCommentPrefix(commentText).keys.singleOrNull()
public fun PsiFile.findElementsByCommentPrefix(prefix: String): Map<PsiElement, String> {
var result = SmartFMap.emptyMap<PsiElement, String>()
@@ -63,11 +63,11 @@ public fun PsiFile.findElementsByCommentPrefix(prefix: String): Map<PsiElement,
is PsiMember -> parent
else -> PsiTreeUtil.skipSiblingsForward(
comment,
javaClass<PsiWhiteSpace>(), javaClass<PsiComment>(), javaClass<KtPackageDirective>()
PsiWhiteSpace::class.java, PsiComment::class.java, KtPackageDirective::class.java
)
} as? PsiElement ?: return
result = result.plus(elementToAdd, commentText.substring(prefix.length()).trim())
result = result.plus(elementToAdd, commentText.substring(prefix.length).trim())
}
}
}
@@ -44,14 +44,14 @@ abstract class AbstractTypeBindingTest : KotlinLiteFixture() {
assertEqualsToFile(
testFile,
StringBuilder {
buildString {
append(removeLastComment(testKtFile))
append("/*\n")
MyPrinter(this).print(typeBinding)
append("*/")
}.toString()
}
)
}