Make KtLightModifierList behave like light element and check it in tests
This commit is contained in:
+25
-1
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.light.LightModifierList
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.util.ArrayUtil
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
@@ -52,7 +54,7 @@ abstract class KtLightModifierListWithExplicitModifiers(
|
||||
class KtLightModifierList(
|
||||
private val delegate: PsiModifierList,
|
||||
private val owner: PsiModifierListOwner
|
||||
): PsiModifierList by delegate {
|
||||
) : PsiModifierList by delegate {
|
||||
private val _annotations by lazy { computeAnnotations(this, delegate) }
|
||||
|
||||
override fun getAnnotations(): Array<out PsiAnnotation> = _annotations.value
|
||||
@@ -62,6 +64,28 @@ class KtLightModifierList(
|
||||
override fun addAnnotation(@NonNls qualifiedName: String) = delegate.addAnnotation(qualifiedName)
|
||||
|
||||
override fun getParent() = owner
|
||||
|
||||
override fun getText(): String? = ""
|
||||
|
||||
override fun getLanguage() = KotlinLanguage.INSTANCE
|
||||
override fun getTextRange() = TextRange.EMPTY_RANGE
|
||||
override fun getStartOffsetInParent() = -1
|
||||
override fun getTextLength() = 0
|
||||
override fun getPrevSibling(): PsiElement? = null
|
||||
override fun getNextSibling(): PsiElement? = null
|
||||
override fun findElementAt(offset: Int): PsiElement? = null
|
||||
override fun findReferenceAt(offset: Int): PsiReference? = null
|
||||
override fun getTextOffset() = -1
|
||||
override fun isWritable() = false
|
||||
override fun isPhysical() = false
|
||||
override fun textToCharArray(): CharArray = ArrayUtil.EMPTY_CHAR_ARRAY;
|
||||
override fun textMatches(text: CharSequence): Boolean = getText() == text.toString()
|
||||
override fun textMatches(element: PsiElement): Boolean = text == element.text
|
||||
override fun textContains(c: Char): Boolean = text?.contains(c) ?: false
|
||||
override fun copy(): PsiElement = KtLightModifierList(delegate, owner)
|
||||
override fun getReferences() = PsiReference.EMPTY_ARRAY
|
||||
override fun isEquivalentTo(another: PsiElement?) =
|
||||
another is KtLightModifierList && delegate == another.delegate && owner == owner
|
||||
}
|
||||
|
||||
internal fun computeAnnotations(lightElement: PsiModifierList,
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.asJava.KtLightElement
|
||||
import org.jetbrains.kotlin.asJava.KtLightModifierList
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.junit.Assert
|
||||
|
||||
@@ -39,7 +40,7 @@ object PsiElementChecker {
|
||||
}
|
||||
|
||||
private fun checkPsiElement(element: PsiElement) {
|
||||
if (element !is KtLightElement<*, *>) return
|
||||
if (element !is KtLightElement<*, *> && element !is KtLightModifierList) return
|
||||
|
||||
if (element is PsiModifierListOwner) {
|
||||
val modifierList = element.modifierList
|
||||
|
||||
Reference in New Issue
Block a user