cleanup (inspection "Java | Class structure | Utility class is not 'final'")
[idea/community.git] / platform / lang-impl / src / com / intellij / ide / actions / searcheverywhere / statistics / SearchEverywhereUsageTriggerCollector.java
1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.ide.actions.searcheverywhere.statistics;
3
4 import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributor;
5 import com.intellij.internal.statistic.eventLog.FeatureUsageData;
6 import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;
7 import com.intellij.internal.statistic.utils.PluginInfo;
8 import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
9 import com.intellij.openapi.project.Project;
10 import org.jetbrains.annotations.NotNull;
11 import org.jetbrains.annotations.Nullable;
12
13 public final class SearchEverywhereUsageTriggerCollector {
14
15   // this string will be used as ID for contributors from private
16   // plugins that mustn't be sent in statistics
17   private static final String NOT_REPORTABLE_CONTRIBUTOR_ID = "third.party";
18
19   public static final String DIALOG_OPEN = "dialogOpen";
20   public static final String DIALOG_CLOSED = "dialogClosed";
21   public static final String TAB_SWITCHED = "tabSwitched";
22   public static final String GROUP_NAVIGATE = "navigateThroughGroups";
23   public static final String CONTRIBUTOR_ITEM_SELECTED = "contributorItemChosen";
24   public static final String MORE_ITEM_SELECTED = "moreItemChosen";
25   public static final String COMMAND_USED = "commandUsed";
26   public static final String COMMAND_COMPLETED = "commandCompleted";
27   public static final String SESSION_FINISHED = "sessionFinished";
28
29   public static final String CONTRIBUTOR_ID_FIELD = "contributorID";
30   public static final String CURRENT_TAB_FIELD = "currentTabId";
31   public static final String SELECTED_ITEM_NUMBER = "selectedItemNumber";
32   public static final String TYPED_SYMBOL_KEYS = "typedSymbolKeys";
33   public static final String TYPED_NAVIGATION_KEYS = "typedNavigationKeys";
34
35   public static void trigger(@Nullable Project project, @NotNull String feature) {
36     trigger(project, feature, new FeatureUsageData());
37   }
38
39   public static void trigger(@Nullable Project project, @NotNull String feature, @NotNull FeatureUsageData data) {
40     FUCounterUsageLogger.getInstance().logEvent(project, "searchEverywhere", feature, data);
41   }
42
43   @NotNull
44   public static FeatureUsageData createData(@Nullable String contributorID) {
45     FeatureUsageData res = new FeatureUsageData();
46     if (contributorID != null) {
47       res.addData(CONTRIBUTOR_ID_FIELD, contributorID);
48     }
49
50     return res;
51   }
52
53   public static FeatureUsageData createData(@Nullable String contributorID, @Nullable String currentTab, int itemNumber) {
54     FeatureUsageData res = createData(contributorID);
55
56     if (currentTab != null) {
57       res.addData(CURRENT_TAB_FIELD, currentTab);
58     }
59
60     res.addData(SELECTED_ITEM_NUMBER, itemNumber);
61
62     return res;
63   }
64
65   @NotNull
66   public static String getReportableContributorID(@NotNull SearchEverywhereContributor<?> contributor) {
67     Class<? extends SearchEverywhereContributor> clazz = contributor.getClass();
68     PluginInfo pluginInfo = PluginInfoDetectorKt.getPluginInfo(clazz);
69     return pluginInfo.isDevelopedByJetBrains() ? contributor.getSearchProviderId() : NOT_REPORTABLE_CONTRIBUTOR_ID;
70   }
71 }