Group all call chain-related tests in a single directory
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
val x = foo
|
||||
.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
val y = xyzzy(foo.bar().baz().quux())
|
||||
|
||||
fun foo() {
|
||||
foo
|
||||
.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
z = foo
|
||||
.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
z += foo
|
||||
.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
return foo
|
||||
.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
}
|
||||
|
||||
// SET_INT: METHOD_CALL_CHAIN_WRAP = 2
|
||||
// SET_FALSE: WRAP_FIRST_METHOD_IN_CALL_CHAIN
|
||||
@@ -0,0 +1,26 @@
|
||||
val x = foo.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
val y = xyzzy(foo.bar().baz().quux())
|
||||
|
||||
fun foo() {
|
||||
foo.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
z = foo.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
z += foo.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
|
||||
return foo.bar()
|
||||
.baz()
|
||||
.quux()
|
||||
}
|
||||
|
||||
// SET_INT: METHOD_CALL_CHAIN_WRAP = 2
|
||||
// SET_FALSE: WRAP_FIRST_METHOD_IN_CALL_CHAIN
|
||||
@@ -0,0 +1,16 @@
|
||||
val x = foo.bar().baz().quux()
|
||||
|
||||
val y = xyzzy(foo.bar().baz().quux())
|
||||
|
||||
fun foo() {
|
||||
foo.bar().baz().quux()
|
||||
|
||||
z = foo.bar().baz().quux()
|
||||
|
||||
z += foo.bar().baz().quux()
|
||||
|
||||
return foo.bar().baz().quux()
|
||||
}
|
||||
|
||||
// SET_INT: METHOD_CALL_CHAIN_WRAP = 2
|
||||
// SET_FALSE: WRAP_FIRST_METHOD_IN_CALL_CHAIN
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
MyFunc1()
|
||||
.MyFunc2()
|
||||
.MyFunc3()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
MyFunc1()
|
||||
.MyFunc2()
|
||||
.MyFunc3()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Some {
|
||||
fun some(): Some? = this
|
||||
}
|
||||
|
||||
public fun bar(): String? =
|
||||
Some()
|
||||
?.some()
|
||||
?.some()
|
||||
?.some()!!
|
||||
.toString()
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,12 @@
|
||||
class Some {
|
||||
fun some(): Some? = this
|
||||
}
|
||||
|
||||
public fun bar(): String? =
|
||||
Some()
|
||||
?.some()
|
||||
?.some()
|
||||
?.some()!!
|
||||
.toString()
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,12 @@
|
||||
class Some {
|
||||
fun some(): Some? = this
|
||||
}
|
||||
|
||||
public fun bar(): String? =
|
||||
Some()
|
||||
?.some()
|
||||
?.some()
|
||||
?.some()!!
|
||||
.toString()
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
val x = "abc"
|
||||
.length
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,4 @@
|
||||
val x = "abc"
|
||||
.length
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,4 @@
|
||||
val x = "abc"
|
||||
.length
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun test() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map({
|
||||
it * 2
|
||||
})
|
||||
.filter({
|
||||
it > 4
|
||||
})
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
val abc = ArrayList<Int>().map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
val abc = ArrayList<Int>().mapTo(
|
||||
LinkedHashSet()
|
||||
) {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun testWithComments() {
|
||||
val abc = ArrayList<Int>()
|
||||
// .map {
|
||||
// it * 2
|
||||
// }
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun test() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map({
|
||||
it * 2
|
||||
})
|
||||
.filter({
|
||||
it > 4
|
||||
})
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
val abc = ArrayList<Int>().map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
val abc = ArrayList<Int>().mapTo(
|
||||
LinkedHashSet()
|
||||
) {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun testWithComments() {
|
||||
val abc = ArrayList<Int>()
|
||||
// .map {
|
||||
// it * 2
|
||||
// }
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun test() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map({
|
||||
it * 2
|
||||
})
|
||||
.filter({
|
||||
it > 4
|
||||
})
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
val abc = ArrayList<Int>()
|
||||
.map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
val abc = ArrayList<Int>().map {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
val abc = ArrayList<Int>().mapTo(
|
||||
LinkedHashSet()
|
||||
) {
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
|
||||
fun testWithComments() {
|
||||
val abc = ArrayList<Int>()
|
||||
// .map {
|
||||
// it * 2
|
||||
// }
|
||||
.filter {
|
||||
it > 4
|
||||
}
|
||||
}
|
||||
|
||||
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
Single.just(Object())
|
||||
.map {
|
||||
it
|
||||
}.map {
|
||||
it // The code unexpectedly shifts to the left
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
Single.just(Object())
|
||||
.map {
|
||||
it
|
||||
}.map {
|
||||
it // The code unexpectedly shifts to the left
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
val ret = (DB.Article innerJoin DB.Project).slice(DB.Article.project, DB.Article.project.count()).select {
|
||||
filterBlogs(params)
|
||||
}.groupBy(DB.Article.project).map {
|
||||
val count = it[DB.Article.project.count()]
|
||||
val project = it[DB.Article.team.count()]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
val ret = (DB.Article innerJoin DB.Project).
|
||||
slice(DB.Article.project, DB.Article.project.count()).
|
||||
select {
|
||||
filterBlogs(params)
|
||||
}.groupBy(DB.Article.project).map {
|
||||
val count = it[DB.Article.project.count()]
|
||||
val project = it[DB.Article.team.count()]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package templates
|
||||
|
||||
import kotlin.coroutines.experimental.buildSequence
|
||||
import kotlin.reflect.KTypeProjection
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.full.isSubtypeOf
|
||||
|
||||
|
||||
typealias TemplateGroup = () -> Sequence<MemberTemplate>
|
||||
|
||||
fun templateGroupOf(vararg templates: MemberTemplate): TemplateGroup = { templates.asSequence() }
|
||||
|
||||
abstract class TemplateGroupBase : TemplateGroup {
|
||||
|
||||
override fun invoke(): Sequence<MemberTemplate> = buildSequence {
|
||||
with(this@TemplateGroupBase) {
|
||||
this::class.members.filter { it.name.startsWith("f_") }.forEach {
|
||||
require(it.parameters.size == 1) { "Member $it violates naming convention" }
|
||||
when {
|
||||
it.returnType.isSubtypeOf(typeMemberTemplate) ->
|
||||
yield(it.call(this) as MemberTemplate)
|
||||
it.returnType.isSubtypeOf(typeIterableOfMemberTemplates) ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
yieldAll(it.call(this) as Iterable<MemberTemplate>)
|
||||
else ->
|
||||
error("Member $it violates naming convention")
|
||||
}
|
||||
}
|
||||
}
|
||||
}.run {
|
||||
if (defaultActions.isEmpty()) this else onEach { t -> defaultActions.forEach(t::builder) }
|
||||
}
|
||||
|
||||
private val defaultActions = mutableListOf<MemberBuildAction>()
|
||||
|
||||
fun defaultBuilder(builderAction: MemberBuildAction) {
|
||||
defaultActions += builderAction
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val typeMemberTemplate = MemberTemplate::class.createType()
|
||||
private val typeIterableOfMemberTemplates = Iterable::class.createType(arguments = listOf(KTypeProjection.invariant(typeMemberTemplate)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
cacheFile.objectInputStream().use {
|
||||
// one indent here
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package templates
|
||||
|
||||
import kotlin.coroutines.experimental.buildSequence
|
||||
import kotlin.reflect.KTypeProjection
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.full.isSubtypeOf
|
||||
|
||||
|
||||
typealias TemplateGroup = () -> Sequence<MemberTemplate>
|
||||
|
||||
fun templateGroupOf(vararg templates: MemberTemplate): TemplateGroup = { templates.asSequence() }
|
||||
|
||||
abstract class TemplateGroupBase : TemplateGroup {
|
||||
|
||||
override fun invoke(): Sequence<MemberTemplate> = buildSequence {
|
||||
with(this@TemplateGroupBase) {
|
||||
this::class.members.filter { it.name.startsWith("f_") }.forEach {
|
||||
require(it.parameters.size == 1) { "Member $it violates naming convention" }
|
||||
when {
|
||||
it.returnType.isSubtypeOf(typeMemberTemplate) ->
|
||||
yield(it.call(this) as MemberTemplate)
|
||||
it.returnType.isSubtypeOf(typeIterableOfMemberTemplates) ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
yieldAll(it.call(this) as Iterable<MemberTemplate>)
|
||||
else ->
|
||||
error("Member $it violates naming convention")
|
||||
}
|
||||
}
|
||||
}
|
||||
}.run {
|
||||
if (defaultActions.isEmpty()) this else onEach { t -> defaultActions.forEach(t::builder) }
|
||||
}
|
||||
|
||||
private val defaultActions = mutableListOf<MemberBuildAction>()
|
||||
|
||||
fun defaultBuilder(builderAction: MemberBuildAction) {
|
||||
defaultActions += builderAction
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val typeMemberTemplate = MemberTemplate::class.createType()
|
||||
private val typeIterableOfMemberTemplates = Iterable::class.createType(arguments = listOf(KTypeProjection.invariant(typeMemberTemplate)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
cacheFile.objectInputStream().use {
|
||||
// one indent here
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
private fun String.foo(): List<String> = emptyList()
|
||||
|
||||
fun test(s: String) {
|
||||
s.foo().flatMap { m ->
|
||||
m.foo().map { e ->
|
||||
e to m
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
private fun String.foo(): List<String> = emptyList()
|
||||
|
||||
fun test(s: String) {
|
||||
s.foo().flatMap { m ->
|
||||
m.foo().map { e ->
|
||||
e to m
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun foo() {
|
||||
async {
|
||||
// ...
|
||||
}.logFailures().invokeOnCompletion {
|
||||
if (it != null) showErrorAndContinue()
|
||||
finish()
|
||||
}
|
||||
|
||||
FirebaseAuth.getInstance().addAuthStateListener(object : FirebaseAuth.AuthStateListener {
|
||||
override fun onAuthStateChanged(auth: FirebaseAuth) {
|
||||
// ...
|
||||
}
|
||||
})
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun foo() {
|
||||
async {
|
||||
// ...
|
||||
}.logFailures().invokeOnCompletion {
|
||||
if (it != null) showErrorAndContinue()
|
||||
finish()
|
||||
}
|
||||
|
||||
FirebaseAuth.getInstance().addAuthStateListener(object : FirebaseAuth.AuthStateListener {
|
||||
override fun onAuthStateChanged(auth: FirebaseAuth) {
|
||||
// ...
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user