From f8ceb039bb0e84b3473e3a74e8711b37d52a4b35 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 1 Oct 2014 22:35:05 +0400 Subject: [PATCH] Added utilities --- .../org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt index 28ae4412067..9537383794b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt @@ -35,6 +35,7 @@ import com.intellij.psi.PsiDirectory import org.jetbrains.jet.lang.psi.stubs.KotlinClassOrObjectStub import org.jetbrains.jet.lang.types.expressions.OperatorConventions import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils +import com.intellij.lang.ASTNode import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.PsiComment import org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke @@ -358,11 +359,22 @@ public fun PsiElement.siblings(forward: Boolean = true, withItself: Boolean = tr return if (withItself) stream else stream.drop(1) } +public fun ASTNode.siblings(forward: Boolean = true, withItself: Boolean = true): Stream { + val stepFun = if (forward) { (node: ASTNode) -> node.getTreeNext() } else { (e: ASTNode) -> e.getTreeNext() } + val stream = stream(this, stepFun) + return if (withItself) stream else stream.drop(1) +} + public fun PsiElement.parents(withItself: Boolean = true): Stream { val stream = stream(this) { if (it is PsiFile) null else it.getParent() } return if (withItself) stream else stream.drop(1) } +public fun ASTNode.parents(withItself: Boolean = true): Stream { + val stream = stream(this) { it.getTreeParent() } + return if (withItself) stream else stream.drop(1) +} + public fun JetExpression.getAssignmentByLHS(): JetBinaryExpression? { val parent = getParent() as? JetBinaryExpression ?: return null return if (JetPsiUtil.isAssignment(parent) && parent.getLeft() == this) parent else null