Refactor: get rid of LightClassUtil#getPsiClass() in favor of KtClassOrObject:toLightClass extension
This commit is contained in:
@@ -45,6 +45,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.asJava.LightClassUtilsKt.toLightClass;
|
||||
|
||||
public class JavaElementFinder extends PsiElementFinder implements KotlinFinderMarker {
|
||||
|
||||
@NotNull
|
||||
@@ -133,7 +135,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
||||
|
||||
for (KtClassOrObject declaration : classOrObjectDeclarations) {
|
||||
if (!(declaration instanceof KtEnumEntry)) {
|
||||
PsiClass lightClass = LightClassUtil.INSTANCE.getPsiClass(declaration);
|
||||
PsiClass lightClass = toLightClass(declaration);
|
||||
if (lightClass != null) {
|
||||
answer.add(lightClass);
|
||||
}
|
||||
@@ -149,7 +151,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
||||
for (KtClassOrObject classOrObject : lightClassGenerationSupport.findClassOrObjectDeclarations(qualifiedName.parent(), scope)) {
|
||||
//NOTE: can't filter out more interfaces right away because decompiled declarations do not have member bodies
|
||||
if (classOrObject instanceof KtClass && ((KtClass) classOrObject).isInterface()) {
|
||||
PsiClass interfaceClass = LightClassUtil.INSTANCE.getPsiClass(classOrObject);
|
||||
PsiClass interfaceClass = toLightClass(classOrObject);
|
||||
if (interfaceClass != null) {
|
||||
PsiClass implsClass = interfaceClass.findInnerClassByName(JvmAbi.DEFAULT_IMPLS_CLASS_NAME, false);
|
||||
if (implsClass != null) {
|
||||
@@ -224,7 +226,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
||||
|
||||
Collection<KtClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
||||
for (KtClassOrObject declaration : declarations) {
|
||||
PsiClass aClass = LightClassUtil.INSTANCE.getPsiClass(declaration);
|
||||
PsiClass aClass = toLightClass(declaration);
|
||||
if (aClass != null) {
|
||||
answer.add(aClass);
|
||||
}
|
||||
|
||||
+2
-2
@@ -116,12 +116,12 @@ open class KtLightClassForExplicitDeclaration(
|
||||
val grandparent = parent.parent
|
||||
|
||||
if (parent is KtClassBody && grandparent is KtClassOrObject) {
|
||||
return LightClassUtil.getPsiClass(grandparent)
|
||||
return grandparent.toLightClass()
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration is KtClass) {
|
||||
return LightClassUtil.getPsiClass(declaration)
|
||||
return declaration.toLightClass()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -48,12 +48,6 @@ object LightClassUtil {
|
||||
return null
|
||||
}/*package*/
|
||||
|
||||
fun getPsiClass(classOrObject: KtClassOrObject?): KtLightClass? {
|
||||
return classOrObject?.let {
|
||||
return LightClassGenerationSupport.getInstance(it.project).getLightClass(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun getLightClassAccessorMethod(accessor: KtPropertyAccessor): PsiMethod? =
|
||||
getLightClassAccessorMethods(accessor).firstOrNull()
|
||||
|
||||
@@ -94,7 +88,7 @@ object LightClassUtil {
|
||||
if (origin is KtObjectDeclaration && origin.isCompanion()) {
|
||||
val containingClass = PsiTreeUtil.getParentOfType(origin, KtClass::class.java)
|
||||
if (containingClass != null) {
|
||||
val containingLightClass = getPsiClass(containingClass)
|
||||
val containingLightClass = containingClass.toLightClass()
|
||||
if (containingLightClass != null) {
|
||||
psiClass = containingLightClass
|
||||
}
|
||||
@@ -156,7 +150,7 @@ object LightClassUtil {
|
||||
if (declaration is KtParameter) {
|
||||
val constructorClass = KtPsiUtil.getClassIfParameterIsProperty(declaration)
|
||||
if (constructorClass != null) {
|
||||
return getPsiClass(constructorClass)
|
||||
return constructorClass.toLightClass()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +159,7 @@ object LightClassUtil {
|
||||
}
|
||||
|
||||
if (declaration is KtConstructor<*>) {
|
||||
return getPsiClass(declaration.getContainingClassOrObject())
|
||||
return declaration.getContainingClassOrObject().toLightClass()
|
||||
}
|
||||
|
||||
if (!canGenerateLightClass(declaration)) {
|
||||
@@ -184,7 +178,7 @@ object LightClassUtil {
|
||||
}
|
||||
else if (parent is KtClassBody) {
|
||||
assert(parent.parent is KtClassOrObject)
|
||||
return getPsiClass(parent.parent as KtClassOrObject)
|
||||
return (parent.parent as KtClassOrObject).toLightClass()
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
fun KtClassOrObject.toLightClass(): KtLightClass? = LightClassUtil.getPsiClass(this)
|
||||
fun KtClassOrObject.toLightClass(): KtLightClass? = LightClassGenerationSupport.getInstance(project).getLightClass(this)
|
||||
|
||||
fun KtFile.findFacadeClass(): KtLightClass? {
|
||||
return LightClassGenerationSupport.getInstance(project)
|
||||
@@ -38,7 +38,7 @@ fun KtFile.findFacadeClass(): KtLightClass? {
|
||||
|
||||
fun KtDeclaration.toLightElements(): List<PsiNamedElement> =
|
||||
when (this) {
|
||||
is KtClassOrObject -> LightClassUtil.getPsiClass(this).singletonOrEmptyList()
|
||||
is KtClassOrObject -> toLightClass().singletonOrEmptyList()
|
||||
is KtNamedFunction,
|
||||
is KtSecondaryConstructor -> LightClassUtil.getLightClassMethods(this as KtFunction)
|
||||
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||
@@ -59,7 +59,7 @@ fun PsiElement.toLightMethods(): List<PsiMethod> =
|
||||
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||
is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||
is KtPropertyAccessor -> LightClassUtil.getLightClassAccessorMethods(this)
|
||||
is KtClass -> LightClassUtil.getPsiClass(this)?.getConstructors()?.first().singletonOrEmptyList()
|
||||
is KtClass -> toLightClass()?.getConstructors()?.first().singletonOrEmptyList()
|
||||
is PsiMethod -> this.singletonList()
|
||||
else -> listOf()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user