diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/ApiDetector.kt b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/ApiDetector.kt index d3d398aa8f8..3f550ebe243 100755 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/ApiDetector.kt +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/ApiDetector.kt @@ -166,7 +166,8 @@ open class ApiDetector : Detector(), UastScanner { val parentClass = declaration.parent as? UClass ?: 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) { is UFunction -> { diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt index b25cb5219ee..bc025ee1df4 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt @@ -28,7 +28,7 @@ import org.jetbrains.uast.psi.PsiElementBacked interface KotlinUElementWithType : UExpression, PsiElementBacked { override fun getExpressionType(): UType? { 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) } } diff --git a/plugins/uast-kotlin/testData/lint/apiCheck.kt b/plugins/uast-kotlin/testData/lint/apiCheck.kt index ef19427839e..6ddd00f8cde 100644 --- a/plugins/uast-kotlin/testData/lint/apiCheck.kt +++ b/plugins/uast-kotlin/testData/lint/apiCheck.kt @@ -23,6 +23,7 @@ import android.os.Build.VERSION.SDK_INT import android.os.Build.VERSION_CODES import android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH import android.os.Build.VERSION_CODES.JELLY_BEAN +import android.os.Bundle import android.widget.TextView @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) { chronometer.setBackground(null) + // Ok + Bundle().getInt("") + // Virtual call getActionBar() // API 11 actionBar // API 11