mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Provide more valuable intention class name in FUS
#KTIJ-389 Fixed GitOrigin-RevId: 78962bfab92e848047cc1cba45097f573b639e74
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f428648590
commit
a2b07c9418
@@ -60,10 +60,7 @@ public final class IntentionFUSCollector extends CounterUsagesCollector {
|
||||
}
|
||||
}
|
||||
LocalQuickFix quickFix = QuickFixWrapper.unwrap(action);
|
||||
if (quickFix != null) {
|
||||
return quickFix.getClass();
|
||||
}
|
||||
return action.getClass();
|
||||
return ReportingClassSubstitutor.getClassToReport(quickFix != null ? quickFix : action);
|
||||
}
|
||||
|
||||
public static void reportShownIntentions(@NotNull Project project,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.internal.statistic;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* ReportingClassSubstitutor is suitable in cases when reporting (e.g. FUS)
|
||||
* has to be performed on behalf of another class.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public interface ReportingClassSubstitutor {
|
||||
@NotNull Class<?> getSubstitutedClass();
|
||||
|
||||
static @NotNull Class<?> getClassToReport(@NotNull Object object) {
|
||||
return object instanceof ReportingClassSubstitutor substitutor ? substitutor.getSubstitutedClass() : object.getClass();
|
||||
}
|
||||
}
|
||||
@@ -38,5 +38,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
|
||||
<orderEntry type="module" module-name="kotlin.base.statistics" />
|
||||
<orderEntry type="module" module-name="kotlin.base.project-structure" />
|
||||
<orderEntry type="module" module-name="intellij.platform.statistics" />
|
||||
</component>
|
||||
</module>
|
||||
+3
@@ -39,6 +39,8 @@ abstract class AbstractKotlinApplicableInspection<ELEMENT : KtElement>(
|
||||
if (!isApplicable) return null
|
||||
|
||||
val elementPointer = element.createSmartPointer()
|
||||
val inspectionClass = javaClass
|
||||
|
||||
val quickFix = object : AbstractKotlinApplicableInspectionQuickFix<ELEMENT>() {
|
||||
override fun applyTo(element: ELEMENT) {
|
||||
apply(element, element.project, element.findExistingEditor())
|
||||
@@ -47,6 +49,7 @@ abstract class AbstractKotlinApplicableInspection<ELEMENT : KtElement>(
|
||||
override fun shouldApplyInWriteAction(): Boolean = this@AbstractKotlinApplicableInspection.shouldApplyInWriteAction()
|
||||
override fun getFamilyName(): String = this@AbstractKotlinApplicableInspection.getActionFamilyName()
|
||||
override fun getName(): String = elementPointer.element?.let { getActionName(it) } ?: familyName
|
||||
override fun getSubstitutedClass(): Class<*> = inspectionClass
|
||||
}
|
||||
|
||||
val description = getProblemDescription(element)
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.codeInspection.util.InspectionMessage
|
||||
import com.intellij.codeInspection.util.IntentionFamilyName
|
||||
import com.intellij.internal.statistic.ReportingClassSubstitutor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiFile
|
||||
@@ -71,7 +72,7 @@ abstract class AbstractKotlinApplicableInspectionBase<ELEMENT : KtElement>(
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class AbstractKotlinApplicableInspectionQuickFix<ELEMENT : KtElement> : LocalQuickFix {
|
||||
internal abstract class AbstractKotlinApplicableInspectionQuickFix<ELEMENT : KtElement> : LocalQuickFix, ReportingClassSubstitutor {
|
||||
abstract fun applyTo(element: ELEMENT)
|
||||
|
||||
abstract fun shouldApplyInWriteAction(): Boolean
|
||||
|
||||
+2
@@ -40,6 +40,7 @@ abstract class AbstractKotlinApplicableInspectionWithContext<ELEMENT : KtElement
|
||||
val context = prepareContextWithAnalyze(element) ?: return null
|
||||
|
||||
val elementPointer = element.createSmartPointer()
|
||||
val inspectionWithContextClass = javaClass
|
||||
val quickFix = object : AbstractKotlinApplicableInspectionQuickFix<ELEMENT>() {
|
||||
override fun applyTo(element: ELEMENT) {
|
||||
apply(element, context, element.project, element.findExistingEditor())
|
||||
@@ -48,6 +49,7 @@ abstract class AbstractKotlinApplicableInspectionWithContext<ELEMENT : KtElement
|
||||
override fun shouldApplyInWriteAction(): Boolean = this@AbstractKotlinApplicableInspectionWithContext.shouldApplyInWriteAction()
|
||||
override fun getFamilyName(): String = this@AbstractKotlinApplicableInspectionWithContext.getActionFamilyName()
|
||||
override fun getName(): String = elementPointer.element?.let { getActionName(it, context) } ?: familyName
|
||||
override fun getSubstitutedClass(): Class<*> = inspectionWithContextClass
|
||||
}
|
||||
|
||||
val description = getProblemDescription(element, context)
|
||||
|
||||
+4
-1
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.intention.FileModifier
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.codeInspection.util.InspectionMessage
|
||||
import com.intellij.codeInspection.util.IntentionName
|
||||
import com.intellij.internal.statistic.ReportingClassSubstitutor
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
@@ -62,7 +63,7 @@ abstract class AbstractApplicabilityBasedInspection<TElement : KtElement>(
|
||||
private class LocalFix<TElement : KtElement>(
|
||||
@FileModifier.SafeFieldForPreview val inspection: AbstractApplicabilityBasedInspection<TElement>,
|
||||
@IntentionName val text: String
|
||||
) : LocalQuickFix {
|
||||
) : LocalQuickFix, ReportingClassSubstitutor {
|
||||
override fun startInWriteAction() = inspection.startFixInWriteAction
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
@@ -74,5 +75,7 @@ abstract class AbstractApplicabilityBasedInspection<TElement : KtElement>(
|
||||
override fun getFamilyName() = inspection.defaultFixText
|
||||
|
||||
override fun getName() = text
|
||||
|
||||
override fun getSubstitutedClass(): Class<*> = inspection.javaClass
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -5,11 +5,11 @@ package org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections
|
||||
import com.intellij.codeInsight.intention.FileModifier
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInsight.intention.IntentionActionDelegate
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.codeInspection.util.InspectionMessage
|
||||
import com.intellij.internal.statistic.ReportingClassSubstitutor
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
@@ -140,11 +140,11 @@ abstract class IntentionBasedInspection<TElement : PsiElement> private construct
|
||||
val intention: SelfTargetingRangeIntention<TElement>,
|
||||
private val additionalChecker: (TElement, IntentionBasedInspection<TElement>) -> Boolean,
|
||||
targetElement: TElement
|
||||
) : LocalQuickFixOnPsiElement(targetElement), IntentionAction, IntentionActionDelegate {
|
||||
) : LocalQuickFixOnPsiElement(targetElement), IntentionAction, ReportingClassSubstitutor {
|
||||
|
||||
private val text = intention.text
|
||||
|
||||
override fun getDelegate(): IntentionAction = intention
|
||||
override fun getSubstitutedClass(): Class<*> = intention.javaClass
|
||||
|
||||
// store text into variable because intention instance is shared and may change its text later
|
||||
override fun getFamilyName() = intention.familyName
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.codeInsight.intention.*
|
||||
import com.intellij.internal.statistic.ReportingClassSubstitutor
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
@@ -11,7 +12,7 @@ import org.jetbrains.annotations.Nls
|
||||
|
||||
open class QuickFixWithDelegateFactory(
|
||||
delegateFactory: () -> IntentionAction?
|
||||
) : IntentionAction, IntentionActionDelegate {
|
||||
) : IntentionAction, ReportingClassSubstitutor {
|
||||
@Nls
|
||||
private val familyName: String
|
||||
@Nls
|
||||
@@ -26,7 +27,7 @@ open class QuickFixWithDelegateFactory(
|
||||
startInWriteAction = delegate != null && delegate.startInWriteAction()
|
||||
}
|
||||
|
||||
override fun getDelegate(): IntentionAction = delegate ?: EmptyIntentionAction("")
|
||||
override fun getSubstitutedClass(): Class<*> = delegate?.javaClass ?: javaClass
|
||||
|
||||
override fun getFamilyName() = familyName
|
||||
|
||||
|
||||
Reference in New Issue
Block a user