Supported object value access expressions
This commit is contained in:
+9
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
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.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
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.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -352,6 +354,13 @@ class ExpressionsOfTypeProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.getStrictParentOfType<KtImportDirective>() != null) return true // ignore usage in import
|
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
|
is KDocName -> return true // ignore usage in doc-comment
|
||||||
|
|||||||
+9
-1
@@ -1,13 +1,21 @@
|
|||||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
|
package pack
|
||||||
|
|
||||||
class B(val n: Int) {
|
open class B(val n: Int) {
|
||||||
operator fun <caret>invoke(i: Int){}
|
operator fun <caret>invoke(i: Int){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Obj : B(0)
|
||||||
|
|
||||||
fun f() = B(1)
|
fun f() = B(1)
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
f(1).invoke(2)
|
f(1).invoke(2)
|
||||||
f(2)(2)
|
f(2)(2)
|
||||||
|
|
||||||
|
val v = Obj
|
||||||
|
v(1)
|
||||||
|
|
||||||
|
listOf(pack.Obj)[0](1)
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -1,8 +1,14 @@
|
|||||||
Checked type of f()
|
Checked type of pack.f()
|
||||||
|
Checked type of v
|
||||||
Resolved f(1)
|
Resolved f(1)
|
||||||
Resolved f(2)
|
Resolved f(2)
|
||||||
Resolved f(2)(2)
|
Resolved f(2)(2)
|
||||||
Searched references to B
|
Resolved listOf(pack.Obj)[0](1)
|
||||||
Searched references to f() in non-Java files
|
Resolved v(1)
|
||||||
Used plain search of B.invoke(i: Int) in LocalSearchScope:
|
Searched references to pack.B
|
||||||
CLASS: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)
|
Function call 14 f(1).invoke(2)
|
||||||
Implicit 'invoke' 12 f(2)(2)
|
Implicit 'invoke' 15 f(2)(2)
|
||||||
|
Implicit 'invoke' 18 v(1)
|
||||||
|
Implicit 'invoke' 20 listOf(pack.Obj)[0](1)
|
||||||
Reference in New Issue
Block a user