Moving methods modifying PSI to psiModificationUtils.kt

This commit is contained in:
Valentin Kipyatkov
2015-05-28 23:10:41 +03:00
parent c1e0469188
commit e99b343be3
31 changed files with 77 additions and 70 deletions
@@ -57,42 +57,12 @@ public fun JetClassOrObject.effectiveDeclarations(): List<JetDeclaration> =
public fun JetClass.isAbstract(): Boolean = isInterface() || hasModifier(JetTokens.ABSTRACT_KEYWORD)
@suppress("UNCHECKED_CAST")
public inline fun <reified T: PsiElement> PsiElement.replaced(newElement: T): T {
val result = replace(newElement)
return if (result is T)
result
else
(result as JetParenthesizedExpression).getExpression() as T
}
@suppress("UNCHECKED_CAST")
public fun <T: PsiElement> T.copied(): T = copy() as T
public fun JetElement.blockExpressionsOrSingle(): Sequence<JetElement> =
if (this is JetBlockExpression) getStatements().asSequence() else sequenceOf(this)
public fun JetExpression.lastBlockStatementOrThis(): JetExpression
= (this as? JetBlockExpression)?.getStatements()?.lastIsInstanceOrNull<JetExpression>() ?: this
public fun JetBlockExpression.appendElement(element: JetElement): JetElement {
val rBrace = getRBrace()
val anchor = if (rBrace == null) {
val lastChild = getLastChild()
if (lastChild !is PsiWhiteSpace) addAfter(JetPsiFactory(this).createNewLine(), lastChild)!! else lastChild
}
else {
rBrace.getPrevSibling()!!
}
return addAfter(element, anchor)!! as JetElement
}
public fun JetElement.wrapInBlock(): JetBlockExpression {
val block = JetPsiFactory(this).createEmptyBody()
block.appendElement(this)
return block
}
/**
* Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
* via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).