Replace appendln with appendLine in project

This commit is contained in:
Alexander Udalov
2020-06-09 21:09:45 +02:00
parent d1c88798df
commit 6e67e1e78d
76 changed files with 405 additions and 402 deletions
@@ -33,26 +33,26 @@ fun main(args: Array<String>) {
val pkg = e.value.first().second
File(dir, fileName).bufferedWriter().use { w ->
w.appendln("package $pkg;")
w.appendln()
w.appendln()
w.appendLine("package $pkg;")
w.appendLine()
w.appendLine()
e.value.forEach { (url) ->
println("Loading $url...")
w.appendln("// Downloaded from $url")
w.appendLine("// Downloaded from $url")
val content = fetch(url)
if (content != null) {
if (url.endsWith(".idl")) {
w.appendln(content)
w.appendLine(content)
} else {
extractIDLText(content, w)
}
}
}
w.appendln()
w.appendLine()
}
}
}
@@ -69,9 +69,9 @@ private fun fetch(url: String): String? {
private fun Appendable.append(element: Element) {
val text = element.text()
appendln(text)
appendLine(text)
if (!text.trimEnd().endsWith(";")) {
appendln(";")
appendLine(";")
}
}
@@ -354,11 +354,11 @@ abstract class BaseGradleIT {
val errors = "(?m)^.*\\[ERROR] \\[\\S+] (.*)$".toRegex().findAll(output)
val errorMessage = buildString {
appendln("Gradle build failed")
appendln()
appendLine("Gradle build failed")
appendLine()
if (errors.any()) {
appendln("Possible errors:")
errors.forEach { match -> appendln(match.groupValues[1]) }
appendLine("Possible errors:")
errors.forEach { match -> appendLine(match.groupValues[1]) }
}
}
fail(errorMessage)
@@ -669,10 +669,10 @@ Finished executing task ':$taskName'|
}
val xmlString = buildString {
appendln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
appendln("<results>")
appendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
appendLine("<results>")
files.forEach {
appendln(
appendLine(
it.readText()
.trimTrailingWhitespaces()
.replace(projectDir.absolutePath, "/\$PROJECT_DIR$")
@@ -680,7 +680,7 @@ Finished executing task ':$taskName'|
.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "")
)
}
appendln("</results>")
appendLine("</results>")
}
val doc = SAXBuilder().build(xmlString.reader())
@@ -70,7 +70,7 @@ class KotlinGradleIT : BaseGradleIT() {
wd1.deleteRecursively()
if (wd1.exists()) {
val files = buildString {
wd1.walk().forEach { appendln(" " + it.relativeTo(wd1).path) }
wd1.walk().forEach { appendLine(" " + it.relativeTo(wd1).path) }
}
error("Some files in $wd1 were not removed:\n$files")
}
@@ -52,11 +52,11 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
// create Gradle Kotlin source sets for project roots:
val scriptCustomization = buildString {
appendln()
appendln("kotlin {\n sourceSets {")
appendLine()
appendLine("kotlin {\n sourceSets {")
sourceRoots.forEach { sourceRoot ->
if (sourceRoot.kotlinSourceSetName != "commonMain") {
appendln(
appendLine(
""" create("${sourceRoot.kotlinSourceSetName}") {
| dependsOn(getByName("commonMain"))
| listOf(${cliCompiler.targets.joinToString { "$it()" }}).forEach {
@@ -67,7 +67,7 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
""".trimMargin()
)
} else {
appendln(" // commonMain source set used for common module")
appendLine(" // commonMain source set used for common module")
}
}
@@ -76,11 +76,11 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
sourceRoot.dependencies.forEach { dependency ->
sourceRoots.find { it.qualifiedName == dependency }?.let { depSourceRoot ->
val depSourceSet = depSourceRoot.kotlinSourceSetName
appendln(""" getByName("${sourceRoot.kotlinSourceSetName}").dependsOn(getByName("$depSourceSet"))""")
appendLine(""" getByName("${sourceRoot.kotlinSourceSetName}").dependsOn(getByName("$depSourceSet"))""")
}
}
}
appendln(" }\n}")
appendLine(" }\n}")
}
gradleBuildScript().appendText("\n" + scriptCustomization)
@@ -39,7 +39,7 @@ fun runProcess(
if (options?.forceOutputToStdout ?: false) {
println(it)
}
sb.appendln(it)
sb.appendLine(it)
}
val exitCode = process.waitFor()
@@ -20,8 +20,8 @@ class MyProcessor() : AbstractProcessor() {
fileCreated = true
val file = processingEnv.filer.createSourceFile("Check")
file.openWriter().use {
it.appendln("// $annotations")
it.appendln("public class Check {}")
it.appendLine("// $annotations")
it.appendLine("public class Check {}")
}
return true
}
@@ -17,12 +17,12 @@ class Kotlinp(private val settings: KotlinpSettings) {
is KotlinClassMetadata.FileFacade -> FileFacadePrinter(settings).print(classFile)
is KotlinClassMetadata.SyntheticClass -> {
if (classFile.isLambda) LambdaPrinter(settings).print(classFile)
else buildString { appendln("synthetic class") }
else buildString { appendLine("synthetic class") }
}
is KotlinClassMetadata.MultiFileClassFacade -> MultiFileClassFacadePrinter().print(classFile)
is KotlinClassMetadata.MultiFileClassPart -> MultiFileClassPartPrinter(settings).print(classFile)
is KotlinClassMetadata.Unknown -> buildString { appendln("unknown file (k=${classFile.header.kind})") }
null -> buildString { appendln("unsupported file") }
is KotlinClassMetadata.Unknown -> buildString { appendLine("unknown file (k=${classFile.header.kind})") }
null -> buildString { appendLine("unsupported file") }
}
internal fun readClassFile(file: File): KotlinClassMetadata? {
@@ -36,7 +36,7 @@ class Kotlinp(private val settings: KotlinpSettings) {
internal fun renderModuleFile(metadata: KotlinModuleMetadata?): String =
if (metadata != null) ModuleFilePrinter(settings).print(metadata)
else buildString { appendln("unsupported file") }
else buildString { appendLine("unsupported file") }
internal fun readModuleFile(file: File): KotlinModuleMetadata? =
KotlinModuleMetadata.read(file.readBytes())
@@ -57,15 +57,15 @@ private fun visitFunction(settings: KotlinpSettings, sb: StringBuilder, flags: F
}
override fun visitEnd() {
sb.appendln()
sb.appendLine()
if (lambdaClassOriginName != null) {
sb.appendln(" // lambda class origin: $lambdaClassOriginName")
sb.appendLine(" // lambda class origin: $lambdaClassOriginName")
}
for (versionRequirement in versionRequirements) {
sb.appendln(" // $versionRequirement")
sb.appendLine(" // $versionRequirement")
}
if (jvmSignature != null) {
sb.appendln(" // signature: $jvmSignature")
sb.appendLine(" // signature: $jvmSignature")
}
sb.append(" ")
sb.appendFlags(flags, FUNCTION_FLAGS_MAP)
@@ -82,9 +82,9 @@ private fun visitFunction(settings: KotlinpSettings, sb: StringBuilder, flags: F
if (returnType != null) {
sb.append(": ").append(returnType)
}
sb.appendln()
sb.appendLine()
if (contract != null) {
sb.appendln(" $contract")
sb.appendLine(" $contract")
}
}
}
@@ -141,24 +141,24 @@ private fun visitProperty(
}
override fun visitEnd() {
sb.appendln()
sb.appendLine()
for (versionRequirement in versionRequirements) {
sb.appendln(" // $versionRequirement")
sb.appendLine(" // $versionRequirement")
}
if (jvmFieldSignature != null) {
sb.appendln(" // field: $jvmFieldSignature")
sb.appendLine(" // field: $jvmFieldSignature")
}
if (jvmGetterSignature != null) {
sb.appendln(" // getter: $jvmGetterSignature")
sb.appendLine(" // getter: $jvmGetterSignature")
}
if (jvmSetterSignature != null) {
sb.appendln(" // setter: $jvmSetterSignature")
sb.appendLine(" // setter: $jvmSetterSignature")
}
if (jvmSyntheticMethodForAnnotationsSignature != null) {
sb.appendln(" // synthetic method for annotations: $jvmSyntheticMethodForAnnotationsSignature")
sb.appendLine(" // synthetic method for annotations: $jvmSyntheticMethodForAnnotationsSignature")
}
if (isMovedFromInterfaceCompanion) {
sb.appendln(" // is moved from interface companion")
sb.appendLine(" // is moved from interface companion")
}
sb.append(" ")
sb.appendFlags(flags, PROPERTY_FLAGS_MAP)
@@ -177,11 +177,11 @@ private fun visitProperty(
if (Flag.Property.HAS_CONSTANT(flags)) {
sb.append(" /* = ... */")
}
sb.appendln()
sb.appendLine()
if (Flag.Property.HAS_GETTER(flags)) {
sb.append(" ")
sb.appendFlags(getterFlags, PROPERTY_ACCESSOR_FLAGS_MAP)
sb.appendln("get")
sb.appendLine("get")
}
if (Flag.Property.HAS_SETTER(flags)) {
sb.append(" ")
@@ -190,7 +190,7 @@ private fun visitProperty(
if (setterParameter != null) {
sb.append("(").append(setterParameter).append(")")
}
sb.appendln()
sb.appendLine()
}
}
}
@@ -217,18 +217,18 @@ private fun visitConstructor(sb: StringBuilder, flags: Flags): KmConstructorVisi
}
override fun visitEnd() {
sb.appendln()
sb.appendLine()
for (versionRequirement in versionRequirements) {
sb.appendln(" // $versionRequirement")
sb.appendLine(" // $versionRequirement")
}
if (jvmSignature != null) {
sb.appendln(" // signature: $jvmSignature")
sb.appendLine(" // signature: $jvmSignature")
}
sb.append(" ")
sb.appendFlags(flags, CONSTRUCTOR_FLAGS_MAP)
sb.append("constructor(")
params.joinTo(sb)
sb.appendln(")")
sb.appendLine(")")
}
}
@@ -257,12 +257,12 @@ private fun visitTypeAlias(settings: KotlinpSettings, sb: StringBuilder, flags:
printVersionRequirement { versionRequirements.add(it) }
override fun visitEnd() {
sb.appendln()
sb.appendLine()
for (versionRequirement in versionRequirements) {
sb.appendln(" // $versionRequirement")
sb.appendLine(" // $versionRequirement")
}
for (annotation in annotations) {
sb.append(" ").append("@").append(renderAnnotation(annotation)).appendln()
sb.append(" ").append("@").append(renderAnnotation(annotation)).appendLine()
}
sb.append(" ")
sb.appendFlags(flags, VISIBILITY_FLAGS_MAP)
@@ -276,7 +276,7 @@ private fun visitTypeAlias(settings: KotlinpSettings, sb: StringBuilder, flags:
if (expandedType != null) {
sb.append(" /* = ").append(expandedType).append(" */")
}
sb.appendln()
sb.appendLine()
}
}
@@ -537,12 +537,12 @@ private fun StringBuilder.appendDeclarationContainerExtensions(
moduleName: String?
) {
for ((i, sb) in localDelegatedProperties.withIndex()) {
appendln()
appendln(" // local delegated property #$i")
appendLine()
appendLine(" // local delegated property #$i")
for (line in sb.lineSequence()) {
if (line.isBlank()) continue
// Comment all uncommented lines to not make it look like these properties are declared here
appendln(
appendLine(
if (line.startsWith(" ") && !line.startsWith(" //")) line.replaceFirst(" ", " // ")
else line
)
@@ -550,8 +550,8 @@ private fun StringBuilder.appendDeclarationContainerExtensions(
}
if (settings.isVerbose && moduleName != null) {
appendln()
appendln(" // module name: $moduleName")
appendLine()
appendLine(" // module name: $moduleName")
}
}
@@ -564,9 +564,9 @@ private fun printContract(output: (String) -> Unit): KmContractVisitor =
override fun visitEnd() {
output(buildString {
appendln("contract {")
appendLine("contract {")
for (effect in effects) {
appendln(" $effect")
appendLine(" $effect")
}
append(" }")
})
@@ -705,10 +705,10 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
override fun visitEnd() {
if (anonymousObjectOriginName != null) {
result.appendln("// anonymous object origin: $anonymousObjectOriginName")
result.appendLine("// anonymous object origin: $anonymousObjectOriginName")
}
for (versionRequirement in versionRequirements) {
result.appendln("// $versionRequirement")
result.appendLine("// $versionRequirement")
}
result.appendFlags(flags!!, CLASS_FLAGS_MAP)
result.append(name)
@@ -719,9 +719,9 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
result.append(" : ")
supertypes.joinTo(result)
}
result.appendln(" {")
result.appendLine(" {")
result.append(sb)
result.appendln("}")
result.appendLine("}")
}
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
@@ -743,23 +743,23 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
visitTypeAlias(settings, sb, flags, name)
override fun visitCompanionObject(name: String) {
sb.appendln()
sb.appendln(" // companion object: $name")
sb.appendLine()
sb.appendLine(" // companion object: $name")
}
override fun visitNestedClass(name: String) {
sb.appendln()
sb.appendln(" // nested class: $name")
sb.appendLine()
sb.appendLine(" // nested class: $name")
}
override fun visitEnumEntry(name: String) {
sb.appendln()
sb.appendln(" $name,")
sb.appendLine()
sb.appendLine(" $name,")
}
override fun visitSealedSubclass(name: ClassName) {
sb.appendln()
sb.appendln(" // sealed subclass: $name")
sb.appendLine()
sb.appendLine(" // sealed subclass: $name")
}
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
@@ -799,11 +799,11 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
abstract class PackagePrinter(private val settings: KotlinpSettings) : KmPackageVisitor() {
internal val sb = StringBuilder().apply {
appendln("package {")
appendLine("package {")
}
override fun visitEnd() {
sb.appendln("}")
sb.appendLine("}")
}
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
@@ -843,14 +843,14 @@ class FileFacadePrinter(settings: KotlinpSettings) : PackagePrinter(settings), A
class LambdaPrinter(private val settings: KotlinpSettings) : KmLambdaVisitor(), AbstractPrinter<KotlinClassMetadata.SyntheticClass> {
private val sb = StringBuilder().apply {
appendln("lambda {")
appendLine("lambda {")
}
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
visitFunction(settings, sb, flags, name)
override fun visitEnd() {
sb.appendln("}")
sb.appendLine("}")
}
override fun print(klass: KotlinClassMetadata.SyntheticClass): String {
@@ -863,7 +863,7 @@ class MultiFileClassPartPrinter(
settings: KotlinpSettings
) : PackagePrinter(settings), AbstractPrinter<KotlinClassMetadata.MultiFileClassPart> {
override fun print(klass: KotlinClassMetadata.MultiFileClassPart): String {
sb.appendln(" // facade: ${klass.facadeClassName}")
sb.appendLine(" // facade: ${klass.facadeClassName}")
klass.accept(this)
return sb.toString()
}
@@ -872,11 +872,11 @@ class MultiFileClassPartPrinter(
class MultiFileClassFacadePrinter : AbstractPrinter<KotlinClassMetadata.MultiFileClassFacade> {
override fun print(klass: KotlinClassMetadata.MultiFileClassFacade): String =
buildString {
appendln("multi-file class {")
appendLine("multi-file class {")
for (part in klass.partClassNames) {
appendln(" // $part")
appendLine(" // $part")
}
appendln("}")
appendLine("}")
}
}
@@ -884,19 +884,19 @@ class ModuleFilePrinter(private val settings: KotlinpSettings) : KmModuleVisitor
private val optionalAnnotations = mutableListOf<ClassPrinter>()
private val sb = StringBuilder().apply {
appendln("module {")
appendLine("module {")
}
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
val presentableFqName = if (fqName.isEmpty()) "<root>" else fqName
sb.appendln(" package $presentableFqName {")
sb.appendLine(" package $presentableFqName {")
for (fileFacade in fileFacades) {
sb.appendln(" $fileFacade")
sb.appendLine(" $fileFacade")
}
for ((multiFileClassPart, facade) in multiFileClassParts) {
sb.appendln(" $multiFileClassPart ($facade)")
sb.appendLine(" $multiFileClassPart ($facade)")
}
sb.appendln(" }")
sb.appendLine(" }")
}
override fun visitAnnotation(annotation: KmAnnotation) {
@@ -908,14 +908,14 @@ class ModuleFilePrinter(private val settings: KotlinpSettings) : KmModuleVisitor
override fun visitEnd() {
if (optionalAnnotations.isNotEmpty()) {
sb.appendln()
sb.appendln(" // Optional annotations")
sb.appendln()
sb.appendLine()
sb.appendLine(" // Optional annotations")
sb.appendLine()
for (element in optionalAnnotations) {
sb.appendln(" " + element.result.toString().replace("\n", "\n ").trimEnd())
sb.appendLine(" " + element.result.toString().replace("\n", "\n ").trimEnd())
}
}
sb.appendln("}")
sb.appendLine("}")
}
fun print(metadata: KotlinModuleMetadata): String {
@@ -87,8 +87,8 @@ private fun compile(file: File, disposable: Disposable, tmpdir: File, forEachOut
}
private fun StringBuilder.appendFileName(file: File) {
appendln("// ${file.invariantSeparatorsPath}")
appendln("// ------------------------------------------")
appendLine("// ${file.invariantSeparatorsPath}")
appendLine("// ------------------------------------------")
}
// Reads the class file and writes it back with *Writer visitors.