Extensions PsiElement.getParentOfType with reified T
1. Renamed *ByType -> *OfType (as in PsiTreeUtil.java) 2. Introduced PsiElement.getStrictParentOfType and PsiElement.getNonStrictParentOfType with reified TP 3. Replaced current usages of PsiTreeUtil.getParentOfType and current extensions 4. Made reified version of PsiElement.getParentOfTypeAndBranch with default strict value --- false (as it used)
This commit is contained in:
+2
-2
@@ -26,7 +26,7 @@ import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
|
||||
@@ -56,7 +56,7 @@ open public class KotlinLightMethodForDeclaration(
|
||||
private val typeParamsList: CachedValue<PsiTypeParameterList> by Delegates.blockingLazy {
|
||||
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
|
||||
cacheManager.createCachedValue<PsiTypeParameterList>({
|
||||
val declaration = if (origin is JetPropertyAccessor) origin.getParentByType(javaClass<JetProperty>()) else origin
|
||||
val declaration = if (origin is JetPropertyAccessor) origin.getNonStrictParentOfType<JetProperty>() else origin
|
||||
|
||||
val list = if (origin is JetClassOrObject) {
|
||||
LightTypeParameterListBuilder(getManager(), getLanguage())
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.asJava
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isExtensionDeclaration
|
||||
import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList
|
||||
@@ -64,7 +64,7 @@ public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
||||
}
|
||||
|
||||
public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
val paramList = getParentByType(javaClass<JetParameterList>())
|
||||
val paramList = getNonStrictParentOfType<JetParameterList>()
|
||||
if (paramList == null) return null
|
||||
|
||||
val paramIndex = paramList.getParameters().indexOf(this)
|
||||
@@ -85,11 +85,11 @@ public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
}
|
||||
|
||||
public fun JetTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
||||
val paramList = getParentByType(javaClass<JetTypeParameterList>())
|
||||
val paramList = getNonStrictParentOfType<JetTypeParameterList>()
|
||||
if (paramList == null) return listOf()
|
||||
|
||||
val paramIndex = paramList.getParameters().indexOf(this)
|
||||
val jetDeclaration = paramList.getParentByType(javaClass<JetDeclaration>()) ?: return listOf()
|
||||
val jetDeclaration = paramList.getNonStrictParentOfType<JetDeclaration>() ?: return listOf()
|
||||
val lightOwners = jetDeclaration.toLightElements()
|
||||
|
||||
return lightOwners.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).getTypeParameters()[paramIndex] }
|
||||
@@ -100,4 +100,4 @@ public val PsiElement.unwrapped: PsiElement?
|
||||
get() = if (this is KotlinLightElement<*, *>) origin else this
|
||||
|
||||
public val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
||||
get() = unwrapped?.getParentByType(javaClass<PsiNamedElement>())
|
||||
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()
|
||||
Reference in New Issue
Block a user