Refactored PsiElement.parents() into 2 properties
This commit is contained in:
@@ -192,7 +192,7 @@ public fun JetElement.getContainingPseudocode(context: BindingContext): Pseudoco
|
||||
?: return null
|
||||
|
||||
val enclosingPseudocodeDeclaration = (pseudocodeDeclaration as? JetFunctionLiteral)?.let {
|
||||
it.parents(withItself = false).firstOrNull { it is JetDeclaration && it !is JetFunctionLiteral } as? JetDeclaration
|
||||
it.parents.firstOrNull { it is JetDeclaration && it !is JetFunctionLiteral } as? JetDeclaration
|
||||
} ?: pseudocodeDeclaration
|
||||
|
||||
val enclosingPseudocode = PseudocodeUtil.generatePseudocode(enclosingPseudocodeDeclaration, context)
|
||||
|
||||
@@ -26,10 +26,7 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.renderName
|
||||
import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.LinkedHashMap
|
||||
@@ -124,7 +121,7 @@ public fun <TElement : JetElement> createByPattern(pattern: String, vararg args:
|
||||
|
||||
for ((range, text) in placeholders) {
|
||||
val token = resultElement.findElementAt(range.getStartOffset())!!
|
||||
for (element in token.parents()) {
|
||||
for (element in token.parentsWithSelf) {
|
||||
val elementRange = element.getTextRange().shiftRight(-start)
|
||||
if (elementRange == range && expectedElementType.isInstance(element)) {
|
||||
val pointer = pointerManager.createSmartPsiElementPointer(element)
|
||||
|
||||
@@ -38,10 +38,11 @@ public fun PsiElement.siblings(forward: Boolean = true, withItself: Boolean = tr
|
||||
return if (withItself) sequence else sequence.drop(1)
|
||||
}
|
||||
|
||||
public fun PsiElement.parents(withItself: Boolean = true): Sequence<PsiElement> {
|
||||
val sequence = sequence(this) { if (it is PsiFile) null else it.getParent() }
|
||||
return if (withItself) sequence else sequence.drop(1)
|
||||
}
|
||||
public val PsiElement.parentsWithSelf: Sequence<PsiElement>
|
||||
get() = sequence(this) { if (it is PsiFile) null else it.getParent() }
|
||||
|
||||
public val PsiElement.parents: Sequence<PsiElement>
|
||||
get() = parentsWithSelf.drop(1)
|
||||
|
||||
public fun PsiElement.prevLeaf(skipEmptyElements: Boolean = false): PsiElement?
|
||||
= PsiTreeUtil.prevLeaf(this, skipEmptyElements)
|
||||
@@ -216,7 +217,7 @@ public fun PsiFile.elementsInRange(range: TextRange): List<PsiElement> {
|
||||
val leaf = findFirstLeafWhollyInRange(this, currentRange) ?: break
|
||||
|
||||
val element = leaf
|
||||
.parents(withItself = true)
|
||||
.parentsWithSelf
|
||||
.first {
|
||||
val parent = it.getParent()
|
||||
it is PsiFile || parent.getTextRange() !in currentRange
|
||||
|
||||
Reference in New Issue
Block a user