Lint: Fix KT-11924 (False positive on beginTransaction() should be completed with a commit() call)

This commit is contained in:
Yan Zhulanow
2016-04-15 19:44:29 +03:00
parent 35fca9171c
commit 574aa5debe
12 changed files with 171 additions and 13 deletions
@@ -245,4 +245,35 @@ fun UExpression.endsWithQualified(fqName: String): Boolean {
if (passedIdentifier != identifiers[i]) return false
}
return true
}
fun UExpression.findTopMostQualifiedExpression(): UQualifiedExpression? {
val parent = this.parent
return when (parent) {
is UQualifiedExpression -> parent.findTopMostQualifiedExpression()
else -> if (this is UQualifiedExpression) this else null
}
}
fun UExpression.getQualifiedChains(): List<UExpression> {
fun collect(expr: UQualifiedExpression, chains: MutableList<UExpression>) {
val receiver = expr.receiver
if (receiver is UQualifiedExpression) {
collect(receiver, chains)
} else {
chains += receiver
}
val selector = expr.selector
if (selector is UQualifiedExpression) {
collect(selector, chains)
} else {
chains += selector
}
}
val qualifiedExpression = this.findTopMostQualifiedExpression() ?: return emptyList()
val chains = mutableListOf<UExpression>()
collect(qualifiedExpression, chains)
return chains
}
@@ -15,6 +15,7 @@
*/
package org.jetbrains.uast
import org.jetbrains.uast.kinds.UastVariableInitialierKind
import org.jetbrains.uast.visitor.UastVisitor
interface UVariable : UDeclaration, UModifierOwner, UVisibilityOwner, UAnnotated {
@@ -23,6 +24,12 @@ interface UVariable : UDeclaration, UModifierOwner, UVisibilityOwner, UAnnotated
*/
val initializer: UExpression?
/**
* Return the variable initializer kind (simple initializer, property delegation, etc.).
*/
val initializerKind: UastVariableInitialierKind
/**
* Return the variable kind.
*/
@@ -75,6 +82,7 @@ interface UVariable : UDeclaration, UModifierOwner, UVisibilityOwner, UAnnotated
object UVariableNotResolved : UVariable {
override val initializer = null
override val initializerKind = UastVariableInitialierKind.NO_INITIALIZER
override val kind = UastVariableKind(ERROR_NAME)
override val type = UastErrorType
override val nameElement = null
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.uast.kinds
open class UastVariableInitialierKind(val name: String) {
class Simple(name: String) : UastVariableInitialierKind(name)
class Delegation(name: String) : UastVariableInitialierKind(name)
companion object {
@JvmField
val SIMPLE = Simple("simple")
@JvmField
val DELEGATION = Simple("delegation")
@JvmField
val NO_INITIALIZER = UastVariableInitialierKind("no_initializer")
}
}
@@ -19,15 +19,19 @@ package org.jetbrains.uast
* Kinds of [UVariable].
*/
open class UastVariableKind(val name: String) {
class Member(name: String) : UastVariableKind(name)
class LocalVariable(name: String) : UastVariableKind(name)
class ValueParameter(name: String) : UastVariableKind(name)
companion object {
@JvmField
val LOCAL_VARIABLE = UastVariableKind("local")
val LOCAL_VARIABLE = LocalVariable("local")
@JvmField
val MEMBER = UastVariableKind("member")
val MEMBER = Member("member")
@JvmField
val VALUE_PARAMETER = UastVariableKind("parameter")
val VALUE_PARAMETER = ValueParameter("parameter")
}
override fun toString(): String{