Refactored PsiElement.parents() into 2 properties
This commit is contained in:
@@ -43,10 +43,7 @@ import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
@@ -96,7 +93,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
}
|
||||
}
|
||||
|
||||
protected val bindingContext: BindingContext = resolutionFacade.analyze(position.parents().firstIsInstance<JetElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
protected val bindingContext: BindingContext = resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance<JetElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
protected val inDescriptor: DeclarationDescriptor? = expression?.let { bindingContext.get(BindingContext.RESOLUTION_SCOPE, it)?.getContainingDeclaration() }
|
||||
|
||||
private val kotlinIdentifierStartPattern: ElementPattern<Char>
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.renderName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -220,7 +221,7 @@ fun thisExpressionItems(bindingContext: BindingContext, position: JetExpression,
|
||||
|
||||
fun returnExpressionItems(bindingContext: BindingContext, position: JetElement): Collection<LookupElement> {
|
||||
val result = ArrayList<LookupElement>()
|
||||
for (parent in position.parents()) {
|
||||
for (parent in position.parentsWithSelf) {
|
||||
if (parent is JetDeclarationWithBody) {
|
||||
val returnsUnit = returnsUnit(parent, bindingContext)
|
||||
if (parent is JetFunctionLiteral) {
|
||||
@@ -279,7 +280,7 @@ fun breakOrContinueExpressionItems(position: JetElement, breakOrContinue: String
|
||||
val result = ArrayList<LookupElement>()
|
||||
|
||||
parentsLoop@
|
||||
for (parent in position.parents()) {
|
||||
for (parent in position.parentsWithSelf) {
|
||||
when (parent) {
|
||||
is JetLoopExpression -> {
|
||||
if (result.isEmpty()) {
|
||||
|
||||
+2
-2
@@ -138,13 +138,13 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
|
||||
private fun isInFunctionLiteralParameterList(tokenBefore: PsiElement?): Boolean {
|
||||
val parameterList = tokenBefore?.parents(false)?.firstOrNull { it is JetParameterList } ?: return false
|
||||
val parameterList = tokenBefore?.parents?.firstOrNull { it is JetParameterList } ?: return false
|
||||
val parent = parameterList.getParent()
|
||||
return parent is JetFunctionLiteral && parent.getValueParameterList() == parameterList
|
||||
}
|
||||
|
||||
private fun isInClassHeader(tokenBefore: PsiElement?): Boolean {
|
||||
val classOrObject = tokenBefore?.parents(false)?.firstIsInstanceOrNull<JetClassOrObject>() ?: return false
|
||||
val classOrObject = tokenBefore?.parents?.firstIsInstanceOrNull<JetClassOrObject>() ?: return false
|
||||
val name = classOrObject.getNameIdentifier() ?: return false
|
||||
val body = classOrObject.getBody() ?: return false
|
||||
val offset = tokenBefore!!.startOffset
|
||||
|
||||
Reference in New Issue
Block a user