Minor: refactoring
This commit is contained in:
+7
-6
@@ -40,9 +40,12 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.findDocComment.findDocComment
|
import org.jetbrains.kotlin.psi.findDocComment.findDocComment
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||||
import org.jetbrains.kotlin.renderer.*
|
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer.Companion.withOptions
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer.Companion.withOptions
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier.*
|
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier.*
|
||||||
|
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||||
|
import org.jetbrains.kotlin.renderer.render
|
||||||
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
|
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.setSingleOverridden
|
import org.jetbrains.kotlin.resolve.descriptorUtil.setSingleOverridden
|
||||||
import org.jetbrains.kotlin.util.findCallableMemberBySignature
|
import org.jetbrains.kotlin.util.findCallableMemberBySignature
|
||||||
@@ -189,8 +192,7 @@ fun OverrideMemberChooserObject.generateMember(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (copyDoc) {
|
if (copyDoc) {
|
||||||
val superDeclaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor)?.navigationElement
|
val kDoc = when (val superDeclaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor)?.navigationElement) {
|
||||||
val kDoc = when (superDeclaration) {
|
|
||||||
is KtDeclaration ->
|
is KtDeclaration ->
|
||||||
findDocComment(superDeclaration)
|
findDocComment(superDeclaration)
|
||||||
is PsiDocCommentOwner -> {
|
is PsiDocCommentOwner -> {
|
||||||
@@ -348,8 +350,7 @@ fun generateUnsupportedOrSuperCall(
|
|||||||
bodyType: OverrideMemberChooserObject.BodyType,
|
bodyType: OverrideMemberChooserObject.BodyType,
|
||||||
canBeEmpty: Boolean = true
|
canBeEmpty: Boolean = true
|
||||||
): String {
|
): String {
|
||||||
val effectiveBodyType = if (!canBeEmpty && bodyType == EMPTY_OR_TEMPLATE) FROM_TEMPLATE else bodyType
|
when (if (!canBeEmpty && bodyType == EMPTY_OR_TEMPLATE) FROM_TEMPLATE else bodyType) {
|
||||||
when (effectiveBodyType) {
|
|
||||||
EMPTY_OR_TEMPLATE -> return ""
|
EMPTY_OR_TEMPLATE -> return ""
|
||||||
FROM_TEMPLATE -> {
|
FROM_TEMPLATE -> {
|
||||||
val templateKind = if (descriptor is FunctionDescriptor) TemplateKind.FUNCTION else TemplateKind.PROPERTY_INITIALIZER
|
val templateKind = if (descriptor is FunctionDescriptor) TemplateKind.FUNCTION else TemplateKind.PROPERTY_INITIALIZER
|
||||||
@@ -362,7 +363,7 @@ fun generateUnsupportedOrSuperCall(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> return buildString {
|
else -> return buildString {
|
||||||
if (bodyType is OverrideMemberChooserObject.BodyType.Delegate) {
|
if (bodyType is Delegate) {
|
||||||
append(bodyType.receiverName)
|
append(bodyType.receiverName)
|
||||||
} else {
|
} else {
|
||||||
append("super")
|
append("super")
|
||||||
|
|||||||
+20
-21
@@ -38,9 +38,13 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
|||||||
import javax.swing.Icon
|
import javax.swing.Icon
|
||||||
|
|
||||||
open class DescriptorMemberChooserObject(
|
open class DescriptorMemberChooserObject(
|
||||||
psiElement: PsiElement,
|
psiElement: PsiElement,
|
||||||
open val descriptor: DeclarationDescriptor
|
open val descriptor: DeclarationDescriptor
|
||||||
) : PsiElementMemberChooserObject(psiElement, DescriptorMemberChooserObject.getText(descriptor), DescriptorMemberChooserObject.getIcon(psiElement, descriptor)), ClassMemberWithElement {
|
) : PsiElementMemberChooserObject(
|
||||||
|
psiElement,
|
||||||
|
getText(descriptor),
|
||||||
|
getIcon(psiElement, descriptor)
|
||||||
|
), ClassMemberWithElement {
|
||||||
|
|
||||||
override fun getParentNodeDelegate(): MemberChooserObject {
|
override fun getParentNodeDelegate(): MemberChooserObject {
|
||||||
val parent = descriptor.containingDeclaration ?: error("No parent for $descriptor")
|
val parent = descriptor.containingDeclaration ?: error("No parent for $descriptor")
|
||||||
@@ -48,8 +52,7 @@ open class DescriptorMemberChooserObject(
|
|||||||
val declaration = if (psiElement is KtDeclaration) { // kotlin
|
val declaration = if (psiElement is KtDeclaration) { // kotlin
|
||||||
PsiTreeUtil.getStubOrPsiParentOfType(psiElement, KtNamedDeclaration::class.java)
|
PsiTreeUtil.getStubOrPsiParentOfType(psiElement, KtNamedDeclaration::class.java)
|
||||||
?: PsiTreeUtil.getStubOrPsiParentOfType(psiElement, KtFile::class.java)
|
?: PsiTreeUtil.getStubOrPsiParentOfType(psiElement, KtFile::class.java)
|
||||||
}
|
} else { // java or compiled
|
||||||
else { // java or compiled
|
|
||||||
(psiElement as PsiMember).containingClass
|
(psiElement as PsiMember).containingClass
|
||||||
} ?: error("No parent for $psiElement")
|
} ?: error("No parent for $psiElement")
|
||||||
|
|
||||||
@@ -80,23 +83,19 @@ open class DescriptorMemberChooserObject(
|
|||||||
MEMBER_RENDERER.render(descriptor)
|
MEMBER_RENDERER.render(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIcon(declaration: PsiElement?, descriptor: DeclarationDescriptor): Icon? {
|
fun getIcon(declaration: PsiElement?, descriptor: DeclarationDescriptor): Icon? = if (declaration != null && declaration.isValid) {
|
||||||
if (declaration != null && declaration.isValid) {
|
val isClass = declaration is PsiClass || declaration is KtClass
|
||||||
val isClass = declaration is PsiClass || declaration is KtClass
|
val flags = if (isClass) 0 else Iconable.ICON_FLAG_VISIBILITY
|
||||||
val flags = if (isClass) 0 else Iconable.ICON_FLAG_VISIBILITY
|
if (declaration is KtDeclaration) {
|
||||||
return if (declaration is KtDeclaration) {
|
// kotlin declaration
|
||||||
// kotlin declaration
|
// visibility and abstraction better detect by a descriptor
|
||||||
// visibility and abstraction better detect by a descriptor
|
KotlinDescriptorIconProvider.getIcon(descriptor, declaration, flags)
|
||||||
KotlinDescriptorIconProvider.getIcon(descriptor, declaration, flags)
|
} else {
|
||||||
}
|
// it is better to show java icons for java code
|
||||||
else {
|
declaration.getIcon(flags)
|
||||||
// it is better to show java icons for java code
|
|
||||||
declaration.getIcon(flags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return KotlinDescriptorIconProvider.getIcon(descriptor, declaration, 0)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
KotlinDescriptorIconProvider.getIcon(descriptor, declaration, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user