Don't use plain text generation

This commit is contained in:
Valentin Kipyatkov
2015-05-23 20:03:34 +03:00
parent 5df840d9e3
commit 17f0ac9ba7
11 changed files with 81 additions and 47 deletions
@@ -566,10 +566,14 @@ public class JetPsiFactory(private val project: Project) {
}
}
public fun createFunctionBody(bodyText: String): JetBlockExpression {
public fun createBlock(bodyText: String): JetBlockExpression {
return createFunction("fun foo() {\n" + bodyText + "\n}").getBodyExpression() as JetBlockExpression
}
public fun createSingleStatementBlock(statement: JetExpression): JetBlockExpression {
return createDeclarationByPattern<JetNamedFunction>("fun foo() {\n$0\n}", statement).getBodyExpression() as JetBlockExpression
}
public fun createComment(text: String): PsiComment {
val file = createFile(text)
val comments = file.getChildren().filterIsInstance<PsiComment>()
@@ -573,12 +573,16 @@ public inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(no
}
public inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean): Boolean {
var result = false
return findDescendantOfType(predicate) != null
}
public inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(noinline predicate: (T) -> Boolean): T? {
var result: T? = null
this.accept(object : PsiRecursiveElementVisitor(){
override fun visitElement(element: PsiElement) {
if (result) return
if (result != null) return
if (element is T && predicate(element)) {
result = true
result = element
return
}
super.visitElement(element)
@@ -587,7 +591,7 @@ public inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinli
return result
}
public inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): Collection<T> {
public inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): List<T> {
val result = ArrayList<T>()
forEachDescendantOfType<T> {
if (predicate(it)) {