Skip to content

Commit

Permalink
[J2KT] Move String.inBackTicks property to Strings.kt.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 586646283
  • Loading branch information
Googler authored and copybara-github committed Nov 30, 2023
1 parent 598e6a1 commit 4b0e182
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.j2cl.transpiler.backend.kotlin

import com.google.j2cl.transpiler.ast.HasName
import com.google.j2cl.transpiler.backend.kotlin.ast.Keywords
import com.google.j2cl.transpiler.backend.kotlin.common.inBackTicks
import com.google.j2cl.transpiler.backend.kotlin.common.letIf
import com.google.j2cl.transpiler.backend.kotlin.source.Source
import com.google.j2cl.transpiler.backend.kotlin.source.Source.Companion.dotSeparated
Expand All @@ -35,9 +36,6 @@ internal val String.identifierString
}
}

internal val String.inBackTicks
get() = "`$this`"

internal fun Renderer.topLevelQualifiedNameSource(
qualifiedName: String,
optInQualifiedName: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.google.j2cl.transpiler.backend.kotlin.KotlinSource.NATIVE_KEYWORD
import com.google.j2cl.transpiler.backend.kotlin.KotlinSource.OPEN_KEYWORD
import com.google.j2cl.transpiler.backend.kotlin.ast.Keywords
import com.google.j2cl.transpiler.backend.kotlin.ast.Visibility as KtVisibility
import com.google.j2cl.transpiler.backend.kotlin.common.inBackTicks
import com.google.j2cl.transpiler.backend.kotlin.objc.comment
import com.google.j2cl.transpiler.backend.kotlin.source.Source
import com.google.j2cl.transpiler.backend.kotlin.source.Source.Companion.block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ fun String.replaceFirstChar(fn: (Char) -> Char): String =
val String.inSingleQuotes: String
get() = "'$this'"

/** Returns this string in back-ticks. */
val String.inBackTicks: String
get() = "`$this`"

/** Returns this string in double quotes. */
val String.inDoubleQuotes: String
get() = "\"$this\""
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class StringsTest {
assertThat("".titleCased).isEqualTo("")
}

@Test
fun stringInBackTicks() {
assertThat("foo".inBackTicks).isEqualTo("`foo`")
}

@Test
fun stringInSingleQuotes() {
assertThat("foo".inSingleQuotes).isEqualTo("'foo'")
Expand Down

0 comments on commit 4b0e182

Please sign in to comment.