Supported object value access expressions

This commit is contained in:
Valentin Kipyatkov
2016-09-05 19:15:20 +03:00
parent e8471b4f32
commit 6d028fbcce
4 changed files with 33 additions and 8 deletions
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
@@ -58,6 +59,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
@@ -352,6 +354,13 @@ class ExpressionsOfTypeProcessor(
}
if (element.getStrictParentOfType<KtImportDirective>() != null) return true // ignore usage in import
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
val hasType = bindingContext.getType(element) != null
if (hasType) { // access to object or companion object
processSuspiciousExpression(element)
return true
}
}
is KDocName -> return true // ignore usage in doc-comment
+9 -1
View File
@@ -1,13 +1,21 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
package pack
class B(val n: Int) {
open class B(val n: Int) {
operator fun <caret>invoke(i: Int){}
}
object Obj : B(0)
fun f() = B(1)
fun test() {
f(1).invoke(2)
f(2)(2)
val v = Obj
v(1)
listOf(pack.Obj)[0](1)
}
+11 -5
View File
@@ -1,8 +1,14 @@
Checked type of f()
Checked type of pack.f()
Checked type of v
Resolved f(1)
Resolved f(2)
Resolved f(2)(2)
Searched references to B
Searched references to f() in non-Java files
Used plain search of B.invoke(i: Int) in LocalSearchScope:
CLASS:B
Resolved listOf(pack.Obj)[0](1)
Resolved v(1)
Searched references to pack.B
Searched references to pack.Obj
Searched references to pack.f() in non-Java files
Searched references to v in non-Java files
Used plain search of pack.B.invoke(i: Int) in LocalSearchScope:
CLASS:B
OBJECT_DECLARATION:Obj
@@ -1,2 +1,4 @@
Function call 11 f(1).invoke(2)
Implicit 'invoke' 12 f(2)(2)
Function call 14 f(1).invoke(2)
Implicit 'invoke' 15 f(2)(2)
Implicit 'invoke' 18 v(1)
Implicit 'invoke' 20 listOf(pack.Obj)[0](1)