diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt index 58cf39f8d7..464e9ef570 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.ast.test +import net.sourceforge.pmd.lang.ast.AbstractNode +import net.sourceforge.pmd.lang.ast.GenericToken import net.sourceforge.pmd.lang.ast.Node import java.util.* @@ -22,6 +24,16 @@ val Node.childIndex: Int val Node.parent: Node? get() = this.jjtGetParent() +val Node.containingFile: Node + get() = generateSequence(this) { it.parent }.last() + + +val Node.firstToken: GenericToken + get() = (this as AbstractNode).jjtGetFirstToken() + +val Node.lastToken: GenericToken + get() = (this as AbstractNode).jjtGetLastToken() + fun Node.getChild(i: Int) = jjtGetChild(i) @@ -84,4 +96,4 @@ data class TextRange(val beginPos: TextPosition, val endPos: TextPosition) { /** Result makes no sense if either of those text bounds is not ordered. */ operator fun contains(other: TextRange): Boolean = other.beginPos in this && other.endPos in this -} \ No newline at end of file +}