Name filters filter by Name instead of String
This commit is contained in:
@@ -30,19 +30,20 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.jet.lang.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
public object TipsManager{
|
||||
|
||||
public fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||
context: BindingContext,
|
||||
nameFilter: (String) -> Boolean,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
visibilityFilter: (DeclarationDescriptor) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return getReferenceVariants(expression, context, nameFilter).filter(visibilityFilter)
|
||||
}
|
||||
|
||||
private fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||
context: BindingContext,
|
||||
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val receiverExpression = expression.getReceiverExpression()
|
||||
val parent = expression.getParent()
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
@@ -105,7 +106,7 @@ public object TipsManager{
|
||||
|
||||
public fun getPackageReferenceVariants(expression: JetSimpleNameExpression,
|
||||
context: BindingContext,
|
||||
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||
}
|
||||
|
||||
@@ -87,10 +87,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
protected abstract fun doComplete()
|
||||
|
||||
protected fun getReferenceVariants(): Collection<DeclarationDescriptor> {
|
||||
return TipsManager.getReferenceVariants(jetReference!!.expression,
|
||||
bindingContext!!,
|
||||
{ prefixMatcher.prefixMatches(it) },
|
||||
{ isVisibleDescriptor(it) })
|
||||
return TipsManager.getReferenceVariants(jetReference!!.expression, bindingContext!!, prefixMatcher.asNameFilter(), { isVisibleDescriptor(it) })
|
||||
}
|
||||
|
||||
protected fun shouldRunTopLevelCompletion(): Boolean {
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
enum class ItemPriority {
|
||||
MULTIPLE_ARGUMENTS_ITEM
|
||||
@@ -76,3 +78,5 @@ private fun qualifierName(descriptor: DeclarationDescriptor): String? = when (de
|
||||
is PackageFragmentDescriptor -> IdeDescriptorRenderers.SOURCE_CODE.renderFqName(descriptor.fqName)
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun PrefixMatcher.asNameFilter() = { (name: Name) -> !name.isSpecial() && prefixMatches(name.getIdentifier()) }
|
||||
@@ -53,7 +53,7 @@ object PackageDirectiveCompletion {
|
||||
val resolveSession = ref.expression.getLazyResolveSession()
|
||||
val bindingContext = resolveSession.resolveToElement(ref.expression)
|
||||
|
||||
val variants = TipsManager.getPackageReferenceVariants(ref.expression, bindingContext, { prefixMatcher.prefixMatches(it) })
|
||||
val variants = TipsManager.getPackageReferenceVariants(ref.expression, bindingContext, prefixMatcher.asNameFilter())
|
||||
for (variant in variants) {
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant)
|
||||
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||
|
||||
+4
-5
@@ -399,13 +399,12 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
}
|
||||
};
|
||||
|
||||
Name refName = callNameExpression.getReferencedNameAsName();
|
||||
final Name refName = callNameExpression.getReferencedNameAsName();
|
||||
|
||||
final String refNameString = refName.isSpecial() ? null : refName.asString();
|
||||
Function1<String, Boolean> nameFilter = new Function1<String, Boolean>() {
|
||||
Function1<Name, Boolean> nameFilter = new Function1<Name, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(String s) {
|
||||
return refNameString == null || s.equals(refNameString);
|
||||
public Boolean invoke(Name name) {
|
||||
return name.equals(refName);
|
||||
}
|
||||
};
|
||||
Collection<DeclarationDescriptor> variants = TipsManager.INSTANCE$.getReferenceVariants(callNameExpression, bindingContext, nameFilter, visibilityFilter);
|
||||
|
||||
Reference in New Issue
Block a user