Moved confusing utility from KtPsiUtil (but the code in KtLightClassForExplicitDeclaration is still incorrect!)

This commit is contained in:
Valentin Kipyatkov
2016-03-23 16:05:04 +03:00
parent 02d309c9cf
commit 03d7c5764d
2 changed files with 17 additions and 20 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.asJava
import com.google.common.collect.Lists
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Comparing
import com.intellij.openapi.util.Key
@@ -31,6 +32,7 @@ import com.intellij.psi.stubs.StubElement
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValuesManager
import com.intellij.util.IncorrectOperationException
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor
@@ -327,7 +329,7 @@ open class KtLightClassForExplicitDeclaration(
val typeElement = typeReference.typeElement
if (typeElement !is KtUserType) continue // If it's not a user type, it's definitely not a ref to deprecated
val fqName = KtPsiUtil.toQualifiedName(typeElement) ?: continue
val fqName = toQualifiedName(typeElement) ?: continue
if (deprecatedFqName == fqName) return true
if (deprecatedName == fqName.asString()) return true
@@ -335,6 +337,20 @@ open class KtLightClassForExplicitDeclaration(
return false
}
private fun toQualifiedName(userType: KtUserType): FqName? {
val reversedNames = Lists.newArrayList<String>()
var current: KtUserType? = userType
while (current != null) {
val name = current.referencedName ?: return null
reversedNames.add(name)
current = current.qualifier
}
return FqName.fromSegments(ContainerUtil.reverse(reversedNames))
}
override fun isInterface(): Boolean {
if (classOrObject !is KtClass) return false
return classOrObject.isInterface() || classOrObject.isAnnotation()