Made ReferenceVariantsHelper class instead of object making method signatures shorter
This commit is contained in:
@@ -34,21 +34,21 @@ import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindExclude
|
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindExclude
|
||||||
import org.jetbrains.jet.plugin.util.extensionsUtils.isExtensionCallable
|
import org.jetbrains.jet.plugin.util.extensionsUtils.isExtensionCallable
|
||||||
|
|
||||||
public object ReferenceVariantsHelper {
|
public class ReferenceVariantsHelper(
|
||||||
|
private val context: BindingContext,
|
||||||
|
private val visibilityFilter: (DeclarationDescriptor) -> Boolean
|
||||||
|
) {
|
||||||
|
|
||||||
public fun getReferenceVariants(
|
public fun getReferenceVariants(
|
||||||
expression: JetSimpleNameExpression,
|
expression: JetSimpleNameExpression,
|
||||||
context: BindingContext,
|
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean,
|
nameFilter: (Name) -> Boolean
|
||||||
visibilityFilter: (DeclarationDescriptor) -> Boolean
|
|
||||||
): Collection<DeclarationDescriptor> {
|
): Collection<DeclarationDescriptor> {
|
||||||
return getReferenceVariants(expression, context, kindFilter, nameFilter).filter(visibilityFilter)
|
return getReferenceVariantsNoVisibilityFilter(expression, kindFilter, nameFilter).filter(visibilityFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReferenceVariants(
|
private fun getReferenceVariantsNoVisibilityFilter(
|
||||||
expression: JetSimpleNameExpression,
|
expression: JetSimpleNameExpression,
|
||||||
context: BindingContext,
|
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean
|
nameFilter: (Name) -> Boolean
|
||||||
): Collection<DeclarationDescriptor> {
|
): Collection<DeclarationDescriptor> {
|
||||||
@@ -85,7 +85,7 @@ public object ReferenceVariantsHelper {
|
|||||||
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptors.addCallableExtensions(resolutionScope, receiverValue, context, dataFlowInfo, isInfixCall, kindFilter, nameFilter)
|
descriptors.addCallableExtensions(resolutionScope, receiverValue, dataFlowInfo, isInfixCall, kindFilter, nameFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
return descriptors
|
return descriptors
|
||||||
@@ -112,7 +112,7 @@ public object ReferenceVariantsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getReferenceVariantsReceivers(expression: JetSimpleNameExpression, context: BindingContext): Collection<ReceiverValue> {
|
public fun getReferenceVariantsReceivers(expression: JetSimpleNameExpression): Collection<ReceiverValue> {
|
||||||
val receiverExpression = getReferenceVariantsReceiver(expression)
|
val receiverExpression = getReferenceVariantsReceiver(expression)
|
||||||
if (receiverExpression != null) {
|
if (receiverExpression != null) {
|
||||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression] ?: return listOf()
|
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression] ?: return listOf()
|
||||||
@@ -138,7 +138,6 @@ public object ReferenceVariantsHelper {
|
|||||||
private fun MutableCollection<DeclarationDescriptor>.addCallableExtensions(
|
private fun MutableCollection<DeclarationDescriptor>.addCallableExtensions(
|
||||||
resolutionScope: JetScope,
|
resolutionScope: JetScope,
|
||||||
receiver: ReceiverValue,
|
receiver: ReceiverValue,
|
||||||
context: BindingContext,
|
|
||||||
dataFlowInfo: DataFlowInfo,
|
dataFlowInfo: DataFlowInfo,
|
||||||
isInfixCall: Boolean,
|
isInfixCall: Boolean,
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
@@ -152,10 +151,11 @@ public object ReferenceVariantsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getPackageReferenceVariants(expression: JetSimpleNameExpression,
|
public fun getPackageReferenceVariants(
|
||||||
context: BindingContext,
|
expression: JetSimpleNameExpression,
|
||||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
nameFilter: (Name) -> Boolean
|
||||||
|
): Collection<DeclarationDescriptor> {
|
||||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||||
return resolutionScope.getDescriptorsFiltered(DescriptorKindFilter.PACKAGES, nameFilter)
|
return resolutionScope.getDescriptorsFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,11 +63,14 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
|||||||
|
|
||||||
protected val prefixMatcher: PrefixMatcher = this.resultSet.getPrefixMatcher()
|
protected val prefixMatcher: PrefixMatcher = this.resultSet.getPrefixMatcher()
|
||||||
|
|
||||||
|
protected val referenceVariantsHelper: ReferenceVariantsHelper?
|
||||||
|
= if (bindingContext != null) ReferenceVariantsHelper(bindingContext) { isVisibleDescriptor(it) } else null
|
||||||
|
|
||||||
protected val boldImmediateLookupElementFactory: LookupElementFactory = run {
|
protected val boldImmediateLookupElementFactory: LookupElementFactory = run {
|
||||||
if (jetReference != null) {
|
if (jetReference != null) {
|
||||||
val expression = jetReference.expression
|
val expression = jetReference.expression
|
||||||
val receivers = ReferenceVariantsHelper.getReferenceVariantsReceivers(expression, bindingContext!!)
|
val receivers = referenceVariantsHelper!!.getReferenceVariantsReceivers(expression)
|
||||||
val dataFlowInfo = bindingContext.getDataFlowInfo(expression)
|
val dataFlowInfo = bindingContext!!.getDataFlowInfo(expression)
|
||||||
val receiverTypes = receivers.flatMap {
|
val receiverTypes = receivers.flatMap {
|
||||||
SmartCastUtils.getSmartCastVariantsWithLessSpecificExcluded(it, bindingContext, dataFlowInfo)
|
SmartCastUtils.getSmartCastVariantsWithLessSpecificExcluded(it, bindingContext, dataFlowInfo)
|
||||||
}
|
}
|
||||||
@@ -111,13 +114,8 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
|||||||
|
|
||||||
protected abstract fun doComplete()
|
protected abstract fun doComplete()
|
||||||
|
|
||||||
protected fun getReferenceVariants(kindFilter: DescriptorKindFilter): Collection<DeclarationDescriptor> {
|
protected fun getReferenceVariants(kindFilter: DescriptorKindFilter): Collection<DeclarationDescriptor>
|
||||||
return ReferenceVariantsHelper.getReferenceVariants(jetReference!!.expression,
|
= referenceVariantsHelper!!.getReferenceVariants(jetReference!!.expression, kindFilter, prefixMatcher.asNameFilter())
|
||||||
bindingContext!!,
|
|
||||||
kindFilter,
|
|
||||||
prefixMatcher.asNameFilter(),
|
|
||||||
{ isVisibleDescriptor(it) })
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun shouldRunTopLevelCompletion(): Boolean
|
protected fun shouldRunTopLevelCompletion(): Boolean
|
||||||
= configuration.completeNonImportedDeclarations && isNoQualifierContext()
|
= configuration.completeNonImportedDeclarations && isNoQualifierContext()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ object PackageDirectiveCompletion {
|
|||||||
val resolveSession = ref.expression.getLazyResolveSession()
|
val resolveSession = ref.expression.getLazyResolveSession()
|
||||||
val bindingContext = resolveSession.resolveToElement(ref.expression)
|
val bindingContext = resolveSession.resolveToElement(ref.expression)
|
||||||
|
|
||||||
val variants = ReferenceVariantsHelper.getPackageReferenceVariants(ref.expression, bindingContext, prefixMatcher.asNameFilter())
|
val variants = ReferenceVariantsHelper(bindingContext, { true }).getPackageReferenceVariants(ref.expression, prefixMatcher.asNameFilter())
|
||||||
for (variant in variants) {
|
for (variant in variants) {
|
||||||
val lookupElement = LookupElementFactory.DEFAULT.createLookupElement(resolveSession, variant)
|
val lookupElement = LookupElementFactory.DEFAULT.createLookupElement(resolveSession, variant)
|
||||||
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||||
|
|||||||
+2
-2
@@ -409,8 +409,8 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
|||||||
return name.equals(refName);
|
return name.equals(refName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Collection<DeclarationDescriptor> variants = ReferenceVariantsHelper.INSTANCE$.getReferenceVariants(
|
Collection<DeclarationDescriptor> variants = new ReferenceVariantsHelper(bindingContext, visibilityFilter).getReferenceVariants(
|
||||||
callNameExpression, bindingContext, new DescriptorKindFilter(DescriptorKindFilter.FUNCTIONS_MASK | DescriptorKindFilter.CLASSIFIERS_MASK, Collections.<DescriptorKindExclude>emptyList()), nameFilter, visibilityFilter);
|
callNameExpression, new DescriptorKindFilter(DescriptorKindFilter.FUNCTIONS_MASK | DescriptorKindFilter.CLASSIFIERS_MASK, Collections.<DescriptorKindExclude>emptyList()), nameFilter);
|
||||||
|
|
||||||
Collection<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>>();
|
Collection<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>>();
|
||||||
for (DeclarationDescriptor variant : variants) {
|
for (DeclarationDescriptor variant : variants) {
|
||||||
|
|||||||
Reference in New Issue
Block a user