Move UL compiler plugin support to separate extension point
This commit is contained in:
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.kotlin.extensions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
enum class LightClassApplicabilityType {
|
||||
LightClass,
|
||||
UltraLightClass
|
||||
}
|
||||
|
||||
/**
|
||||
* This extension point needs to be implemented by the Kotlin compiler plugins in case they change the requested declaration (i.e. producing synthetic parts)
|
||||
* with backend extension points. The light class provider will request this EP to check either to create LightClass or UltraLight class implementations.
|
||||
* @see org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
||||
* @see org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
*/
|
||||
interface LightClassApplicabilityCheckExtension {
|
||||
companion object : ProjectExtensionDescriptor<LightClassApplicabilityCheckExtension>(
|
||||
"org.jetbrains.kotlin.lightClassApplicabilityCheckExtension",
|
||||
LightClassApplicabilityCheckExtension::class.java
|
||||
)
|
||||
|
||||
/**
|
||||
* This method should return LightClass if any changes in Kotlin declarations is going to be produced during JVM-backend code generation.
|
||||
* This method ought to be as fast as possible but never return UltraLightClass when not sure.
|
||||
* Next advice could be given to make best:
|
||||
* 1) Try to cover as much cases as possible without forcing descriptor evaluation
|
||||
* 2) After you've forced descriptor evaluation, ideally, you should never return LightClass while in fact no synthetic parts going to be generated
|
||||
* 3) So, you should force descriptor evaluation only if you're sure that you will be able to return UltraLightClass significantly more often
|
||||
* @see org.jetbrains.kotlin.noarg.ide.IdeNoArgApplicabilityExtension
|
||||
* @see org.jetbrains.kotlin.android.parcel.IDEParcelableApplicabilityExtension
|
||||
*/
|
||||
fun checkApplicabilityType(declaration: KtDeclaration, descriptor: Lazy<DeclarationDescriptor?>): LightClassApplicabilityType
|
||||
}
|
||||
+9
-2
@@ -9,9 +9,16 @@ import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightField
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
interface UltraLightClassCodegenSupport {
|
||||
interface UltraLightClassModifierExtension {
|
||||
|
||||
companion object : ProjectExtensionDescriptor<UltraLightClassModifierExtension>(
|
||||
"org.jetbrains.kotlin.ultraLightClassModifierExtension",
|
||||
UltraLightClassModifierExtension::class.java
|
||||
)
|
||||
|
||||
fun interceptMethodsBuilding(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: Lazy<DeclarationDescriptor?>,
|
||||
@@ -23,6 +30,6 @@ interface UltraLightClassCodegenSupport {
|
||||
declaration: KtDeclaration,
|
||||
descriptor: Lazy<DeclarationDescriptor?>,
|
||||
containingDeclaration: KtUltraLightClass,
|
||||
methodsList: MutableList<KtLightField>
|
||||
fieldsList: MutableList<KtLightField>
|
||||
) = Unit
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import com.intellij.psi.impl.light.LightMethodBuilder
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.kotlin.asJava.UltraLightClassCodegenSupport
|
||||
import org.jetbrains.kotlin.asJava.UltraLightClassModifierExtension
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassData
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightField
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
@@ -340,10 +340,8 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
return result
|
||||
}
|
||||
|
||||
private inline fun applyCompilerPlugins(body: (UltraLightClassCodegenSupport) -> Unit) {
|
||||
ExpressionCodegenExtension.getInstances(project)
|
||||
.filterIsInstance<UltraLightClassCodegenSupport>()
|
||||
.forEach { body(it) }
|
||||
private inline fun applyCompilerPlugins(body: (UltraLightClassModifierExtension) -> Unit) {
|
||||
UltraLightClassModifierExtension.getInstances(project).forEach { body(it) }
|
||||
}
|
||||
|
||||
private val _ownMethods: CachedValue<List<KtLightMethod>> = CachedValuesManager.getManager(project).createCachedValue(
|
||||
|
||||
Reference in New Issue
Block a user