Light Elements: Filter out nulls when converting Kotlin declarations to corresponding light elements

#EA-64403 Fixed
This commit is contained in:
Alexey Sedunov
2015-05-28 18:27:11 +03:00
parent fed8047a59
commit 26c4efb587
2 changed files with 9 additions and 5 deletions
@@ -17,22 +17,24 @@
package org.jetbrains.kotlin.asJava
import com.intellij.psi.*
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.psi.*
import java.util.Collections
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import java.util.ArrayList
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
public fun JetClassOrObject.toLightClass(): KotlinLightClass? = LightClassUtil.getPsiClass(this) as KotlinLightClass?
public fun JetDeclaration.toLightElements(): List<PsiNamedElement> =
when (this) {
is JetClassOrObject -> Collections.singletonList(LightClassUtil.getPsiClass(this))
is JetClassOrObject -> LightClassUtil.getPsiClass(this).singletonOrEmptyList()
is JetNamedFunction,
is JetSecondaryConstructor -> Collections.singletonList(LightClassUtil.getLightClassMethod(this as JetFunction))
is JetSecondaryConstructor -> LightClassUtil.getLightClassMethod(this as JetFunction).singletonOrEmptyList()
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
is JetPropertyAccessor -> Collections.singletonList(LightClassUtil.getLightClassAccessorMethod(this))
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
is JetParameter -> ArrayList<PsiNamedElement>().let { elements ->
toPsiParameter()?.let { psiParameter -> elements.add(psiParameter) }
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
@@ -49,8 +51,8 @@ public fun PsiElement.toLightMethods(): List<PsiMethod> =
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).toList()
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
is JetClass -> Collections.singletonList(LightClassUtil.getPsiClass(this).getConstructors()[0])
is PsiMethod -> Collections.singletonList(this)
is JetClass -> LightClassUtil.getPsiClass(this)?.getConstructors()?.first().singletonOrEmptyList()
is PsiMethod -> this.singletonList()
else -> listOf()
}
@@ -21,6 +21,8 @@ import java.util.NoSuchElementException
public fun <T: Any> T?.singletonOrEmptyList(): List<T> = if (this != null) Collections.singletonList(this) else Collections.emptyList()
public fun <T> T.singletonList(): List<T> = Collections.singletonList(this)
public fun <T: Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) Collections.singleton(this) else Collections.emptySet()
public inline fun <reified T : Any> Stream<*>.firstIsInstanceOrNull(): T? {