Reformat file
Relates to #KT-40960
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
5c7054a5ab
commit
ee0250bd35
@@ -48,14 +48,14 @@ object LightClassUtil {
|
||||
}
|
||||
|
||||
fun getLightClassAccessorMethod(accessor: KtPropertyAccessor): PsiMethod? =
|
||||
getLightClassAccessorMethods(accessor).firstOrNull()
|
||||
getLightClassAccessorMethods(accessor).firstOrNull()
|
||||
|
||||
fun getLightClassAccessorMethods(accessor: KtPropertyAccessor): List<PsiMethod> {
|
||||
val property = accessor.getNonStrictParentOfType<KtProperty>() ?: return emptyList()
|
||||
val wrappers = getPsiMethodWrappers(property)
|
||||
return wrappers.filter { wrapper ->
|
||||
(accessor.isGetter && !JvmAbi.isSetterName(wrapper.name)) ||
|
||||
(accessor.isSetter && JvmAbi.isSetterName(wrapper.name))
|
||||
(accessor.isSetter && JvmAbi.isSetterName(wrapper.name))
|
||||
}.toList()
|
||||
}
|
||||
|
||||
@@ -170,11 +170,11 @@ object LightClassUtil {
|
||||
private fun findFileFacade(ktFile: KtFile): PsiClass? {
|
||||
val fqName = ktFile.javaFileFacadeFqName
|
||||
val project = ktFile.project
|
||||
val classesWithMatchingFqName = JavaElementFinder.getInstance(project).findClasses(fqName.asString(), GlobalSearchScope.allScope(project))
|
||||
return classesWithMatchingFqName.singleOrNull() ?:
|
||||
classesWithMatchingFqName.find {
|
||||
it.containingFile?.virtualFile == ktFile.virtualFile
|
||||
}
|
||||
val classesWithMatchingFqName =
|
||||
JavaElementFinder.getInstance(project).findClasses(fqName.asString(), GlobalSearchScope.allScope(project))
|
||||
return classesWithMatchingFqName.singleOrNull() ?: classesWithMatchingFqName.find {
|
||||
it.containingFile?.virtualFile == ktFile.virtualFile
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWrappingClasses(declaration: KtDeclaration): Sequence<PsiClass> {
|
||||
@@ -192,8 +192,9 @@ object LightClassUtil {
|
||||
}
|
||||
|
||||
private fun extractPropertyAccessors(
|
||||
ktDeclaration: KtDeclaration,
|
||||
specialGetter: PsiMethod?, specialSetter: PsiMethod?): PropertyAccessorsPsiMethods {
|
||||
ktDeclaration: KtDeclaration,
|
||||
specialGetter: PsiMethod?, specialSetter: PsiMethod?
|
||||
): PropertyAccessorsPsiMethods {
|
||||
|
||||
val (setters, getters) = getPsiMethodWrappers(ktDeclaration).partition { it.isSetter }
|
||||
|
||||
@@ -202,21 +203,22 @@ object LightClassUtil {
|
||||
val backingField = getLightClassBackingField(ktDeclaration)
|
||||
val additionalAccessors = allGetters.drop(1) + allSetters.drop(1)
|
||||
return PropertyAccessorsPsiMethods(
|
||||
allGetters.firstOrNull(),
|
||||
allSetters.firstOrNull(),
|
||||
backingField,
|
||||
additionalAccessors
|
||||
allGetters.firstOrNull(),
|
||||
allSetters.firstOrNull(),
|
||||
backingField,
|
||||
additionalAccessors
|
||||
)
|
||||
}
|
||||
|
||||
fun buildLightTypeParameterList(
|
||||
owner: PsiTypeParameterListOwner,
|
||||
declaration: KtDeclaration): PsiTypeParameterList {
|
||||
owner: PsiTypeParameterListOwner,
|
||||
declaration: KtDeclaration
|
||||
): PsiTypeParameterList {
|
||||
val builder = KotlinLightTypeParameterListBuilder(owner)
|
||||
if (declaration is KtTypeParameterListOwner) {
|
||||
val parameters = declaration.typeParameters
|
||||
for (i in parameters.indices) {
|
||||
val jetTypeParameter = parameters.get(i)
|
||||
val jetTypeParameter = parameters[i]
|
||||
val name = jetTypeParameter.name
|
||||
val safeName = name ?: "__no_name__"
|
||||
builder.addParameter(KtLightTypeParameter(owner, i, safeName))
|
||||
@@ -225,19 +227,21 @@ object LightClassUtil {
|
||||
return builder
|
||||
}
|
||||
|
||||
class PropertyAccessorsPsiMethods(val getter: PsiMethod?,
|
||||
val setter: PsiMethod?,
|
||||
val backingField: PsiField?,
|
||||
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> {
|
||||
class PropertyAccessorsPsiMethods(
|
||||
val getter: PsiMethod?,
|
||||
val setter: PsiMethod?,
|
||||
val backingField: PsiField?,
|
||||
additionalAccessors: List<PsiMethod>
|
||||
) : Iterable<PsiMethod> {
|
||||
private val allMethods: List<PsiMethod>
|
||||
val allDeclarations: List<PsiNamedElement>
|
||||
|
||||
init {
|
||||
allMethods = arrayListOf<PsiMethod>()
|
||||
allMethods = arrayListOf()
|
||||
arrayOf(getter, setter).filterNotNullTo(allMethods)
|
||||
additionalAccessors.filterIsInstanceTo<PsiMethod, MutableList<PsiMethod>>(allMethods)
|
||||
|
||||
allDeclarations = arrayListOf<PsiNamedElement>()
|
||||
allDeclarations = arrayListOf()
|
||||
arrayOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
|
||||
allDeclarations.addAll(additionalAccessors)
|
||||
}
|
||||
@@ -250,6 +254,6 @@ fun KtNamedDeclaration.getAccessorLightMethods(): LightClassUtil.PropertyAccesso
|
||||
return when (this) {
|
||||
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this)
|
||||
is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this)
|
||||
else -> throw IllegalStateException("Unexpected property type: ${this}")
|
||||
else -> throw IllegalStateException("Unexpected property type: $this")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user