|
67 | 67 | import com.intellij.openapi.wm.IdeFocusManager;
|
68 | 68 | import com.intellij.psi.PsiDocumentManager;
|
69 | 69 | import com.intellij.psi.PsiElement;
|
| 70 | +import com.intellij.psi.PsiJavaCodeReferenceElement; |
| 71 | +import com.intellij.psi.PsiMethod; |
70 | 72 | import com.intellij.psi.search.GlobalSearchScope;
|
71 | 73 | import com.intellij.psi.search.ProjectScope;
|
72 | 74 | import com.intellij.psi.search.PsiElementProcessor;
|
|
80 | 82 | import com.intellij.ui.TableUtil;
|
81 | 83 | import com.intellij.ui.awt.RelativePoint;
|
82 | 84 | import com.intellij.ui.popup.AbstractPopup;
|
| 85 | +import com.intellij.usageView.UsageInfo; |
83 | 86 | import com.intellij.usageView.UsageViewBundle;
|
84 | 87 | import com.intellij.usages.PsiElementUsageTarget;
|
85 | 88 | import com.intellij.usages.Usage;
|
|
110 | 113 | import org.jetbrains.annotations.NonNls;
|
111 | 114 | import org.jetbrains.annotations.NotNull;
|
112 | 115 | import org.jetbrains.annotations.Nullable;
|
| 116 | +import org.jetbrains.kotlin.psi.KtNameReferenceExpression; |
| 117 | +import org.jetbrains.kotlin.psi.KtNamedFunction; |
113 | 118 |
|
114 | 119 | import java.awt.BorderLayout;
|
115 | 120 | import java.awt.Component;
|
@@ -148,6 +153,11 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
148 | 153 | private static final int USAGES_PAGE_SIZE = 100;
|
149 | 154 |
|
150 | 155 | private Filter filter;
|
| 156 | + //0 search receiver; 1 search post |
| 157 | + private int type; |
| 158 | + |
| 159 | + public static final int TYPE_RECEIVER = 0; |
| 160 | + public static final int TYPE_POST = 1; |
151 | 161 |
|
152 | 162 | public final static NullUsage MORE_USAGES_SEPARATOR = NullUsage.INSTANCE;
|
153 | 163 | private static final UsageNode MORE_USAGES_SEPARATOR_NODE = UsageViewImpl.NULL_NODE;
|
@@ -193,8 +203,9 @@ public ShowUsagesAction() {
|
193 | 203 | myUsageViewSettings.GROUP_BY_SCOPE = false;
|
194 | 204 | }
|
195 | 205 |
|
196 |
| - public ShowUsagesAction(Filter filter) { |
| 206 | + public ShowUsagesAction(Filter filter, int type) { |
197 | 207 | this.filter = filter;
|
| 208 | + this.type = type; |
198 | 209 | setInjectedContext(true);
|
199 | 210 |
|
200 | 211 | final UsageViewSettings usageViewSettings = UsageViewSettings.getInstance();
|
@@ -465,8 +476,22 @@ private void useHandler(@NotNull final FindUsagesHandler handler,
|
465 | 476 | Disposer.register(popup, indicator::cancel);
|
466 | 477 | }
|
467 | 478 |
|
468 |
| - protected @Nullable |
469 |
| - Usage transform(@NotNull Usage usage) { |
| 479 | + /** |
| 480 | + * 转换usage 显示行 |
| 481 | + * 当使用@Subscribe 进行搜索时,显示列不是函数所在行,需要转换至函数Usage |
| 482 | + */ |
| 483 | + @SuppressWarnings("ConstantConditions") |
| 484 | + private Usage transform(@NotNull Usage usage) { |
| 485 | + if (type == TYPE_RECEIVER) { |
| 486 | + PsiElement ele = ((UsageInfo2UsageAdapter) usage).getElement(); |
| 487 | + if (ele instanceof PsiJavaCodeReferenceElement) { |
| 488 | + PsiElement method = ((PsiMethod) ele.getContext().getContext().getContext()).getIdentifyingElement(); |
| 489 | + return new UsageInfo2UsageAdapter(new UsageInfo(method)); |
| 490 | + } else if (ele instanceof KtNameReferenceExpression) { |
| 491 | + PsiElement method = ((KtNamedFunction) ele.getParent().getParent().getParent().getParent().getParent().getParent()).getNameIdentifier(); |
| 492 | + return new UsageInfo2UsageAdapter(new UsageInfo(method)); |
| 493 | + } |
| 494 | + } |
470 | 495 | return usage;
|
471 | 496 | }
|
472 | 497 |
|
|
0 commit comments