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? =
|
fun getLightClassAccessorMethod(accessor: KtPropertyAccessor): PsiMethod? =
|
||||||
getLightClassAccessorMethods(accessor).firstOrNull()
|
getLightClassAccessorMethods(accessor).firstOrNull()
|
||||||
|
|
||||||
fun getLightClassAccessorMethods(accessor: KtPropertyAccessor): List<PsiMethod> {
|
fun getLightClassAccessorMethods(accessor: KtPropertyAccessor): List<PsiMethod> {
|
||||||
val property = accessor.getNonStrictParentOfType<KtProperty>() ?: return emptyList()
|
val property = accessor.getNonStrictParentOfType<KtProperty>() ?: return emptyList()
|
||||||
val wrappers = getPsiMethodWrappers(property)
|
val wrappers = getPsiMethodWrappers(property)
|
||||||
return wrappers.filter { wrapper ->
|
return wrappers.filter { wrapper ->
|
||||||
(accessor.isGetter && !JvmAbi.isSetterName(wrapper.name)) ||
|
(accessor.isGetter && !JvmAbi.isSetterName(wrapper.name)) ||
|
||||||
(accessor.isSetter && JvmAbi.isSetterName(wrapper.name))
|
(accessor.isSetter && JvmAbi.isSetterName(wrapper.name))
|
||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,11 +170,11 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getWrappingClasses(declaration: KtDeclaration): Sequence<PsiClass> {
|
private fun getWrappingClasses(declaration: KtDeclaration): Sequence<PsiClass> {
|
||||||
@@ -192,8 +192,9 @@ 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 }
|
||||||
|
|
||||||
@@ -202,21 +203,22 @@ object LightClassUtil {
|
|||||||
val backingField = getLightClassBackingField(ktDeclaration)
|
val backingField = getLightClassBackingField(ktDeclaration)
|
||||||
val additionalAccessors = allGetters.drop(1) + allSetters.drop(1)
|
val additionalAccessors = allGetters.drop(1) + allSetters.drop(1)
|
||||||
return PropertyAccessorsPsiMethods(
|
return PropertyAccessorsPsiMethods(
|
||||||
allGetters.firstOrNull(),
|
allGetters.firstOrNull(),
|
||||||
allSetters.firstOrNull(),
|
allSetters.firstOrNull(),
|
||||||
backingField,
|
backingField,
|
||||||
additionalAccessors
|
additionalAccessors
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 setter: PsiMethod?,
|
val getter: PsiMethod?,
|
||||||
val backingField: PsiField?,
|
val setter: PsiMethod?,
|
||||||
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> {
|
val backingField: PsiField?,
|
||||||
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user