Added utilities
This commit is contained in:
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiDirectory
|
|||||||
import org.jetbrains.jet.lang.psi.stubs.KotlinClassOrObjectStub
|
import org.jetbrains.jet.lang.psi.stubs.KotlinClassOrObjectStub
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||||
|
import com.intellij.lang.ASTNode
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke
|
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)
|
return if (withItself) stream else stream.drop(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun ASTNode.siblings(forward: Boolean = true, withItself: Boolean = true): Stream<ASTNode> {
|
||||||
|
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<PsiElement> {
|
public fun PsiElement.parents(withItself: Boolean = true): Stream<PsiElement> {
|
||||||
val stream = stream(this) { if (it is PsiFile) null else it.getParent() }
|
val stream = stream(this) { if (it is PsiFile) null else it.getParent() }
|
||||||
return if (withItself) stream else stream.drop(1)
|
return if (withItself) stream else stream.drop(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun ASTNode.parents(withItself: Boolean = true): Stream<ASTNode> {
|
||||||
|
val stream = stream(this) { it.getTreeParent() }
|
||||||
|
return if (withItself) stream else stream.drop(1)
|
||||||
|
}
|
||||||
|
|
||||||
public fun JetExpression.getAssignmentByLHS(): JetBinaryExpression? {
|
public fun JetExpression.getAssignmentByLHS(): JetBinaryExpression? {
|
||||||
val parent = getParent() as? JetBinaryExpression ?: return null
|
val parent = getParent() as? JetBinaryExpression ?: return null
|
||||||
return if (JetPsiUtil.isAssignment(parent) && parent.getLeft() == this) parent else null
|
return if (JetPsiUtil.isAssignment(parent) && parent.getLeft() == this) parent else null
|
||||||
|
|||||||
Reference in New Issue
Block a user