Fix #KT-12015 (Kotlin Lint False Positive for Bundle.getInt()).
Android firstly checks API version against the function call receiver type, so we should do the same to be consistent. (cherry picked from commit c3d01ec) (cherry picked from commit 5c78acc)
This commit is contained in:
@@ -166,7 +166,8 @@ open class ApiDetector : Detector(), UastScanner {
|
|||||||
|
|
||||||
val parentClass = declaration.parent as? UClass ?: return
|
val parentClass = declaration.parent as? UClass ?: return
|
||||||
if (!isSdkClass(parentClass) || checkAosp(parentClass)) return
|
if (!isSdkClass(parentClass) || checkAosp(parentClass)) return
|
||||||
val parentInternalName = parentClass.internalName ?: return
|
val parentInternalName = (node as? UCallExpression)?.getReceiver()?.getExpressionType()?.resolveClass(context)?.internalName
|
||||||
|
?: parentClass.internalName ?: return
|
||||||
|
|
||||||
when (declaration) {
|
when (declaration) {
|
||||||
is UFunction -> {
|
is UFunction -> {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
|||||||
interface KotlinUElementWithType : UExpression, PsiElementBacked {
|
interface KotlinUElementWithType : UExpression, PsiElementBacked {
|
||||||
override fun getExpressionType(): UType? {
|
override fun getExpressionType(): UType? {
|
||||||
val ktElement = psi as? KtExpression ?: return null
|
val ktElement = psi as? KtExpression ?: return null
|
||||||
val ktType = ktElement.analyze(BodyResolveMode.PARTIAL)[BindingContext.EXPECTED_EXPRESSION_TYPE, ktElement] ?: return null
|
val ktType = ktElement.analyze(BodyResolveMode.PARTIAL)[BindingContext.EXPRESSION_TYPE_INFO, ktElement]?.type ?: return null
|
||||||
return KotlinConverter.convert(ktType, ktElement.project, null)
|
return KotlinConverter.convert(ktType, ktElement.project, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.Build.VERSION.SDK_INT
|
|||||||
import android.os.Build.VERSION_CODES
|
import android.os.Build.VERSION_CODES
|
||||||
import android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH
|
import android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH
|
||||||
import android.os.Build.VERSION_CODES.JELLY_BEAN
|
import android.os.Build.VERSION_CODES.JELLY_BEAN
|
||||||
|
import android.os.Bundle
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
@Suppress("SENSELESS_COMPARISON", "UNUSED_EXPRESSION", "UsePropertyAccessSyntax", "UNUSED_VARIABLE", "unused", "UNUSED_PARAMETER", "DEPRECATION")
|
@Suppress("SENSELESS_COMPARISON", "UNUSED_EXPRESSION", "UsePropertyAccessSyntax", "UNUSED_VARIABLE", "unused", "UNUSED_PARAMETER", "DEPRECATION")
|
||||||
@@ -31,6 +32,9 @@ class ApiCallTest: Activity() {
|
|||||||
fun method(chronometer: Chronometer, locator: DOMLocator) {
|
fun method(chronometer: Chronometer, locator: DOMLocator) {
|
||||||
chronometer.<error descr="Call requires API level 16 (current min is 1): `setBackground`">setBackground(null)</error>
|
chronometer.<error descr="Call requires API level 16 (current min is 1): `setBackground`">setBackground(null)</error>
|
||||||
|
|
||||||
|
// Ok
|
||||||
|
Bundle().getInt("")
|
||||||
|
|
||||||
// Virtual call
|
// Virtual call
|
||||||
<error descr="Call requires API level 11 (current min is 1): `getActionBar`">getActionBar()</error> // API 11
|
<error descr="Call requires API level 11 (current min is 1): `getActionBar`">getActionBar()</error> // API 11
|
||||||
<error descr="Call requires API level 11 (current min is 1): `getActionBar`">actionBar</error> // API 11
|
<error descr="Call requires API level 11 (current min is 1): `getActionBar`">actionBar</error> // API 11
|
||||||
|
|||||||
Reference in New Issue
Block a user