Add UL support for NoArg compiler plugin
This commit is contained in:
+15
-12
@@ -28,18 +28,21 @@ abstract class AnnotationBasedLightClassApplicabilityExtension(project: Project,
|
||||
cachedAnnotationsNames.getAnnotationNames(modifierListOwner)
|
||||
|
||||
override fun checkApplicabilityType(declaration: KtDeclaration, descriptor: Lazy<DeclarationDescriptor?>): LightClassApplicabilityType {
|
||||
if (!declaration.isOrdinaryClass || !declaration.isAnnotated) return UltraLightClass
|
||||
|
||||
if (cachedAnnotationsNames.getAnnotationNames(declaration).isEmpty()) return UltraLightClass
|
||||
|
||||
val descriptorValue = descriptor.value ?: return UltraLightClass
|
||||
|
||||
val classDescriptor = (descriptorValue as? ClassDescriptor)
|
||||
?: descriptorValue.containingDeclaration as? ClassDescriptor
|
||||
?: return UltraLightClass
|
||||
|
||||
val hasSpecialAnnotation = run { classDescriptor.hasSpecialAnnotation(declaration) }
|
||||
|
||||
return if (hasSpecialAnnotation) LightClass else UltraLightClass
|
||||
return UltraLightClass
|
||||
//
|
||||
// if (!declaration.isOrdinaryClass || !declaration.isAnnotated) return UltraLightClass
|
||||
//
|
||||
// if (cachedAnnotationsNames.getAnnotationNames(declaration).isEmpty()) return UltraLightClass
|
||||
//
|
||||
// val descriptorValue = descriptor.value ?: return UltraLightClass
|
||||
//
|
||||
// val classDescriptor = (descriptorValue as? ClassDescriptor)
|
||||
// ?: descriptorValue.containingDeclaration as? ClassDescriptor
|
||||
// ?: return UltraLightClass
|
||||
//
|
||||
// val hasSpecialAnnotation = run { classDescriptor.hasSpecialAnnotation(declaration) }
|
||||
//
|
||||
// return if (hasSpecialAnnotation) LightClass else UltraLightClass
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ abstract class AbstractNoArgExpressionCodegenExtension(val invokeInitializers: B
|
||||
})
|
||||
}
|
||||
|
||||
private fun createNoArgConstructorDescriptor(containingClass: ClassDescriptor): ConstructorDescriptor {
|
||||
protected fun createNoArgConstructorDescriptor(containingClass: ClassDescriptor): ConstructorDescriptor {
|
||||
return ClassConstructorDescriptorImpl.createSynthesized(containingClass, Annotations.EMPTY, false, SourceElement.NO_SOURCE).apply {
|
||||
initialize(
|
||||
null, calculateDispatchReceiverParameter(), emptyList(), emptyList(),
|
||||
|
||||
@@ -43,6 +43,8 @@ dependencies {
|
||||
testRuntimeOnly(intellijDep())
|
||||
|
||||
Platform[192].orHigher {
|
||||
compileOnly(intellijPluginDep("java"))
|
||||
|
||||
testCompileOnly(intellijPluginDep("java"))
|
||||
testRuntimeOnly(intellijPluginDep("java"))
|
||||
}
|
||||
|
||||
@@ -8,14 +8,49 @@ package org.jetbrains.kotlin.noarg.ide
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.CachedAnnotationNames
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.getAnnotationNames
|
||||
import org.jetbrains.kotlin.asJava.UltraLightClassCodegenSupport
|
||||
import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.createGeneratedMethodFromDescriptor
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.noarg.AbstractNoArgExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.util.isAnnotated
|
||||
import org.jetbrains.kotlin.util.isOrdinaryClass
|
||||
|
||||
class IdeNoArgExpressionCodegenExtension(project: Project) :
|
||||
AbstractNoArgExpressionCodegenExtension(invokeInitializers = false) {
|
||||
AbstractNoArgExpressionCodegenExtension(invokeInitializers = false),
|
||||
UltraLightClassCodegenSupport {
|
||||
|
||||
private val cachedAnnotationsNames = CachedAnnotationNames(project, NO_ARG_ANNOTATION_OPTION_PREFIX)
|
||||
|
||||
override fun getAnnotationFqNames(modifierListOwner: KtModifierListOwner?): List<String> =
|
||||
cachedAnnotationsNames.getAnnotationNames(modifierListOwner)
|
||||
|
||||
override fun interceptMethodsBuilding(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: Lazy<DeclarationDescriptor?>,
|
||||
containingDeclaration: KtUltraLightClass,
|
||||
methodsList: MutableList<KtLightMethod>
|
||||
) {
|
||||
if (!declaration.isOrdinaryClass || !declaration.isAnnotated) return
|
||||
|
||||
if (cachedAnnotationsNames.getAnnotationNames(declaration).isEmpty()) return
|
||||
|
||||
val descriptorValue = descriptor.value ?: return
|
||||
|
||||
val classDescriptor = (descriptorValue as? ClassDescriptor)
|
||||
?: descriptorValue.containingDeclaration as? ClassDescriptor
|
||||
?: return
|
||||
|
||||
if (!run { classDescriptor.hasSpecialAnnotation(declaration) }) return
|
||||
|
||||
val parentClass = containingDeclaration as? KtUltraLightClass ?: return
|
||||
|
||||
val constructorDescriptor = createNoArgConstructorDescriptor(classDescriptor)
|
||||
|
||||
methodsList.add(parentClass.createGeneratedMethodFromDescriptor(constructorDescriptor))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.noarg
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinProjectDescriptorWithFacet
|
||||
|
||||
Reference in New Issue
Block a user