Delegate text coordinates to the tokens

This commit is contained in:
Andreas Dangel
2019-05-01 17:29:32 +02:00
parent 5ec4324fbc
commit 9a93a6c5e9

View File

@ -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
}
}