diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/JavaScriptInterfaceDetector.java b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/JavaScriptInterfaceDetector.java index 1a7dc086cae..3da9ab652c8 100644 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/JavaScriptInterfaceDetector.java +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/JavaScriptInterfaceDetector.java @@ -96,7 +96,7 @@ public class JavaScriptInterfaceDetector extends Detector implements UastScanner } UExpression first = node.getValueArguments().get(0); - UElement resolved = node.resolve(context); + UElement resolved = UastUtils.resolveIfCan(first, context); if (resolved instanceof UVariable) { // We're passing in a variable to the addJavaScriptInterface method; // the variable may be of a more generic type than the actual diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt index c2120007917..159094dad53 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt @@ -16,9 +16,15 @@ package org.jetbrains.kotlin.uast +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.psi.KtObjectLiteralExpression +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.uast.UElement import org.jetbrains.uast.UObjectLiteralExpression +import org.jetbrains.uast.UType import org.jetbrains.uast.psi.PsiElementBacked class KotlinUObjectLiteralExpression( @@ -26,4 +32,10 @@ class KotlinUObjectLiteralExpression( override val parent: UElement ) : UObjectLiteralExpression, PsiElementBacked, KotlinUElementWithType { override val declaration by lz { KotlinUClass(psi.objectDeclaration, this, true) } + override fun getExpressionType(): UType? { + val obj = psi.objectDeclaration + val bindingContext = obj.analyze(BodyResolveMode.PARTIAL) + val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, obj] as? ClassDescriptor ?: return null + return KotlinConverter.convert(descriptor.getSuperClassOrAny().defaultType, psi.project, null) + } } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/lint/javaScriptInterface.kt b/plugins/uast-kotlin/testData/lint/javaScriptInterface.kt index 3b4d09c7215..8d425594a56 100644 --- a/plugins/uast-kotlin/testData/lint/javaScriptInterface.kt +++ b/plugins/uast-kotlin/testData/lint/javaScriptInterface.kt @@ -12,6 +12,10 @@ class JavaScriptTestK { webview.addJavascriptInterface(InheritsFromAnnotated(), "myobj") webview.addJavascriptInterface(NonAnnotatedObject(), "myobj") + webview.addJavascriptInterface(null, "nothing") + webview.addJavascriptInterface(object : Any() { @JavascriptInterface fun method() {} }, "nothing") + webview.addJavascriptInterface(JavascriptFace(), "nothing") + var o: Any = NonAnnotatedObject() webview.addJavascriptInterface(o, "myobj") o = InheritsFromAnnotated() @@ -55,4 +59,8 @@ class JavaScriptTestK { override fun test2() {} } +} + +class JavascriptFace { + fun method() {} } \ No newline at end of file