Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ExplicitCollectionElementAccessMethod(config: Config) : Rule(
}

private fun isCallerMap(expression: KtCallExpression): Boolean {
if (expression.valueArguments.size != 2) return false
val caller = expression.getQualifiedExpressionForSelector()?.receiverExpression
val type = caller.getResolvedCall(bindingContext)?.resultingDescriptor?.returnType
if (type == null || type is ErrorType) return false // There is no caller or it can't be resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ class ExplicitCollectionElementAccessMethodSpec {
assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
}

@Test
fun `does not report map put method usage with three arguments`() {
val code = """
class MyMap : java.util.HashMap<String, Int>() {
fun put(key: String, key2: String, value: Int): Int {
return value
}
}
fun main() {
val map = MyMap()
map.put("a", "b", 1)
}
""".trimIndent()
assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
}

@Test
fun `does not report map put method with used return value`() {
val code = """
Expand Down