Moving more PSI modification methods to psiModificationUtils.kt

This commit is contained in:
Valentin Kipyatkov
2015-05-28 23:18:00 +03:00
parent 006c02b569
commit cbc0a60006
4 changed files with 41 additions and 40 deletions
@@ -141,44 +141,6 @@ public fun JetDeclaration.isExtensionDeclaration(): Boolean {
public fun JetClassOrObject.isObjectLiteral(): Boolean = this is JetObjectDeclaration && isObjectLiteral()
//TODO: git rid of this method
public fun PsiElement.deleteElementAndCleanParent() {
val parent = getParent()
deleteElementWithDelimiters(this)
deleteChildlessElement(parent, this.javaClass)
}
// Delete element if it doesn't contain children of a given type
private fun <T : PsiElement> deleteChildlessElement(element: PsiElement, childClass: Class<T>) {
if (PsiTreeUtil.getChildrenOfType<T>(element, childClass) == null) {
element.delete()
}
}
// Delete given element and all the elements separating it from the neighboring elements of the same class
private fun deleteElementWithDelimiters(element: PsiElement) {
val paramBefore = PsiTreeUtil.getPrevSiblingOfType<PsiElement>(element, element.javaClass)
val from: PsiElement
val to: PsiElement
if (paramBefore != null) {
from = paramBefore.getNextSibling()
to = element
}
else {
val paramAfter = PsiTreeUtil.getNextSiblingOfType<PsiElement>(element, element.javaClass)
from = element
to = if (paramAfter != null) paramAfter.getPrevSibling() else element
}
val parent = element.getParent()
parent.deleteChildRange(from, to)
}
public fun PsiElement.parameterIndex(): Int {
val parent = getParent()
return when {