Don't duplicate UAST parent calculation logic

This commit is contained in:
Dmitry Jemerov
2017-09-13 13:38:27 +02:00
parent b638febc41
commit a5a5b37e1e
6 changed files with 12 additions and 31 deletions
@@ -13,10 +13,8 @@ import org.jetbrains.uast.*
class KotlinUAnnotation(
override val psi: KtAnnotationEntry,
private val givenParent: UElement?
) : UAnnotation {
override val uastParent: UElement? by lz { convertParent(givenParent) }
givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UAnnotation {
private val resolvedAnnotation: AnnotationDescriptor? by lz { psi.analyze()[BindingContext.ANNOTATION, psi] }
private val resolvedCall: ResolvedCall<*>? by lz { psi.getResolvedCall(psi.analyze()) }
@@ -28,10 +28,8 @@ import org.jetbrains.uast.USimpleNameReferenceExpression
class KotlinUImportStatement(
override val psi: KtImportDirective,
private val givenParent: UElement?
) : UImportStatement {
override val uastParent: UElement? by lz { convertParent(givenParent) }
givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UImportStatement {
override val isOnDemand: Boolean
get() = psi.isAllUnder
@@ -30,12 +30,10 @@ import org.jetbrains.uast.kotlin.*
open class KotlinUMethod(
psi: KtLightMethod,
private val givenParent: UElement?
) : UAnnotationMethod, JavaUElementWithComments, PsiMethod by psi {
givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UAnnotationMethod, JavaUElementWithComments, PsiMethod by psi {
override val psi: KtLightMethod = unwrap<UMethod, KtLightMethod>(psi)
override val uastParent: UElement? by lz { convertParent(givenParent) }
override val uastDefaultValue by lz {
val annotationParameter = psi.kotlinOrigin as? KtParameter ?: return@lz null
val defaultValue = annotationParameter.defaultValue ?: return@lz null
@@ -85,8 +83,6 @@ open class KotlinUMethod(
override fun equals(other: Any?) = other is KotlinUMethod && psi == other.psi
override fun hashCode() = psi.hashCode()
companion object {
fun create(psi: KtLightMethod, containingElement: UElement?) = KotlinUMethod(psi, containingElement)
}
@@ -33,10 +33,8 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
import org.jetbrains.uast.visitor.UastVisitor
abstract class AbstractKotlinUVariable(private val givenParent: UElement?)
: PsiVariable, UVariable, KotlinUElementWithComments {
override val uastParent: UElement? by lz { convertParent(givenParent) }
abstract class AbstractKotlinUVariable(givenParent: UElement?)
: KotlinAbstractUElement(givenParent), PsiVariable, UVariable, KotlinUElementWithComments {
override val uastInitializer: UExpression?
get() {
@@ -83,8 +81,6 @@ abstract class AbstractKotlinUVariable(private val givenParent: UElement?)
get() = UIdentifier(nameIdentifier, this)
override fun equals(other: Any?) = other is AbstractKotlinUVariable && psi == other.psi
override fun hashCode() = psi.hashCode()
}
class KotlinUVariable(
@@ -23,17 +23,15 @@ import org.jetbrains.uast.*
class KotlinUNamedExpression private constructor(
override val name: String?,
private val givenParent: UElement?,
givenParent: UElement?,
expressionProducer: (UElement) -> UExpression
) : UNamedExpression {
) : KotlinAbstractUElement(givenParent), UNamedExpression {
override val expression: UExpression by lz { expressionProducer(this) }
override val annotations: List<UAnnotation> = emptyList()
override val psi: PsiElement? = null
override val uastParent: UElement? by lz { convertParent(givenParent) }
companion object {
internal fun create(name: String?, valueArgument: ValueArgument, uastParent: UElement?): UNamedExpression {
val expression = valueArgument.getArgumentExpression()
@@ -12,19 +12,14 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
private class KotlinLocalFunctionUVariable(
val function: KtFunction,
override val psi: PsiVariable,
private val givenParent: UElement?
) : UVariable, PsiVariable by psi {
override val uastParent: UElement? by lz { convertParent(givenParent) }
givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UVariable, PsiVariable by psi {
override val uastInitializer: UExpression? by lz {
createLocalFunctionLambdaExpression(function, this)
}
override val typeReference: UTypeReferenceExpression? = null
override val uastAnchor: UElement? = null
override val annotations: List<UAnnotation> = emptyList()
override fun equals(other: Any?) = other is KotlinLocalFunctionUVariable && psi == other.psi
override fun hashCode() = psi.hashCode()
}