Reformat file

Relates to #KT-40960
This commit is contained in:
Vladimir Dolzhenko
2020-08-10 15:46:00 +02:00
committed by Vladimir Dolzhenko
parent 5c7054a5ab
commit ee0250bd35
@@ -170,9 +170,9 @@ object LightClassUtil {
private fun findFileFacade(ktFile: KtFile): PsiClass? { private fun findFileFacade(ktFile: KtFile): PsiClass? {
val fqName = ktFile.javaFileFacadeFqName val fqName = ktFile.javaFileFacadeFqName
val project = ktFile.project val project = ktFile.project
val classesWithMatchingFqName = JavaElementFinder.getInstance(project).findClasses(fqName.asString(), GlobalSearchScope.allScope(project)) val classesWithMatchingFqName =
return classesWithMatchingFqName.singleOrNull() ?: JavaElementFinder.getInstance(project).findClasses(fqName.asString(), GlobalSearchScope.allScope(project))
classesWithMatchingFqName.find { return classesWithMatchingFqName.singleOrNull() ?: classesWithMatchingFqName.find {
it.containingFile?.virtualFile == ktFile.virtualFile it.containingFile?.virtualFile == ktFile.virtualFile
} }
} }
@@ -193,7 +193,8 @@ object LightClassUtil {
private fun extractPropertyAccessors( private fun extractPropertyAccessors(
ktDeclaration: KtDeclaration, ktDeclaration: KtDeclaration,
specialGetter: PsiMethod?, specialSetter: PsiMethod?): PropertyAccessorsPsiMethods { specialGetter: PsiMethod?, specialSetter: PsiMethod?
): PropertyAccessorsPsiMethods {
val (setters, getters) = getPsiMethodWrappers(ktDeclaration).partition { it.isSetter } val (setters, getters) = getPsiMethodWrappers(ktDeclaration).partition { it.isSetter }
@@ -211,12 +212,13 @@ object LightClassUtil {
fun buildLightTypeParameterList( fun buildLightTypeParameterList(
owner: PsiTypeParameterListOwner, owner: PsiTypeParameterListOwner,
declaration: KtDeclaration): PsiTypeParameterList { declaration: KtDeclaration
): PsiTypeParameterList {
val builder = KotlinLightTypeParameterListBuilder(owner) val builder = KotlinLightTypeParameterListBuilder(owner)
if (declaration is KtTypeParameterListOwner) { if (declaration is KtTypeParameterListOwner) {
val parameters = declaration.typeParameters val parameters = declaration.typeParameters
for (i in parameters.indices) { for (i in parameters.indices) {
val jetTypeParameter = parameters.get(i) val jetTypeParameter = parameters[i]
val name = jetTypeParameter.name val name = jetTypeParameter.name
val safeName = name ?: "__no_name__" val safeName = name ?: "__no_name__"
builder.addParameter(KtLightTypeParameter(owner, i, safeName)) builder.addParameter(KtLightTypeParameter(owner, i, safeName))
@@ -225,19 +227,21 @@ object LightClassUtil {
return builder return builder
} }
class PropertyAccessorsPsiMethods(val getter: PsiMethod?, class PropertyAccessorsPsiMethods(
val getter: PsiMethod?,
val setter: PsiMethod?, val setter: PsiMethod?,
val backingField: PsiField?, val backingField: PsiField?,
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> { additionalAccessors: List<PsiMethod>
) : Iterable<PsiMethod> {
private val allMethods: List<PsiMethod> private val allMethods: List<PsiMethod>
val allDeclarations: List<PsiNamedElement> val allDeclarations: List<PsiNamedElement>
init { init {
allMethods = arrayListOf<PsiMethod>() allMethods = arrayListOf()
arrayOf(getter, setter).filterNotNullTo(allMethods) arrayOf(getter, setter).filterNotNullTo(allMethods)
additionalAccessors.filterIsInstanceTo<PsiMethod, MutableList<PsiMethod>>(allMethods) additionalAccessors.filterIsInstanceTo<PsiMethod, MutableList<PsiMethod>>(allMethods)
allDeclarations = arrayListOf<PsiNamedElement>() allDeclarations = arrayListOf()
arrayOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations) arrayOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
allDeclarations.addAll(additionalAccessors) allDeclarations.addAll(additionalAccessors)
} }
@@ -250,6 +254,6 @@ fun KtNamedDeclaration.getAccessorLightMethods(): LightClassUtil.PropertyAccesso
return when (this) { return when (this) {
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this) is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this)
is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this) is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this)
else -> throw IllegalStateException("Unexpected property type: ${this}") else -> throw IllegalStateException("Unexpected property type: $this")
} }
} }