No members from anonymous objects etc
This commit is contained in:
+18
-1
@@ -25,7 +25,10 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
||||||
import org.jetbrains.kotlin.idea.core.targetDescriptors
|
import org.jetbrains.kotlin.idea.core.targetDescriptors
|
||||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||||
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
@@ -94,11 +97,25 @@ class StaticMembersCompletion(
|
|||||||
indicesHelper.getJavaStaticMembers(descriptorKindFilter, nameFilter).filterTo(result) { it !in alreadyAdded } //TODO: substitution
|
indicesHelper.getJavaStaticMembers(descriptorKindFilter, nameFilter).filterTo(result) { it !in alreadyAdded } //TODO: substitution
|
||||||
}
|
}
|
||||||
|
|
||||||
indicesHelper.getObjectMembers(descriptorKindFilter, nameFilter).filterTo(result) { it !in alreadyAdded } //TODO: substitution
|
indicesHelper.getObjectMembers(descriptorKindFilter, nameFilter) filter@ { declaration, objectDeclaration ->
|
||||||
|
!declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD) && objectDeclaration.isTopLevelOrCompanion()
|
||||||
|
}.filterTo(result) {
|
||||||
|
it !in alreadyAdded //TODO: substitution
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KtObjectDeclaration.isTopLevelOrCompanion(): Boolean {
|
||||||
|
if (isCompanion()) {
|
||||||
|
val owner = parent.parent as? KtClass ?: return false
|
||||||
|
return owner.isTopLevel()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return isTopLevel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun completeFromImports(file: KtFile, collector: LookupElementsCollector) {
|
fun completeFromImports(file: KtFile, collector: LookupElementsCollector) {
|
||||||
val factory = decoratedLookupElementFactory(ItemPriority.STATIC_MEMBER_FROM_IMPORTS)
|
val factory = decoratedLookupElementFactory(ItemPriority.STATIC_MEMBER_FROM_IMPORTS)
|
||||||
membersFromImports(file)
|
membersFromImports(file)
|
||||||
|
|||||||
+26
-2
@@ -2,13 +2,13 @@ package test
|
|||||||
|
|
||||||
object KotlinObject {
|
object KotlinObject {
|
||||||
fun funFromObject() { }
|
fun funFromObject() { }
|
||||||
private fun privateFun(){}
|
private fun funPrivate(){}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinClass {
|
class KotlinClass {
|
||||||
companion object SomeName {
|
companion object SomeName {
|
||||||
fun funFromCompanionObject() { }
|
fun funFromCompanionObject() { }
|
||||||
private fun privateFun(){}
|
private fun funPrivate(){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,4 +16,28 @@ class AnotherKotlinClass {
|
|||||||
private companion object {
|
private companion object {
|
||||||
fun funFromPrivateCompanionObject() { }
|
fun funFromPrivateCompanionObject() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Nested {
|
||||||
|
fun fromNested(){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface I {
|
||||||
|
fun fromInterface()
|
||||||
|
}
|
||||||
|
|
||||||
|
object DefaultI : I {
|
||||||
|
override fun fromInterface() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val o = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
fromAnonymous()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromAnonymous(){}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,11 +1,14 @@
|
|||||||
package first
|
package first
|
||||||
|
|
||||||
fun testFun() {
|
fun testFun() {
|
||||||
funFromO<caret>
|
f<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
// INVOCATION_COUNT: 2
|
// INVOCATION_COUNT: 2
|
||||||
// EXIST: { allLookupStrings: "funFromObject", itemText: "KotlinObject.funFromObject", tailText: "() (test)", typeText: "Unit", attributes: "" }
|
// EXIST: { allLookupStrings: "funFromObject", itemText: "KotlinObject.funFromObject", tailText: "() (test)", typeText: "Unit", attributes: "" }
|
||||||
// EXIST: { allLookupStrings: "funFromCompanionObject", itemText: "KotlinClass.funFromCompanionObject", tailText: "() (test)", typeText: "Unit", attributes: "" }
|
// EXIST: { allLookupStrings: "funFromCompanionObject", itemText: "KotlinClass.funFromCompanionObject", tailText: "() (test)", typeText: "Unit", attributes: "" }
|
||||||
// ABSENT: privateFun
|
// ABSENT: funPrivate
|
||||||
// ABSENT: funFromPrivateCompanionObject
|
// ABSENT: funFromPrivateCompanionObject
|
||||||
|
// ABSENT: fromNested
|
||||||
|
// ABSENT: fromInterface
|
||||||
|
// ABSENT: fromAnonymous
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.core
|
|||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightSettings
|
import com.intellij.codeInsight.CodeInsightSettings
|
||||||
import com.intellij.openapi.progress.ProgressManager
|
import com.intellij.openapi.progress.ProgressManager
|
||||||
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.PsiModifier
|
import com.intellij.psi.PsiModifier
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.search.PsiShortNamesCache
|
import com.intellij.psi.search.PsiShortNamesCache
|
||||||
@@ -196,7 +197,11 @@ public class KotlinIndicesHelper(
|
|||||||
.filter(descriptorFilter)
|
.filter(descriptorFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getObjectMembers(descriptorKindFilter: DescriptorKindFilter, nameFilter: (String) -> Boolean): Collection<CallableDescriptor> {
|
public fun getObjectMembers(
|
||||||
|
descriptorKindFilter: DescriptorKindFilter,
|
||||||
|
nameFilter: (String) -> Boolean,
|
||||||
|
filter: (KtCallableDeclaration, KtObjectDeclaration) -> Boolean
|
||||||
|
): Collection<CallableDescriptor> {
|
||||||
val result = LinkedHashSet<CallableDescriptor>()
|
val result = LinkedHashSet<CallableDescriptor>()
|
||||||
|
|
||||||
fun addFromIndex(index: StringStubIndexExtension<out KtCallableDeclaration>) {
|
fun addFromIndex(index: StringStubIndexExtension<out KtCallableDeclaration>) {
|
||||||
@@ -205,8 +210,10 @@ public class KotlinIndicesHelper(
|
|||||||
if (!nameFilter(name)) continue
|
if (!nameFilter(name)) continue
|
||||||
|
|
||||||
for (declaration in index.get(name, project, scope)) {
|
for (declaration in index.get(name, project, scope)) {
|
||||||
if (declaration.parent.parent !is KtObjectDeclaration) continue
|
val objectDeclaration = declaration.parent.parent as? KtObjectDeclaration ?: continue
|
||||||
|
if (objectDeclaration.isObjectLiteral()) continue
|
||||||
if (!visibilityFilterMayIncludeAccessible && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) continue
|
if (!visibilityFilterMayIncludeAccessible && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) continue
|
||||||
|
if (!filter(declaration, objectDeclaration)) continue
|
||||||
declaration.resolveToDescriptorsWithHack().filterTo(result) { descriptorKindFilter.accepts(it) && descriptorFilter(it) }
|
declaration.resolveToDescriptorsWithHack().filterTo(result) { descriptorKindFilter.accepts(it) && descriptorFilter(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,6 +242,7 @@ public class KotlinIndicesHelper(
|
|||||||
for (method in shortNamesCache.getMethodsByName(name, scope)) {
|
for (method in shortNamesCache.getMethodsByName(name, scope)) {
|
||||||
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue
|
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue
|
||||||
if (!visibilityFilterMayIncludeAccessible && method.hasModifierProperty(PsiModifier.PRIVATE)) continue
|
if (!visibilityFilterMayIncludeAccessible && method.hasModifierProperty(PsiModifier.PRIVATE)) continue
|
||||||
|
if (method.containingClass?.parent !is PsiFile) continue // only top-level classes
|
||||||
val descriptor = method.getJavaMethodDescriptor(resolutionFacade) ?: continue
|
val descriptor = method.getJavaMethodDescriptor(resolutionFacade) ?: continue
|
||||||
val container = descriptor.containingDeclaration as? ClassDescriptor ?: continue
|
val container = descriptor.containingDeclaration as? ClassDescriptor ?: continue
|
||||||
if (descriptorKindFilter.accepts(descriptor) && descriptorFilter(descriptor)) {
|
if (descriptorKindFilter.accepts(descriptor) && descriptorFilter(descriptor)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user