More usable rendering of usage context in Analyze Data Flow to/from Here
This commit is contained in:
@@ -10,20 +10,25 @@ import com.intellij.slicer.SliceUsageCellRendererBase
|
|||||||
import com.intellij.ui.JBColor
|
import com.intellij.ui.JBColor
|
||||||
import com.intellij.ui.SimpleTextAttributes
|
import com.intellij.ui.SimpleTextAttributes
|
||||||
import com.intellij.util.FontUtil
|
import com.intellij.util.FontUtil
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||||
|
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||||
|
|
||||||
// Based on com.intellij.slicer.SliceUsageCellRenderer
|
// Based on com.intellij.slicer.SliceUsageCellRenderer
|
||||||
object KotlinSliceUsageCellRenderer : SliceUsageCellRendererBase() {
|
object KotlinSliceUsageCellRenderer : SliceUsageCellRendererBase() {
|
||||||
private val descriptorRenderer = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.withOptions {
|
private val descriptorRenderer = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.withOptions {
|
||||||
withDefinedIn = true
|
withoutReturnType = true
|
||||||
withoutTypeParameters = true
|
renderConstructorKeyword = false
|
||||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
|
||||||
includeAdditionalModifiers = false
|
|
||||||
withoutSuperTypes = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun customizeCellRendererFor(sliceUsage: SliceUsage) {
|
override fun customizeCellRendererFor(sliceUsage: SliceUsage) {
|
||||||
@@ -45,9 +50,25 @@ object KotlinSliceUsageCellRenderer : SliceUsageCellRendererBase() {
|
|||||||
append(" (Tracking enclosing lambda)".repeat(sliceUsage.lambdaLevel), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
|
append(" (Tracking enclosing lambda)".repeat(sliceUsage.lambdaLevel), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
|
||||||
|
|
||||||
val declaration = sliceUsage.element?.parents?.firstOrNull {
|
val declaration = sliceUsage.element?.parents?.firstOrNull {
|
||||||
it is KtClass || it is KtObjectDeclaration && !it.isObjectLiteral() || it is KtDeclarationWithBody || it is KtProperty && it.isLocal
|
it is KtClass ||
|
||||||
|
it is KtObjectDeclaration && !it.isObjectLiteral() ||
|
||||||
|
it is KtNamedFunction && !it.isLocal ||
|
||||||
|
it is KtProperty && !it.isLocal ||
|
||||||
|
it is KtConstructor<*>
|
||||||
} as? KtDeclaration ?: return
|
} as? KtDeclaration ?: return
|
||||||
|
|
||||||
|
append(" in ", SimpleTextAttributes.GRAY_ATTRIBUTES)
|
||||||
|
|
||||||
val descriptor = declaration.unsafeResolveToDescriptor()
|
val descriptor = declaration.unsafeResolveToDescriptor()
|
||||||
append(" in ${descriptorRenderer.render(descriptor)}", SimpleTextAttributes.GRAY_ATTRIBUTES)
|
|
||||||
|
if (!descriptor.isExtension && descriptor !is ConstructorDescriptor && !descriptor.isCompanionObject()) {
|
||||||
|
val containingClassifier = descriptor.containingDeclaration as? ClassifierDescriptor
|
||||||
|
if (containingClassifier != null) {
|
||||||
|
append(descriptorRenderer.render(containingClassifier), SimpleTextAttributes.GRAY_ATTRIBUTES)
|
||||||
|
append(".", SimpleTextAttributes.GRAY_ATTRIBUTES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
append(descriptorRenderer.render(descriptor), SimpleTextAttributes.GRAY_ATTRIBUTES)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user