FIR/UAST: commonize abstract UElement and UExpression
This commit is contained in:
committed by
Ilya Kirillov
parent
a54a807dc9
commit
3c3b5aa4ac
@@ -78,6 +78,7 @@ dependencies {
|
|||||||
compile(project(":idea:idea-jps-common"))
|
compile(project(":idea:idea-jps-common"))
|
||||||
compile(project(":idea:kotlin-gradle-tooling"))
|
compile(project(":idea:kotlin-gradle-tooling"))
|
||||||
compile(project(":idea:line-indent-provider"))
|
compile(project(":idea:line-indent-provider"))
|
||||||
|
compile(project(":plugins:uast-kotlin-base"))
|
||||||
compile(project(":plugins:uast-kotlin"))
|
compile(project(":plugins:uast-kotlin"))
|
||||||
compile(project(":plugins:uast-kotlin-idea"))
|
compile(project(":plugins:uast-kotlin-idea"))
|
||||||
compile(project(":plugins:uast-kotlin-idea-base"))
|
compile(project(":plugins:uast-kotlin-idea-base"))
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ The Kotlin FIR plugin provides language support in IntelliJ IDEA and Android Stu
|
|||||||
<projectService serviceInterface="org.jetbrains.kotlin.psi.KtFileClassProvider"
|
<projectService serviceInterface="org.jetbrains.kotlin.psi.KtFileClassProvider"
|
||||||
serviceImplementation="org.jetbrains.kotlin.idea.caches.resolve.KtFileClassProviderImpl"/>
|
serviceImplementation="org.jetbrains.kotlin.idea.caches.resolve.KtFileClassProviderImpl"/>
|
||||||
|
|
||||||
|
<projectService serviceInterface="org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService"
|
||||||
|
serviceImplementation="org.jetbrains.uast.kotlin.internal.FirIdeaKotlinUastResolveProviderService"/>
|
||||||
<projectService serviceInterface="org.jetbrains.uast.kotlin.FirKotlinUastResolveProviderService"
|
<projectService serviceInterface="org.jetbrains.uast.kotlin.FirKotlinUastResolveProviderService"
|
||||||
serviceImplementation="org.jetbrains.uast.kotlin.internal.FirIdeaKotlinUastResolveProviderService"/>
|
serviceImplementation="org.jetbrains.uast.kotlin.internal.FirIdeaKotlinUastResolveProviderService"/>
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,8 @@
|
|||||||
displayName="Incompatible API usage"
|
displayName="Incompatible API usage"
|
||||||
implementationClass="org.jetbrains.kotlin.idea.inspections.api.IncompatibleAPIInspection"/>
|
implementationClass="org.jetbrains.kotlin.idea.inspections.api.IncompatibleAPIInspection"/>
|
||||||
|
|
||||||
|
<projectService serviceInterface="org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService"
|
||||||
|
serviceImplementation="org.jetbrains.uast.kotlin.internal.IdeaKotlinUastResolveProviderService"/>
|
||||||
<projectService serviceInterface="org.jetbrains.uast.kotlin.KotlinUastResolveProviderService"
|
<projectService serviceInterface="org.jetbrains.uast.kotlin.KotlinUastResolveProviderService"
|
||||||
serviceImplementation="org.jetbrains.uast.kotlin.internal.IdeaKotlinUastResolveProviderService"/>
|
serviceImplementation="org.jetbrains.uast.kotlin.internal.IdeaKotlinUastResolveProviderService"/>
|
||||||
|
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.uast.kotlin
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
|
||||||
|
interface BaseKotlinUastResolveProviderService {
|
||||||
|
fun isJvmElement(psiElement: PsiElement): Boolean
|
||||||
|
|
||||||
|
fun convertParent(uElement: UElement): UElement?
|
||||||
|
|
||||||
|
}
|
||||||
+16
-18
@@ -5,21 +5,30 @@
|
|||||||
|
|
||||||
package org.jetbrains.uast.kotlin
|
package org.jetbrains.uast.kotlin
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.openapi.components.ServiceManager
|
||||||
import org.jetbrains.uast.UElement
|
import org.jetbrains.uast.UElement
|
||||||
import org.jetbrains.uast.UExpression
|
import org.jetbrains.uast.UastFacade
|
||||||
|
import org.jetbrains.uast.UastLanguagePlugin
|
||||||
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
||||||
|
|
||||||
abstract class FirKotlinAbstractUElement(
|
abstract class KotlinAbstractUElement(
|
||||||
private val givenParent: UElement?
|
givenParent: UElement?
|
||||||
) : KotlinUElementWithComments {
|
) : KotlinUElementWithComments {
|
||||||
|
|
||||||
|
protected val languagePlugin: UastLanguagePlugin? by lz {
|
||||||
|
psi?.let { UastFacade.findPlugin(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected val baseResolveProviderService: BaseKotlinUastResolveProviderService? by lz {
|
||||||
|
psi?.project?.let { ServiceManager.getService(it, BaseKotlinUastResolveProviderService::class.java) }
|
||||||
|
}
|
||||||
|
|
||||||
final override val uastParent: UElement? by lz {
|
final override val uastParent: UElement? by lz {
|
||||||
givenParent ?: convertParent()
|
givenParent ?: convertParent()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun convertParent(): UElement? {
|
protected open fun convertParent(): UElement? {
|
||||||
TODO("Not yet implemented")
|
return baseResolveProviderService?.convertParent(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@@ -27,21 +36,10 @@ abstract class FirKotlinAbstractUElement(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sourcePsi == other.sourcePsi
|
return this.psi == other.psi
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return sourcePsi?.hashCode() ?: 0
|
return psi?.hashCode() ?: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class FirKotlinAbstractUExpression(
|
|
||||||
givenParent: UElement?
|
|
||||||
) : FirKotlinAbstractUElement(givenParent), UExpression {
|
|
||||||
override val javaPsi: PsiElement? = null
|
|
||||||
|
|
||||||
override val psi: PsiElement?
|
|
||||||
get() = sourcePsi
|
|
||||||
|
|
||||||
// TODO: annotations
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.uast.kotlin
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
|
||||||
|
import org.jetbrains.uast.UAnnotation
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UExpression
|
||||||
|
import org.jetbrains.uast.convertOpt
|
||||||
|
|
||||||
|
abstract class KotlinAbstractUExpression(
|
||||||
|
givenParent: UElement?
|
||||||
|
) : KotlinAbstractUElement(givenParent), UExpression {
|
||||||
|
|
||||||
|
override val javaPsi: PsiElement? = null
|
||||||
|
|
||||||
|
override val psi
|
||||||
|
get() = sourcePsi
|
||||||
|
|
||||||
|
override val uAnnotations: List<UAnnotation>
|
||||||
|
get() {
|
||||||
|
val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||||
|
return annotatedExpression.annotationEntries.mapNotNull { languagePlugin?.convertOpt(it, this) }
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-3
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.uast.kotlin
|
package org.jetbrains.uast.kotlin
|
||||||
|
|
||||||
import com.intellij.lang.Language
|
import com.intellij.lang.Language
|
||||||
|
import com.intellij.openapi.components.ServiceManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
@@ -18,8 +19,10 @@ import org.jetbrains.uast.UExpression
|
|||||||
import org.jetbrains.uast.UastLanguagePlugin
|
import org.jetbrains.uast.UastLanguagePlugin
|
||||||
import org.jetbrains.uast.kotlin.FirKotlinConverter.convertDeclarationOrElement
|
import org.jetbrains.uast.kotlin.FirKotlinConverter.convertDeclarationOrElement
|
||||||
|
|
||||||
interface FirKotlinUastResolveProviderService {
|
interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderService {
|
||||||
fun isJvmElement(psiElement: PsiElement): Boolean
|
override fun convertParent(uElement: UElement): UElement? {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FirKotlinUastLanguagePlugin : UastLanguagePlugin {
|
class FirKotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||||
@@ -33,7 +36,10 @@ class FirKotlinUastLanguagePlugin : UastLanguagePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val PsiElement.isJvmElement: Boolean
|
private val PsiElement.isJvmElement: Boolean
|
||||||
get() = service.isJvmElement(this)
|
get() {
|
||||||
|
val resolveProvider = ServiceManager.getService(project, FirKotlinUastResolveProviderService::class.java)
|
||||||
|
return resolveProvider.isJvmElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
|
override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
|
||||||
if (!element.isJvmElement) return null
|
if (!element.isJvmElement) return null
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.uast.visitor.UastVisitor
|
|||||||
|
|
||||||
sealed class AbstractFirKotlinUClass(
|
sealed class AbstractFirKotlinUClass(
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
) : FirKotlinAbstractUElement(givenParent), UClass, UAnchorOwner {
|
) : KotlinAbstractUElement(givenParent), UClass, UAnchorOwner {
|
||||||
override val uAnnotations: List<UAnnotation>
|
override val uAnnotations: List<UAnnotation>
|
||||||
get() {
|
get() {
|
||||||
// TODO: Not yet implemented
|
// TODO: Not yet implemented
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ import org.jetbrains.uast.USimpleNameReferenceExpression
|
|||||||
class FirKotlinUImportStatement(
|
class FirKotlinUImportStatement(
|
||||||
override val psi: KtImportDirective,
|
override val psi: KtImportDirective,
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
): FirKotlinAbstractUElement(givenParent), UImportStatement {
|
) : KotlinAbstractUElement(givenParent), UImportStatement {
|
||||||
override val javaPsi: PsiElement? = null
|
override val javaPsi: PsiElement? = null
|
||||||
|
|
||||||
override val sourcePsi: KtImportDirective = psi
|
override val sourcePsi: KtImportDirective = psi
|
||||||
@@ -41,7 +41,7 @@ class FirKotlinUImportStatement(
|
|||||||
override val identifier: String,
|
override val identifier: String,
|
||||||
givenParent: UElement?,
|
givenParent: UElement?,
|
||||||
private val importDirective: KtImportDirective
|
private val importDirective: KtImportDirective
|
||||||
) : FirKotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression {
|
) : KotlinAbstractUExpression(givenParent), USimpleNameReferenceExpression {
|
||||||
override val sourcePsi: KtExpression = psi
|
override val sourcePsi: KtExpression = psi
|
||||||
|
|
||||||
override val resolvedName: String = identifier
|
override val resolvedName: String = identifier
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ open class FirKotlinUMethod(
|
|||||||
psi: PsiMethod,
|
psi: PsiMethod,
|
||||||
final override val sourcePsi: KtDeclaration?,
|
final override val sourcePsi: KtDeclaration?,
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
) : FirKotlinAbstractUElement(givenParent), UMethod, UAnchorOwner, PsiMethod by psi {
|
) : KotlinAbstractUElement(givenParent), UMethod, UAnchorOwner, PsiMethod by psi {
|
||||||
constructor(
|
constructor(
|
||||||
psi: KtLightMethod,
|
psi: KtLightMethod,
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.uast.visitor.UastVisitor
|
|||||||
|
|
||||||
sealed class AbstractFirKotlinUVariable(
|
sealed class AbstractFirKotlinUVariable(
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
) : FirKotlinAbstractUElement(givenParent), PsiVariable, UVariableEx, UAnchorOwner {
|
) : KotlinAbstractUElement(givenParent), PsiVariable, UVariableEx, UAnchorOwner {
|
||||||
override val uAnnotations: List<UAnnotation>
|
override val uAnnotations: List<UAnnotation>
|
||||||
get() {
|
get() {
|
||||||
// TODO: Not yet implemented
|
// TODO: Not yet implemented
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ class FirKotlinUTypeReferenceExpression(
|
|||||||
override val sourcePsi: KtTypeReference,
|
override val sourcePsi: KtTypeReference,
|
||||||
givenParent: UElement?,
|
givenParent: UElement?,
|
||||||
private val typeSupplier: (() -> PsiType)? = null,
|
private val typeSupplier: (() -> PsiType)? = null,
|
||||||
) : FirKotlinAbstractUExpression(givenParent), UTypeReferenceExpression {
|
) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression {
|
||||||
override val type: PsiType by lz {
|
override val type: PsiType by lz {
|
||||||
typeSupplier?.invoke() ?: sourcePsi.toPsiType(uastParent ?: this)
|
typeSupplier?.invoke() ?: sourcePsi.toPsiType(uastParent ?: this)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -8,11 +8,10 @@ package org.jetbrains.uast.kotlin
|
|||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.uast.UElement
|
import org.jetbrains.uast.UElement
|
||||||
import org.jetbrains.uast.UExpression
|
import org.jetbrains.uast.UExpression
|
||||||
import org.jetbrains.uast.kotlin.FirKotlinAbstractUExpression
|
|
||||||
|
|
||||||
class FirUnknownKotlinExpression(
|
class FirUnknownKotlinExpression(
|
||||||
override val sourcePsi: KtExpression,
|
override val sourcePsi: KtExpression,
|
||||||
givenParent: UElement?
|
givenParent: UElement?
|
||||||
) : FirKotlinAbstractUExpression(givenParent), UExpression {
|
) : KotlinAbstractUExpression(givenParent), UExpression {
|
||||||
override fun asLogString() = "[!] FirUnknownKotlinExpression ($sourcePsi)"
|
override fun asLogString() = "[!] FirUnknownKotlinExpression ($sourcePsi)"
|
||||||
}
|
}
|
||||||
|
|||||||
-7
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.uast.kotlin
|
package org.jetbrains.uast.kotlin
|
||||||
|
|
||||||
import com.intellij.openapi.components.ServiceManager
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.uast.UastLanguagePlugin
|
import org.jetbrains.uast.UastLanguagePlugin
|
||||||
|
|
||||||
@@ -14,8 +12,3 @@ val firKotlinUastPlugin: UastLanguagePlugin by lz {
|
|||||||
UastLanguagePlugin.getInstances().find { it.language == KotlinLanguage.INSTANCE }
|
UastLanguagePlugin.getInstances().find { it.language == KotlinLanguage.INSTANCE }
|
||||||
?: FirKotlinUastLanguagePlugin()
|
?: FirKotlinUastLanguagePlugin()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val PsiElement.service: FirKotlinUastResolveProviderService
|
|
||||||
get() {
|
|
||||||
return ServiceManager.getService(project, FirKotlinUastResolveProviderService::class.java)
|
|
||||||
}
|
|
||||||
|
|||||||
+7
-1
@@ -19,6 +19,7 @@ import org.jetbrains.uast.UFile
|
|||||||
import org.jetbrains.uast.UastFacade
|
import org.jetbrains.uast.UastFacade
|
||||||
import org.jetbrains.uast.UastLanguagePlugin
|
import org.jetbrains.uast.UastLanguagePlugin
|
||||||
import org.jetbrains.uast.common.kotlin.FirUastPluginSelection
|
import org.jetbrains.uast.common.kotlin.FirUastPluginSelection
|
||||||
|
import org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService
|
||||||
import org.jetbrains.uast.kotlin.FirKotlinUastResolveProviderService
|
import org.jetbrains.uast.kotlin.FirKotlinUastResolveProviderService
|
||||||
import org.jetbrains.uast.kotlin.firKotlinUastPlugin
|
import org.jetbrains.uast.kotlin.firKotlinUastPlugin
|
||||||
import org.jetbrains.uast.kotlin.internal.FirCliKotlinUastResolveProviderService
|
import org.jetbrains.uast.kotlin.internal.FirCliKotlinUastResolveProviderService
|
||||||
@@ -45,9 +46,14 @@ abstract class AbstractFirUastTest : KotlinLightCodeInsightFixtureTestCase(), Fi
|
|||||||
)
|
)
|
||||||
area.getExtensionPoint(UastLanguagePlugin.extensionPointName)
|
area.getExtensionPoint(UastLanguagePlugin.extensionPointName)
|
||||||
.registerExtension(firKotlinUastPlugin, testRootDisposable)
|
.registerExtension(firKotlinUastPlugin, testRootDisposable)
|
||||||
|
val service = FirCliKotlinUastResolveProviderService()
|
||||||
|
project.registerServiceInstance(
|
||||||
|
BaseKotlinUastResolveProviderService::class.java,
|
||||||
|
service
|
||||||
|
)
|
||||||
project.registerServiceInstance(
|
project.registerServiceInstance(
|
||||||
FirKotlinUastResolveProviderService::class.java,
|
FirKotlinUastResolveProviderService::class.java,
|
||||||
FirCliKotlinUastResolveProviderService()
|
service
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ dependencies {
|
|||||||
compile(project(":compiler:frontend.java"))
|
compile(project(":compiler:frontend.java"))
|
||||||
compile(project(":idea:ide-common"))
|
compile(project(":idea:ide-common"))
|
||||||
compile(project(":idea:idea-core"))
|
compile(project(":idea:idea-core"))
|
||||||
compile(project(":plugins:uast-kotlin-idea-base"))
|
compile(project(":plugins:uast-kotlin-base"))
|
||||||
compile(project(":plugins:uast-kotlin-fir"))
|
compile(project(":plugins:uast-kotlin-fir"))
|
||||||
|
compile(project(":plugins:uast-kotlin-idea-base"))
|
||||||
compileOnly(intellijDep())
|
compileOnly(intellijDep())
|
||||||
compileOnly(intellijPluginDep("java"))
|
compileOnly(intellijPluginDep("java"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ dependencies {
|
|||||||
compile(project(":compiler:frontend.java"))
|
compile(project(":compiler:frontend.java"))
|
||||||
compile(project(":idea:ide-common"))
|
compile(project(":idea:ide-common"))
|
||||||
compile(project(":idea:idea-core"))
|
compile(project(":idea:idea-core"))
|
||||||
|
compile(project(":plugins:uast-kotlin-base"))
|
||||||
compile(project(":plugins:uast-kotlin"))
|
compile(project(":plugins:uast-kotlin"))
|
||||||
compile(project(":plugins:uast-kotlin-idea-base"))
|
compile(project(":plugins:uast-kotlin-idea-base"))
|
||||||
compileOnly(intellijDep())
|
compileOnly(intellijDep())
|
||||||
|
|||||||
@@ -53,12 +53,15 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUMethodWithFakeLightDelegate
|
|||||||
import org.jetbrains.uast.kotlin.expressions.*
|
import org.jetbrains.uast.kotlin.expressions.*
|
||||||
import org.jetbrains.uast.kotlin.psi.*
|
import org.jetbrains.uast.kotlin.psi.*
|
||||||
|
|
||||||
interface KotlinUastResolveProviderService {
|
interface KotlinUastResolveProviderService : BaseKotlinUastResolveProviderService {
|
||||||
fun getBindingContext(element: KtElement): BindingContext
|
fun getBindingContext(element: KtElement): BindingContext
|
||||||
fun getTypeMapper(element: KtElement): KotlinTypeMapper?
|
fun getTypeMapper(element: KtElement): KotlinTypeMapper?
|
||||||
fun getLanguageVersionSettings(element: KtElement): LanguageVersionSettings
|
fun getLanguageVersionSettings(element: KtElement): LanguageVersionSettings
|
||||||
fun isJvmElement(psiElement: PsiElement): Boolean
|
|
||||||
fun getReferenceVariants(ktElement: KtElement, nameHint: String): Sequence<DeclarationDescriptor>
|
fun getReferenceVariants(ktElement: KtElement, nameHint: String): Sequence<DeclarationDescriptor>
|
||||||
|
|
||||||
|
override fun convertParent(uElement: UElement): UElement? {
|
||||||
|
return convertParentImpl(uElement)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var PsiElement.destructuringDeclarationInitializer: Boolean? by UserDataProperty(Key.create("kotlin.uast.destructuringDeclarationInitializer"))
|
var PsiElement.destructuringDeclarationInitializer: Boolean? by UserDataProperty(Key.create("kotlin.uast.destructuringDeclarationInitializer"))
|
||||||
|
|||||||
+7
-42
@@ -33,26 +33,19 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionULambdaExpression
|
import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionULambdaExpression
|
||||||
import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression
|
import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression
|
||||||
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||||
|
|
||||||
abstract class KotlinAbstractUElement(private val givenParent: UElement?) : KotlinUElementWithComments {
|
fun convertParentImpl(uElement: UElement): UElement? {
|
||||||
|
|
||||||
final override val uastParent: UElement? by lz {
|
|
||||||
givenParent ?: convertParent()
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun convertParent(): UElement? {
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
val psi = psi //TODO: `psi` is deprecated but it seems that it couldn't be simply replaced for this case
|
val psi = uElement.psi //TODO: `psi` is deprecated but it seems that it couldn't be simply replaced for this case
|
||||||
var parent = psi?.parent ?: sourcePsi?.parent ?: psi?.containingFile
|
var parent = psi?.parent ?: uElement.sourcePsi?.parent ?: psi?.containingFile
|
||||||
|
|
||||||
if (psi is PsiMethod && psi !is KtLightMethod) { // handling of synthetic things not represented in lightclasses directly
|
if (psi is PsiMethod && psi !is KtLightMethod) { // handling of synthetic things not represented in lightclasses directly
|
||||||
when (parent) {
|
when (parent) {
|
||||||
is KtClassBody -> {
|
is KtClassBody -> {
|
||||||
val grandParent = parent.parent
|
val grandParent = parent.parent
|
||||||
doConvertParent(this, grandParent)?.let { return it }
|
doConvertParent(uElement, grandParent)?.let { return it }
|
||||||
parent = grandParent
|
parent = grandParent
|
||||||
}
|
}
|
||||||
is KtFile -> {
|
is KtFile -> {
|
||||||
@@ -62,7 +55,7 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (psi is KtLightElement<*, *> && sourcePsi.safeAs<KtClassOrObject>()?.isLocal == true) {
|
if (psi is KtLightElement<*, *> && uElement.sourcePsi.safeAs<KtClassOrObject>()?.isLocal == true) {
|
||||||
val originParent = psi.kotlinOrigin?.parent
|
val originParent = psi.kotlinOrigin?.parent
|
||||||
parent = when (originParent) {
|
parent = when (originParent) {
|
||||||
null -> parent
|
null -> parent
|
||||||
@@ -132,23 +125,12 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
|||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = doConvertParent(this, parent)
|
val result = doConvertParent(uElement, parent)
|
||||||
if (result == this) {
|
if (result == uElement) {
|
||||||
throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}], result = $result")
|
throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}], result = $result")
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (other !is UElement) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.psi == other.psi
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode() = psi?.hashCode() ?: 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doConvertParent(element: UElement, parent: PsiElement?): UElement? {
|
fun doConvertParent(element: UElement, parent: PsiElement?): UElement? {
|
||||||
@@ -247,20 +229,3 @@ private fun findAnnotationClassFromConstructorParameter(parameter: KtParameter):
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class KotlinAbstractUExpression(givenParent: UElement?) :
|
|
||||||
KotlinAbstractUElement(givenParent),
|
|
||||||
UExpression {
|
|
||||||
|
|
||||||
override val javaPsi: PsiElement? = null
|
|
||||||
|
|
||||||
override val psi
|
|
||||||
get() = sourcePsi
|
|
||||||
|
|
||||||
override val annotations: List<UAnnotation>
|
|
||||||
get() {
|
|
||||||
val annotatedExpression = sourcePsi?.parent as? KtAnnotatedExpression ?: return emptyList()
|
|
||||||
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.test.TestJdkKind
|
|||||||
import org.jetbrains.kotlin.test.testFramework.resetApplicationToNull
|
import org.jetbrains.kotlin.test.testFramework.resetApplicationToNull
|
||||||
import org.jetbrains.uast.UastLanguagePlugin
|
import org.jetbrains.uast.UastLanguagePlugin
|
||||||
import org.jetbrains.uast.evaluation.UEvaluatorExtension
|
import org.jetbrains.uast.evaluation.UEvaluatorExtension
|
||||||
|
import org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService
|
||||||
import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin
|
import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin
|
||||||
import org.jetbrains.uast.kotlin.KotlinUastResolveProviderService
|
import org.jetbrains.uast.kotlin.KotlinUastResolveProviderService
|
||||||
import org.jetbrains.uast.kotlin.evaluation.KotlinEvaluatorExtension
|
import org.jetbrains.uast.kotlin.evaluation.KotlinEvaluatorExtension
|
||||||
@@ -94,6 +95,10 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() {
|
|||||||
area.getExtensionPoint(UEvaluatorExtension.EXTENSION_POINT_NAME)
|
area.getExtensionPoint(UEvaluatorExtension.EXTENSION_POINT_NAME)
|
||||||
.registerExtension(KotlinEvaluatorExtension())
|
.registerExtension(KotlinEvaluatorExtension())
|
||||||
|
|
||||||
|
project.registerService(
|
||||||
|
BaseKotlinUastResolveProviderService::class.java,
|
||||||
|
CliKotlinUastResolveProviderService::class.java
|
||||||
|
)
|
||||||
project.registerService(
|
project.registerService(
|
||||||
KotlinUastResolveProviderService::class.java,
|
KotlinUastResolveProviderService::class.java,
|
||||||
CliKotlinUastResolveProviderService::class.java
|
CliKotlinUastResolveProviderService::class.java
|
||||||
|
|||||||
Reference in New Issue
Block a user