Skip to content

Commit

Permalink
Removes no longer needed parentheses in @composable() annotations
Browse files Browse the repository at this point in the history
-Enables the NonParenthesizedAnnotationsOnFunctionalTypes flag to disable the IDE warning
-Temporarily disables the 'paren-spacing' lint in ktlint, due to: pinterest/ktlint#737
-Turns unnecessary parentheses into a 'warning', and stops ignoring this IDE inspection in the UI project

Bug: b/155391691
Test: ./gradlew bOS, Studio
Change-Id: Ib4af53591b82a0d56ae0733ff2561196c2d49635

[androidx-to-kotlin-move] Original commit: androidx/androidx@3a54b94
  • Loading branch information
Louis Pullen-Freilich committed May 7, 2020
1 parent 39969e7 commit 9cec984
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ abstract class AbstractCodegenSignatureTest : AbstractCodegenTest() {
)
}
fun invokeComposable(composer: Composer<*>?, fn: @Composable() () -> Unit) {
fun invokeComposable(composer: Composer<*>?, fn: @Composable () -> Unit) {
if (composer == null) error("Composer was null")
val composition = compositionFor(composer) { a, b -> composer }
composition.setContent(fn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
fun testSimpleInlining(): Unit = ensureSetup {
compose("""
@Composable
inline fun foo(block: @Composable() () -> Unit) {
inline fun foo(block: @Composable () -> Unit) {
block()
}
Expand All @@ -85,7 +85,7 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
import androidx.compose.*
@Composable
fun test(children: @Composable() () -> Unit) {
fun test(children: @Composable () -> Unit) {
children()
}
"""
Expand Down Expand Up @@ -158,13 +158,13 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
"""
import androidx.compose.*
@Composable fun <T> A(value: T, block: @Composable() (T) -> Unit) {
@Composable fun <T> A(value: T, block: @Composable (T) -> Unit) {
block(value)
}
@Composable fun <T> B(
value: T,
block: @Composable() (@Composable() (T) -> Unit) -> Unit
block: @Composable (@Composable (T) -> Unit) -> Unit
) {
block({ })
}
Expand Down Expand Up @@ -246,7 +246,7 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
@Composable
inline fun PointerInputWrapper(
crossinline children: @Composable() () -> Unit
crossinline children: @Composable () -> Unit
) {
// Hide the internals of PointerInputNode
LinearLayout {
Expand Down Expand Up @@ -288,15 +288,15 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
"""
@Composable
inline fun PointerInputWrapper(
crossinline children: @Composable() () -> Unit
crossinline children: @Composable () -> Unit
) {
LinearLayout {
children()
}
}
@Composable
fun PressReleasedGestureDetector(children: @Composable() () -> Unit) {
fun PressReleasedGestureDetector(children: @Composable () -> Unit) {
PointerInputWrapper {
children()
}
Expand All @@ -310,11 +310,11 @@ class ComposeCallLoweringTests : AbstractLoweringTests() {
codegen(
"""
@Composable
inline fun Foo(crossinline children: @Composable() () -> Unit) {
inline fun Foo(crossinline children: @Composable () -> Unit) {
children()
}
@Composable fun test(children: @Composable() () -> Unit) {
@Composable fun test(children: @Composable () -> Unit) {
Foo {
println("hello world")
children()
Expand Down Expand Up @@ -410,7 +410,7 @@ fun <T> B(foo: T, bar: String) { }
codegen(
"""
@Composable fun SomeThing(children: @Composable() () -> Unit) {}
@Composable fun SomeThing(children: @Composable () -> Unit) {}
@Composable
fun Example() {
Expand Down Expand Up @@ -458,7 +458,7 @@ fun WebComponent(
codegen(
"""
fun startCompose(block: @Composable() () -> Unit) {}
fun startCompose(block: @Composable () -> Unit) {}
fun nonComposable() {
startCompose {
Expand Down Expand Up @@ -511,7 +511,7 @@ fun WebComponent(
fun testSetContent(): Unit = ensureSetup {
codegen(
"""
fun fakeCompose(block: @Composable() ()->Unit) { }
fun fakeCompose(block: @Composable ()->Unit) { }
class Test {
fun test() {
Expand All @@ -528,7 +528,7 @@ fun WebComponent(
fun testComposeWithResult(): Unit = ensureSetup {
compose(
"""
@Composable fun <T> identity(block: @Composable() ()->T): T = block()
@Composable fun <T> identity(block: @Composable ()->T): T = block()
@Composable
fun TestCall() {
Expand Down Expand Up @@ -599,7 +599,7 @@ fun WebComponent(
}
@Composable
fun FancyBox2(children: @Composable() ()->Unit) {
fun FancyBox2(children: @Composable ()->Unit) {
children()
}
""",
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fun WebComponent(
@Test
fun testInline_NonComposable_Identity(): Unit = ensureSetup {
compose("""
@Composable inline fun InlineWrapper(base: Int, children: @Composable() ()->Unit) {
@Composable inline fun InlineWrapper(base: Int, children: @Composable ()->Unit) {
children()
}
""",
Expand Down Expand Up @@ -1071,7 +1071,7 @@ fun WebComponent(
fun testInline_Composable_EmitChildren(): Unit = ensureSetup {
compose("""
@Composable
inline fun InlineWrapper(base: Int, crossinline children: @Composable() ()->Unit) {
inline fun InlineWrapper(base: Int, crossinline children: @Composable ()->Unit) {
LinearLayout(id = base + 0) {
children()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ComposeCallResolutionDiagnosticsTests : AbstractComposeDiagnosticsTest() {
val x: Any? = null
fun Activity.setViewContent(composable: @Composable() () -> Unit): Composition? {
fun Activity.setViewContent(composable: @Composable () -> Unit): Composition? {
assert(composable != x)
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ComposeCallResolverTests : AbstractCodegenTest() {
import androidx.compose.*
@Composable
fun test(children: @Composable() () -> Unit) {
fun test(children: @Composable () -> Unit) {
<call>children()
}
"""
Expand All @@ -117,13 +117,13 @@ class ComposeCallResolverTests : AbstractCodegenTest() {
"""
import androidx.compose.*
@Composable fun <T> A(value: T, block: @Composable() (T) -> Unit) {
@Composable fun <T> A(value: T, block: @Composable (T) -> Unit) {
<call>block(value)
}
@Composable fun <T> B(
value: T,
block: @Composable() (@Composable() (T) -> Unit) -> Unit
block: @Composable (@Composable (T) -> Unit) -> Unit
) {
<call>block({ })
}
Expand Down Expand Up @@ -164,7 +164,7 @@ class ComposeCallResolverTests : AbstractCodegenTest() {
@Composable fun Foo(
scope: TextSpanScope,
composable: @Composable() TextSpanScope.() -> Unit
composable: @Composable TextSpanScope.() -> Unit
) {
with(scope) {
<call>composable()
Expand Down Expand Up @@ -200,7 +200,7 @@ class ComposeCallResolverTests : AbstractCodegenTest() {
@Composable
inline fun PointerInputWrapper(
crossinline children: @Composable() () -> Unit
crossinline children: @Composable () -> Unit
) {
// Hide the internals of PointerInputNode
<emit>LinearLayout {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
@Test
fun testParameterlessChildrenLambdasReused(): Unit = checkApi(
"""
@Composable fun Foo(children: @Composable() () -> Unit) {
@Composable fun Foo(children: @Composable () -> Unit) {
}
@Composable fun Bar() {
Foo {}
Expand Down Expand Up @@ -97,7 +97,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
fun testAnonymousParamNaming(): Unit = validateBytecode(
"""
@Composable
fun Foo(children: @Composable() (a: Int, b: Int) -> Unit) {}
fun Foo(children: @Composable (a: Int, b: Int) -> Unit) {}
@Composable
fun test() {
Foo { _, _ -> }
Expand Down Expand Up @@ -224,7 +224,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
fun testDataClassHashCode(): Unit = validateBytecode(
"""
data class Foo(
val bar: @Composable() () -> Unit
val bar: @Composable () -> Unit
)
""") {
assert(!it.contains("CHECKCAST kotlin/jvm/functions/Function0"))
Expand Down Expand Up @@ -339,7 +339,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
fun testCorrectComposerPassed5(): Unit = checkComposerParam(
"""
var a: Composer<*>? = null
@Composable fun Wrap(children: @Composable() () -> Unit) {
@Composable fun Wrap(children: @Composable () -> Unit) {
children()
}
fun run() {
Expand Down Expand Up @@ -551,7 +551,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
@Test
fun testLocalLambda(): Unit = checkApi(
"""
@Composable fun Bar(children: @Composable() () -> Unit) {
@Composable fun Bar(children: @Composable () -> Unit) {
val foo = @Composable { x: Int -> print(x) }
foo(123)
children()
Expand Down Expand Up @@ -584,7 +584,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
@Test
fun testNesting(): Unit = checkApi(
"""
@Composable fun Wrap(children: @Composable() (x: Int) -> Unit) {
@Composable fun Wrap(children: @Composable (x: Int) -> Unit) {
children(123)
}
@Composable fun App(x: Int) {
Expand Down Expand Up @@ -756,7 +756,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
"""
@Composable
fun Foo() {
val c: @Composable() () -> Unit = with(123) {
val c: @Composable () -> Unit = with(123) {
val x = @Composable {}
x
}
Expand All @@ -771,7 +771,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
"""
@Composable
fun Scaffold(
topAppBar: @Composable() (() -> Unit)? = null
topAppBar: @Composable (() -> Unit)? = null
) {}
"""
) {
Expand All @@ -792,9 +792,9 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
@Test
fun testLambdaMemoization(): Unit = validateBytecode(
"""
fun subcompose(block: @Composable() () -> Unit) {}
fun subcompose(block: @Composable () -> Unit) {}
private class Foo {
var children: @Composable() (Double) -> Unit = {}
var children: @Composable (Double) -> Unit = {}
fun subcompose() {
val constraints = Math.random()
subcompose {
Expand Down Expand Up @@ -1053,7 +1053,7 @@ class ComposerParamSignatureTests : AbstractCodegenSignatureTest() {
@Test
fun testInlineCall(): Unit = checkApi(
"""
@Composable inline fun Example(children: @Composable() () -> Unit) {
@Composable inline fun Example(children: @Composable () -> Unit) {
children()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class ComposerParamTransformTests : AbstractIrTransformTest() {
@Test
fun testInlineCall(): Unit = composerParam(
"""
@Composable inline fun Example(children: @Composable() () -> Unit) {
@Composable inline fun Example(children: @Composable () -> Unit) {
children()
}
Expand Down
Loading

0 comments on commit 9cec984

Please sign in to comment.