Hiding getters and setters from completion
This commit is contained in:
+26
-7
@@ -18,11 +18,11 @@
|
|||||||
package org.jetbrains.kotlin.idea.codeInsight
|
package org.jetbrains.kotlin.idea.codeInsight
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.idea.util.CallType
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.idea.util.ShadowedDeclarationsFilter
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstance
|
||||||
import org.jetbrains.kotlin.idea.util.*
|
import org.jetbrains.kotlin.idea.util.substituteExtensionIfCallable
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -37,9 +37,11 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
|
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class ReferenceVariantsHelper(
|
public class ReferenceVariantsHelper(
|
||||||
@@ -61,11 +63,28 @@ public class ReferenceVariantsHelper(
|
|||||||
expression: JetSimpleNameExpression,
|
expression: JetSimpleNameExpression,
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean,
|
nameFilter: (Name) -> Boolean,
|
||||||
|
filterOutJavaGettersAndSetters: Boolean = false,
|
||||||
useRuntimeReceiverType: Boolean = false
|
useRuntimeReceiverType: Boolean = false
|
||||||
): Collection<DeclarationDescriptor> {
|
): Collection<DeclarationDescriptor> {
|
||||||
val variants = getReferenceVariantsNoVisibilityFilter(expression, kindFilter, useRuntimeReceiverType, nameFilter)
|
var variants: Collection<DeclarationDescriptor>
|
||||||
|
= getReferenceVariantsNoVisibilityFilter(expression, kindFilter, useRuntimeReceiverType, nameFilter)
|
||||||
.filter(visibilityFilter)
|
.filter(visibilityFilter)
|
||||||
return ShadowedDeclarationsFilter(context, moduleDescriptor, project).filter(variants, expression)
|
|
||||||
|
variants = ShadowedDeclarationsFilter(context, moduleDescriptor, project).filter(variants, expression)
|
||||||
|
|
||||||
|
if (filterOutJavaGettersAndSetters) {
|
||||||
|
val accessorMethodsToRemove = HashSet<FunctionDescriptor>()
|
||||||
|
for (variant in variants) {
|
||||||
|
if (variant is SyntheticExtensionPropertyDescriptor) {
|
||||||
|
accessorMethodsToRemove.add(variant.getMethod)
|
||||||
|
accessorMethodsToRemove.addIfNotNull(variant.setMethod)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variants = variants.filter { it !in accessorMethodsToRemove }
|
||||||
|
}
|
||||||
|
|
||||||
|
return variants
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReferenceVariantsNoVisibilityFilter(
|
private fun getReferenceVariantsNoVisibilityFilter(
|
||||||
|
|||||||
@@ -61,11 +61,15 @@ import kotlin.properties.Delegates
|
|||||||
|
|
||||||
class CompletionSessionConfiguration(
|
class CompletionSessionConfiguration(
|
||||||
val completeNonImportedDeclarations: Boolean,
|
val completeNonImportedDeclarations: Boolean,
|
||||||
val completeNonAccessibleDeclarations: Boolean)
|
val completeNonAccessibleDeclarations: Boolean,
|
||||||
|
val filterOutJavaGettersAndSetters: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
fun CompletionSessionConfiguration(parameters: CompletionParameters) = CompletionSessionConfiguration(
|
fun CompletionSessionConfiguration(parameters: CompletionParameters) = CompletionSessionConfiguration(
|
||||||
completeNonImportedDeclarations = parameters.getInvocationCount() >= 2,
|
completeNonImportedDeclarations = parameters.getInvocationCount() >= 2,
|
||||||
completeNonAccessibleDeclarations = parameters.getInvocationCount() >= 2)
|
completeNonAccessibleDeclarations = parameters.getInvocationCount() >= 2,
|
||||||
|
filterOutJavaGettersAndSetters = parameters.getInvocationCount() < 2
|
||||||
|
)
|
||||||
|
|
||||||
abstract class CompletionSession(protected val configuration: CompletionSessionConfiguration,
|
abstract class CompletionSession(protected val configuration: CompletionSessionConfiguration,
|
||||||
protected val parameters: CompletionParameters,
|
protected val parameters: CompletionParameters,
|
||||||
@@ -208,7 +212,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
protected val referenceVariants: Collection<DeclarationDescriptor> by Delegates.lazy {
|
protected val referenceVariants: Collection<DeclarationDescriptor> by Delegates.lazy {
|
||||||
if (descriptorKindFilter != null) {
|
if (descriptorKindFilter != null) {
|
||||||
val expression = reference!!.expression
|
val expression = reference!!.expression
|
||||||
referenceVariantsHelper.getReferenceVariants(expression, descriptorKindFilter!!, prefixMatcher.asNameFilter())
|
referenceVariantsHelper.getReferenceVariants(expression, descriptorKindFilter!!, prefixMatcher.asNameFilter(), filterOutJavaGettersAndSetters = configuration.filterOutJavaGettersAndSetters)
|
||||||
.excludeNonInitializedVariable(expression)
|
.excludeNonInitializedVariable(expression)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+2
-1
@@ -249,7 +249,8 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
if (!somethingAdded && parameters.getInvocationCount() < 2) {
|
if (!somethingAdded && parameters.getInvocationCount() < 2) {
|
||||||
// Rerun completion if nothing was found
|
// Rerun completion if nothing was found
|
||||||
val newConfiguration = CompletionSessionConfiguration(completeNonImportedDeclarations = true,
|
val newConfiguration = CompletionSessionConfiguration(completeNonImportedDeclarations = true,
|
||||||
completeNonAccessibleDeclarations = false)
|
completeNonAccessibleDeclarations = false,
|
||||||
|
filterOutJavaGettersAndSetters = false)
|
||||||
BasicCompletionSession(newConfiguration, parameters, result).complete()
|
BasicCompletionSession(newConfiguration, parameters, result).complete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun File.foo(absolutePath: String) {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST_JAVA_ONLY: getAbsolutePath
|
||||||
|
// ABSENT: { itemText: "absolutePath", tailText: " for File" }
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(thread: Thread) {
|
||||||
|
thread.get<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST_JAVA_ONLY: getPriority
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
fun foo(thread: Thread) {
|
||||||
|
thread.<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// INVOCATION_COUNT: 2
|
||||||
|
// EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " for Thread", typeText: "Int" }
|
||||||
|
// EXIST_JAVA_ONLY: getPriority
|
||||||
|
// EXIST_JAVA_ONLY: setPriority
|
||||||
@@ -5,3 +5,4 @@ fun foo(file: File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" }
|
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" }
|
||||||
|
// ABSENT: getAbsolutePath
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
import java.io.File
|
fun Thread.foo() {
|
||||||
|
|
||||||
fun File.foo() {
|
|
||||||
<caret>
|
<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" }
|
// EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " for Thread", typeText: "Int" }
|
||||||
|
// ABSENT: getPriority
|
||||||
|
// ABSENT: setPriority
|
||||||
|
|||||||
+1
@@ -5,3 +5,4 @@ fun foo(file: File?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" }
|
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" }
|
||||||
|
// ABSENT: getAbsolutePath
|
||||||
|
|||||||
+18
@@ -1107,6 +1107,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DoNotHideGetterWhenExtensionCannotBeUsed.kt")
|
||||||
|
public void testDoNotHideGetterWhenExtensionCannotBeUsed() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/DoNotHideGetterWhenExtensionCannotBeUsed.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtensionInExtendedClass.kt")
|
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||||
public void testExtensionInExtendedClass() throws Exception {
|
public void testExtensionInExtendedClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||||
@@ -1209,6 +1215,18 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ShowGetMethodWhenNothingElseMatch.kt")
|
||||||
|
public void testShowGetMethodWhenNothingElseMatch() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ShowGetMethodWhenNothingElseMatch.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ShowGetSetOnSecondCompletion.kt")
|
||||||
|
public void testShowGetSetOnSecondCompletion() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ShowGetSetOnSecondCompletion.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("SyntheticExtensions1.kt")
|
@TestMetadata("SyntheticExtensions1.kt")
|
||||||
public void testSyntheticExtensions1() throws Exception {
|
public void testSyntheticExtensions1() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/SyntheticExtensions1.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/SyntheticExtensions1.kt");
|
||||||
|
|||||||
+18
@@ -1107,6 +1107,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DoNotHideGetterWhenExtensionCannotBeUsed.kt")
|
||||||
|
public void testDoNotHideGetterWhenExtensionCannotBeUsed() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/DoNotHideGetterWhenExtensionCannotBeUsed.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtensionInExtendedClass.kt")
|
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||||
public void testExtensionInExtendedClass() throws Exception {
|
public void testExtensionInExtendedClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||||
@@ -1209,6 +1215,18 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ShowGetMethodWhenNothingElseMatch.kt")
|
||||||
|
public void testShowGetMethodWhenNothingElseMatch() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ShowGetMethodWhenNothingElseMatch.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ShowGetSetOnSecondCompletion.kt")
|
||||||
|
public void testShowGetSetOnSecondCompletion() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ShowGetSetOnSecondCompletion.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("SyntheticExtensions1.kt")
|
@TestMetadata("SyntheticExtensions1.kt")
|
||||||
public void testSyntheticExtensions1() throws Exception {
|
public void testSyntheticExtensions1() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/SyntheticExtensions1.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/SyntheticExtensions1.kt");
|
||||||
|
|||||||
+1
-1
@@ -414,7 +414,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
|||||||
};
|
};
|
||||||
Collection<DeclarationDescriptor> variants = new ReferenceVariantsHelper(bindingContext, moduleDescriptor, file.getProject(), visibilityFilter).getReferenceVariants(
|
Collection<DeclarationDescriptor> variants = new ReferenceVariantsHelper(bindingContext, moduleDescriptor, file.getProject(), visibilityFilter).getReferenceVariants(
|
||||||
callNameExpression, new DescriptorKindFilter(DescriptorKindFilter.FUNCTIONS_MASK | DescriptorKindFilter.CLASSIFIERS_MASK,
|
callNameExpression, new DescriptorKindFilter(DescriptorKindFilter.FUNCTIONS_MASK | DescriptorKindFilter.CLASSIFIERS_MASK,
|
||||||
Collections.<DescriptorKindExclude>emptyList()), nameFilter, false);
|
Collections.<DescriptorKindExclude>emptyList()), nameFilter, false, false);
|
||||||
|
|
||||||
Collection<Pair<? extends DeclarationDescriptor, ResolutionFacade>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolutionFacade>>();
|
Collection<Pair<? extends DeclarationDescriptor, ResolutionFacade>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolutionFacade>>();
|
||||||
for (DeclarationDescriptor variant : variants) {
|
for (DeclarationDescriptor variant : variants) {
|
||||||
|
|||||||
Reference in New Issue
Block a user