[light classes] extract KtLightModifierList to light-classes-base module
^KT-53097
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 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.asJava.elements
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotation
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiModifierList
|
||||||
|
import com.intellij.psi.PsiModifierListOwner
|
||||||
|
import com.intellij.util.IncorrectOperationException
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||||
|
import org.jetbrains.kotlin.psi.KtModifierList
|
||||||
|
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||||
|
|
||||||
|
abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
||||||
|
protected val owner: T
|
||||||
|
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierList> {
|
||||||
|
private val _annotations by lazyPub {
|
||||||
|
val annotations = computeAnnotations()
|
||||||
|
annotationsFilter?.let(annotations::filter) ?: annotations
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open val annotationsFilter: ((KtLightAbstractAnnotation) -> Boolean)? = null
|
||||||
|
|
||||||
|
override val kotlinOrigin: KtModifierList?
|
||||||
|
get() = owner.kotlinOrigin?.modifierList
|
||||||
|
|
||||||
|
override fun getParent() = owner
|
||||||
|
|
||||||
|
override fun hasExplicitModifier(name: String) = hasModifierProperty(name)
|
||||||
|
|
||||||
|
private fun throwInvalidOperation(): Nothing = throw IncorrectOperationException()
|
||||||
|
|
||||||
|
override fun setModifierProperty(name: String, value: Boolean): Unit = throwInvalidOperation()
|
||||||
|
|
||||||
|
override fun checkSetModifierProperty(name: String, value: Boolean): Unit = throwInvalidOperation()
|
||||||
|
|
||||||
|
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throwInvalidOperation()
|
||||||
|
|
||||||
|
override fun getApplicableAnnotations(): Array<out PsiAnnotation> = annotations
|
||||||
|
|
||||||
|
override fun getAnnotations(): Array<out PsiAnnotation> = _annotations.toTypedArray()
|
||||||
|
override fun findAnnotation(qualifiedName: String) = _annotations.firstOrNull { it.fqNameMatches(qualifiedName) }
|
||||||
|
|
||||||
|
override fun isEquivalentTo(another: PsiElement?) =
|
||||||
|
another is KtLightModifierList<*> && owner == another.owner
|
||||||
|
|
||||||
|
override fun isWritable() = false
|
||||||
|
|
||||||
|
override fun toString() = "Light modifier list of $owner"
|
||||||
|
|
||||||
|
open fun nonSourceAnnotationsForAnnotationType(sourceAnnotations: List<PsiAnnotation>): List<KtLightAbstractAnnotation> = emptyList()
|
||||||
|
|
||||||
|
abstract fun computeAnnotations(): List<KtLightAbstractAnnotation>
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import com.intellij.psi.impl.InheritanceImplUtil
|
|||||||
import com.intellij.psi.scope.PsiScopeProcessor
|
import com.intellij.psi.scope.PsiScopeProcessor
|
||||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||||
import org.jetbrains.kotlin.asJava.elements.FakeFileForLightClass
|
import org.jetbrains.kotlin.asJava.elements.FakeFileForLightClass
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightModifierList
|
import org.jetbrains.kotlin.asJava.elements.KtLightModifierListDescriptorBased
|
||||||
import org.jetbrains.kotlin.asJava.hasInterfaceDefaultImpls
|
import org.jetbrains.kotlin.asJava.hasInterfaceDefaultImpls
|
||||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.config.JvmDefaultMode
|
import org.jetbrains.kotlin.config.JvmDefaultMode
|
||||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
private class KtLightClassModifierList(containingClass: KtLightClassForSourceDeclaration, computeModifiers: () -> Set<String>) :
|
private class KtLightClassModifierList(containingClass: KtLightClassForSourceDeclaration, computeModifiers: () -> Set<String>) :
|
||||||
KtLightModifierList<KtLightClassForSourceDeclaration>(containingClass) {
|
KtLightModifierListDescriptorBased<KtLightClassForSourceDeclaration>(containingClass) {
|
||||||
|
|
||||||
private val modifiers by lazyPub { computeModifiers() }
|
private val modifiers by lazyPub { computeModifiers() }
|
||||||
|
|
||||||
|
|||||||
+15
-50
@@ -3,13 +3,19 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:JvmName("KtLightModifierListDescriptorBasedKt")
|
||||||
|
|
||||||
package org.jetbrains.kotlin.asJava.elements
|
package org.jetbrains.kotlin.asJava.elements
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.CommonClassNames
|
||||||
import com.intellij.util.IncorrectOperationException
|
import com.intellij.psi.PsiAnnotation
|
||||||
|
import com.intellij.psi.PsiModifierListOwner
|
||||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
||||||
import org.jetbrains.kotlin.asJava.classes.*
|
import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtUltraLightElementWithNullabilityAnnotation
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtUltraLightNullabilityAnnotation
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtUltraLightSupport
|
||||||
import org.jetbrains.kotlin.asJava.fastCheckIsNullabilityApplied
|
import org.jetbrains.kotlin.asJava.fastCheckIsNullabilityApplied
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
@@ -21,46 +27,9 @@ import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||||
|
|
||||||
abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
abstract class KtLightModifierListDescriptorBased<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(owner: T) :
|
||||||
protected val owner: T
|
KtLightModifierList<T>(owner) {
|
||||||
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierList> {
|
override fun computeAnnotations(): List<KtLightAbstractAnnotation> {
|
||||||
private val _annotations by lazyPub {
|
|
||||||
val annotations = computeAnnotations()
|
|
||||||
annotationsFilter?.let(annotations::filter) ?: annotations
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open val annotationsFilter: ((KtLightAbstractAnnotation) -> Boolean)? = null
|
|
||||||
|
|
||||||
override val kotlinOrigin: KtModifierList?
|
|
||||||
get() = owner.kotlinOrigin?.modifierList
|
|
||||||
|
|
||||||
override fun getParent() = owner
|
|
||||||
|
|
||||||
override fun hasExplicitModifier(name: String) = hasModifierProperty(name)
|
|
||||||
|
|
||||||
private fun throwInvalidOperation(): Nothing = throw IncorrectOperationException()
|
|
||||||
|
|
||||||
override fun setModifierProperty(name: String, value: Boolean): Unit = throwInvalidOperation()
|
|
||||||
|
|
||||||
override fun checkSetModifierProperty(name: String, value: Boolean): Unit = throwInvalidOperation()
|
|
||||||
|
|
||||||
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throwInvalidOperation()
|
|
||||||
|
|
||||||
override fun getApplicableAnnotations(): Array<out PsiAnnotation> = annotations
|
|
||||||
|
|
||||||
override fun getAnnotations(): Array<out PsiAnnotation> = _annotations.toTypedArray()
|
|
||||||
override fun findAnnotation(qualifiedName: String) = _annotations.firstOrNull { it.fqNameMatches(qualifiedName) }
|
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement?) =
|
|
||||||
another is KtLightModifierList<*> && owner == another.owner
|
|
||||||
|
|
||||||
override fun isWritable() = false
|
|
||||||
|
|
||||||
override fun toString() = "Light modifier list of $owner"
|
|
||||||
|
|
||||||
open fun nonSourceAnnotationsForAnnotationType(sourceAnnotations: List<PsiAnnotation>): List<KtLightAbstractAnnotation> = emptyList()
|
|
||||||
|
|
||||||
private fun computeAnnotations(): List<KtLightAbstractAnnotation> {
|
|
||||||
val annotationsForEntries = owner.givenAnnotations ?: lightAnnotationsForEntries(this)
|
val annotationsForEntries = owner.givenAnnotations ?: lightAnnotationsForEntries(this)
|
||||||
//TODO: Hacky way to update wrong parents for annotations
|
//TODO: Hacky way to update wrong parents for annotations
|
||||||
annotationsForEntries.forEach {
|
annotationsForEntries.forEach {
|
||||||
@@ -98,7 +67,7 @@ abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, P
|
|||||||
class KtUltraLightSimpleModifierList(
|
class KtUltraLightSimpleModifierList(
|
||||||
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>,
|
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>,
|
||||||
private val modifiers: Set<String>,
|
private val modifiers: Set<String>,
|
||||||
) : KtUltraLightModifierListBase<KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(owner) {
|
) : KtLightModifierListDescriptorBased<KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(owner) {
|
||||||
override fun hasModifierProperty(name: String) = name in modifiers
|
override fun hasModifierProperty(name: String) = name in modifiers
|
||||||
|
|
||||||
override fun copy() = KtUltraLightSimpleModifierList(owner, modifiers)
|
override fun copy() = KtUltraLightSimpleModifierList(owner, modifiers)
|
||||||
@@ -107,7 +76,7 @@ class KtUltraLightSimpleModifierList(
|
|||||||
abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
||||||
owner: T,
|
owner: T,
|
||||||
protected val support: KtUltraLightSupport
|
protected val support: KtUltraLightSupport
|
||||||
) : KtUltraLightModifierListBase<T>(owner) {
|
) : KtLightModifierListDescriptorBased<T>(owner) {
|
||||||
|
|
||||||
protected open fun PsiAnnotation.additionalConverter(): KtLightAbstractAnnotation? = null
|
protected open fun PsiAnnotation.additionalConverter(): KtLightAbstractAnnotation? = null
|
||||||
|
|
||||||
@@ -132,13 +101,9 @@ abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class KtUltraLightModifierListBase<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
|
||||||
owner: T
|
|
||||||
) : KtLightModifierList<T>(owner)
|
|
||||||
|
|
||||||
class KtLightSimpleModifierList(
|
class KtLightSimpleModifierList(
|
||||||
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>, private val modifiers: Set<String>
|
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>, private val modifiers: Set<String>
|
||||||
) : KtLightModifierList<KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(owner) {
|
) : KtLightModifierListDescriptorBased<KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(owner) {
|
||||||
override fun hasModifierProperty(name: String) = name in modifiers
|
override fun hasModifierProperty(name: String) = name in modifiers
|
||||||
|
|
||||||
override fun copy() = KtLightSimpleModifierList(owner, modifiers)
|
override fun copy() = KtLightSimpleModifierList(owner, modifiers)
|
||||||
Reference in New Issue
Block a user