mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
IDEA-231364 Implement Find Usages tool window and dialog design updates
GitOrigin-RevId: 59d518299fe2c38886c80cd7187bf7c26a602a81
This commit is contained in:
committed by
intellij-monorepo-bot
parent
37e61ab8ef
commit
d46c2468fe
@@ -19,6 +19,7 @@ public class JavaMethodFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
public boolean isIncludeInherited;
|
||||
public boolean isIncludeOverloadUsages;
|
||||
public boolean isImplicitToString = true;
|
||||
public boolean isSearchForBaseMethod;
|
||||
|
||||
public JavaMethodFindUsagesOptions(@NotNull Project project) {
|
||||
super(project);
|
||||
@@ -41,6 +42,7 @@ public class JavaMethodFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
isIncludeInherited = properties.getBoolean(prefix + "isIncludeInherited");
|
||||
isIncludeOverloadUsages = properties.getBoolean(prefix + "isIncludeOverloadUsages");
|
||||
isImplicitToString = properties.getBoolean(prefix + "isImplicitToString", true);
|
||||
isSearchForBaseMethod = properties.getBoolean(prefix + "isSearchForBaseMethod", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,6 +56,7 @@ public class JavaMethodFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
properties.setValue(prefix + "isIncludeInherited", isIncludeInherited);
|
||||
properties.setValue(prefix + "isIncludeOverloadUsages", isIncludeOverloadUsages);
|
||||
properties.setValue(prefix + "isImplicitToString", isImplicitToString, true);
|
||||
properties.setValue(prefix + "isSearchForBaseMethod", isSearchForBaseMethod);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
@@ -69,6 +72,7 @@ public class JavaMethodFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
if (isIncludeOverloadUsages != that.isIncludeOverloadUsages) return false;
|
||||
if (isOverridingMethods != that.isOverridingMethods) return false;
|
||||
if (isImplicitToString != that.isImplicitToString) return false;
|
||||
if (isSearchForBaseMethod != that.isSearchForBaseMethod) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -81,6 +85,7 @@ public class JavaMethodFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
result = 31 * result + (isIncludeInherited ? 1 : 0);
|
||||
result = 31 * result + (isIncludeOverloadUsages ? 1 : 0);
|
||||
result = 31 * result + (isImplicitToString ? 1 : 0);
|
||||
result = 31 * result + (isSearchForBaseMethod ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JavaVariableFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
public boolean isReadAccess = true;
|
||||
public boolean isWriteAccess = true;
|
||||
public boolean isSearchForAccessors;
|
||||
public boolean isSearchInOverridingMethods;
|
||||
public boolean isSearchForBaseAccessors;
|
||||
|
||||
public JavaVariableFindUsagesOptions(@NotNull Project project) {
|
||||
super(project);
|
||||
@@ -44,6 +47,9 @@ public class JavaVariableFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
isUsages = properties.getBoolean(prefix + "isUsages", true);
|
||||
isReadAccess = properties.getBoolean(prefix + "isReadAccess", true);
|
||||
isWriteAccess = properties.getBoolean(prefix + "isWriteAccess", true);
|
||||
isSearchForAccessors = properties.getBoolean(prefix + "isSearchForAccessors", false);
|
||||
isSearchInOverridingMethods = properties.getBoolean(prefix + "isSearchInOverridingMethods", false);
|
||||
isSearchForBaseAccessors = properties.getBoolean(prefix + "isSearchForBaseAccessors", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,6 +59,9 @@ public class JavaVariableFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
properties.setValue(prefix + "isUsages", isUsages, true);
|
||||
properties.setValue(prefix + "isReadAccess", isReadAccess, true);
|
||||
properties.setValue(prefix + "isWriteAccess", isWriteAccess, true);
|
||||
properties.setValue(prefix + "isSearchForAccessors", isSearchForAccessors, false);
|
||||
properties.setValue(prefix + "isSearchInOverridingMethods", isSearchInOverridingMethods, false);
|
||||
properties.setValue(prefix + "isSearchForBaseAccessors", isSearchForBaseAccessors, false);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
@@ -64,6 +73,9 @@ public class JavaVariableFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
|
||||
if (isReadAccess != that.isReadAccess) return false;
|
||||
if (isWriteAccess != that.isWriteAccess) return false;
|
||||
if (isSearchForAccessors != that.isSearchForAccessors) return false;
|
||||
if (isSearchInOverridingMethods != that.isSearchInOverridingMethods) return false;
|
||||
if (isSearchForBaseAccessors != that.isSearchForBaseAccessors) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -72,7 +84,9 @@ public class JavaVariableFindUsagesOptions extends JavaFindUsagesOptions {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (isReadAccess ? 1 : 0);
|
||||
result = 31 * result + (isWriteAccess ? 1 : 0);
|
||||
result = 31 * result + (isSearchForAccessors ? 1 : 0);
|
||||
result = 31 * result + (isSearchInOverridingMethods ? 1 : 0);
|
||||
result = 31 * result + (isSearchForBaseAccessors ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -89,8 +88,6 @@ public class FindClassUsagesDialog extends JavaFindUsagesDialog<JavaClassFindUsa
|
||||
@Override
|
||||
protected JPanel createFindWhatPanel() {
|
||||
JPanel findWhatPanel = new JPanel();
|
||||
|
||||
findWhatPanel.setBorder(IdeBorderFactory.createTitledBorder(JavaBundle.message("find.what.group")));
|
||||
findWhatPanel.setLayout(new BoxLayout(findWhatPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
myCbUsages = addCheckboxToPanel(JavaBundle.message("find.what.usages.checkbox"), getFindUsagesOptions().isUsages, findWhatPanel, true);
|
||||
|
||||
@@ -5,24 +5,25 @@ import com.intellij.internal.statistic.eventLog.FeatureUsageData;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.panel.ComponentPanelBuilder;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ImplicitToStringSearch;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindUsagesOptions> {
|
||||
private StateRestoringCheckBox myCbSearchForBase;
|
||||
private StateRestoringCheckBox myCbUsages;
|
||||
private StateRestoringCheckBox myCbImplementingMethods;
|
||||
private StateRestoringCheckBox myCbOverridingMethods;
|
||||
private StateRestoringCheckBox myCbImplicitToString;
|
||||
private boolean myHasFindWhatPanel;
|
||||
|
||||
public FindMethodUsagesDialog(PsiElement element, Project project, FindUsagesOptions findUsagesOptions, boolean toShowInNewTab, boolean mustOpenInNewTab,
|
||||
boolean isSingleFile,
|
||||
FindUsagesHandler handler) {
|
||||
public FindMethodUsagesDialog(PsiElement element, Project project, FindUsagesOptions findUsagesOptions,
|
||||
boolean toShowInNewTab, boolean mustOpenInNewTab, boolean isSingleFile, FindUsagesHandler handler) {
|
||||
super(element, project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, handler);
|
||||
}
|
||||
|
||||
@@ -37,6 +38,9 @@ public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindU
|
||||
super.calcFindUsagesOptions(options);
|
||||
|
||||
options.isUsages = isSelected(myCbUsages) || !myHasFindWhatPanel;
|
||||
if (isToChange(myCbSearchForBase)) {
|
||||
options.isSearchForBaseMethod = isSelected(myCbSearchForBase);
|
||||
}
|
||||
if (isToChange(myCbOverridingMethods)) {
|
||||
options.isOverridingMethods = isSelected(myCbOverridingMethods);
|
||||
}
|
||||
@@ -53,6 +57,7 @@ public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindU
|
||||
@Override
|
||||
protected FeatureUsageData createFeatureUsageData(JavaMethodFindUsagesOptions options) {
|
||||
FeatureUsageData data = super.createFeatureUsageData(options);
|
||||
data.addData("searchForBaseMethods", options.isSearchForBaseMethod);
|
||||
data.addData("overridingMethods", options.isOverridingMethods);
|
||||
data.addData("implementingMethods", options.isImplementingMethods);
|
||||
data.addData("includeInherited", options.isIncludeInherited);
|
||||
@@ -64,7 +69,6 @@ public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindU
|
||||
@Override
|
||||
protected JPanel createFindWhatPanel() {
|
||||
JPanel findWhatPanel = new JPanel();
|
||||
findWhatPanel.setBorder(IdeBorderFactory.createTitledBorder(JavaBundle.message("find.what.group")));
|
||||
findWhatPanel.setLayout(new BoxLayout(findWhatPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
myCbUsages = addCheckboxToPanel(JavaBundle.message("find.what.usages.checkbox"), getFindUsagesOptions().isUsages, findWhatPanel, true);
|
||||
@@ -82,39 +86,29 @@ public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindU
|
||||
return null;
|
||||
}
|
||||
|
||||
myCbSearchForBase = createCheckbox(JavaBundle.message("find.what.search.for.base.methods.checkbox"),
|
||||
getFindUsagesOptions().isSearchForBaseMethod, true);
|
||||
|
||||
JComponent decoratedCheckbox = new ComponentPanelBuilder(myCbSearchForBase).
|
||||
withComment(JavaBundle.message("find.what.search.for.base.methods.checkbox.comment")).createPanel();
|
||||
decoratedCheckbox.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
findWhatPanel.add(decoratedCheckbox);
|
||||
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
myCbImplementingMethods =
|
||||
addCheckboxToPanel(JavaBundle.message("find.what.implementing.methods.checkbox"), getFindUsagesOptions().isImplementingMethods,
|
||||
findWhatPanel, true);
|
||||
myCbImplementingMethods = addCheckboxToPanel(JavaBundle.message("find.what.implementing.methods.checkbox"),
|
||||
getFindUsagesOptions().isImplementingMethods, findWhatPanel, true);
|
||||
}
|
||||
else {
|
||||
myCbOverridingMethods =
|
||||
addCheckboxToPanel(JavaBundle.message("find.what.overriding.methods.checkbox"), getFindUsagesOptions().isOverridingMethods,
|
||||
findWhatPanel, true);
|
||||
myCbOverridingMethods = addCheckboxToPanel(JavaBundle.message("find.what.overriding.methods.checkbox"),
|
||||
getFindUsagesOptions().isOverridingMethods, findWhatPanel, true);
|
||||
}
|
||||
if (ImplicitToStringSearch.isToStringMethod(method)) {
|
||||
myCbImplicitToString =
|
||||
addCheckboxToPanel(JavaBundle.message("find.what.implicit.to.string.checkbox"), getFindUsagesOptions().isImplicitToString,
|
||||
findWhatPanel, true);
|
||||
myCbImplicitToString = addCheckboxToPanel(JavaBundle.message("find.what.implicit.to.string.checkbox"),
|
||||
getFindUsagesOptions().isImplicitToString, findWhatPanel, true);
|
||||
}
|
||||
|
||||
myHasFindWhatPanel = true;
|
||||
return findWhatPanel;
|
||||
|
||||
/*if (method.isConstructor() ||
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
method.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
method.hasModifierProperty(PsiModifier.PRIVATE) ||
|
||||
aClass == null ||
|
||||
aClass instanceof PsiAnonymousClass ||
|
||||
aClass.hasModifierProperty(PsiModifier.FINAL)){
|
||||
myHasFindWhatPanel = false;
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
myHasFindWhatPanel = true;
|
||||
return findWhatPanel;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,6 +117,7 @@ public class FindMethodUsagesDialog extends JavaFindUsagesDialog<JavaMethodFindU
|
||||
setOKActionEnabled(true);
|
||||
} else {
|
||||
boolean hasSelected = isSelected(myCbUsages) ||
|
||||
isSelected(myCbSearchForBase) ||
|
||||
isSelected(myCbImplementingMethods) ||
|
||||
isSelected(myCbOverridingMethods) ||
|
||||
isSelected(myCbImplicitToString);
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogg
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -65,7 +64,6 @@ public class FindPackageUsagesDialog extends JavaFindUsagesDialog<JavaPackageFin
|
||||
@Override
|
||||
protected JPanel createFindWhatPanel() {
|
||||
JPanel findWhatPanel = new JPanel();
|
||||
findWhatPanel.setBorder(IdeBorderFactory.createTitledBorder(JavaBundle.message("find.what.group")));
|
||||
findWhatPanel.setLayout(new BoxLayout(findWhatPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
myCbUsages = addCheckboxToPanel(JavaBundle.message("find.what.usages.checkbox"), getFindUsagesOptions().isUsages, findWhatPanel, true);
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.search.ThrowSearchUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -82,11 +81,10 @@ public class FindThrowUsagesDialog extends JavaFindUsagesDialog<JavaThrowFindUsa
|
||||
|
||||
@Override
|
||||
protected JPanel createFindWhatPanel() {
|
||||
final JPanel findWhatPanel = new JPanel();
|
||||
findWhatPanel.setBorder(IdeBorderFactory.createTitledBorder(JavaBundle.message("find.what.group")));
|
||||
JPanel findWhatPanel = new JPanel();
|
||||
findWhatPanel.setLayout(new BoxLayout(findWhatPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
myCbUsages = addCheckboxToPanel(JavaBundle.message("find.what.usages.checkbox") , myFindUsagesOptions.isUsages, findWhatPanel, true);
|
||||
myCbUsages = addCheckboxToPanel(JavaBundle.message("find.what.usages.checkbox"), myFindUsagesOptions.isUsages, findWhatPanel, true);
|
||||
//final ThrowSearchUtil.Root[] searchRoots = ThrowSearchUtil.getSearchRoots(getPsiElement ());
|
||||
|
||||
//final PsiThrowStatement throwStatement = (PsiThrowStatement)getPsiElement();
|
||||
|
||||
@@ -17,16 +17,25 @@ package com.intellij.find.findUsages;
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.FeatureUsageData;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.panel.ComponentPanelBuilder;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FindVariableUsagesDialog extends JavaFindUsagesDialog<JavaVariableFindUsagesOptions> {
|
||||
private StateRestoringCheckBox myCbSearchForAccessors;
|
||||
private StateRestoringCheckBox myCbSearchForBase;
|
||||
private StateRestoringCheckBox myCbSearchInOverridingMethods;
|
||||
|
||||
public FindVariableUsagesDialog(PsiElement element, Project project, FindUsagesOptions findUsagesOptions,
|
||||
boolean toShowInNewTab, boolean mustOpenInNewTab, boolean isSingleFile, FindUsagesHandler handler){
|
||||
boolean toShowInNewTab, boolean mustOpenInNewTab, boolean isSingleFile,
|
||||
FindUsagesHandler handler) {
|
||||
super(element, project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, handler);
|
||||
}
|
||||
|
||||
@@ -41,20 +50,59 @@ public class FindVariableUsagesDialog extends JavaFindUsagesDialog<JavaVariableF
|
||||
|
||||
options.isReadAccess = true;
|
||||
options.isWriteAccess = true;
|
||||
|
||||
if (isToChange(myCbSearchForAccessors)) {
|
||||
options.isSearchForAccessors = isSelected(myCbSearchForAccessors);
|
||||
}
|
||||
if (isToChange(myCbSearchInOverridingMethods)) {
|
||||
options.isSearchInOverridingMethods = isSelected(myCbSearchInOverridingMethods);
|
||||
}
|
||||
if (isToChange(myCbSearchForBase)) {
|
||||
options.isSearchForBaseAccessors = isSelected(myCbSearchForBase);
|
||||
}
|
||||
|
||||
FUCounterUsageLogger.getInstance().logEvent(myPsiElement.getProject(), EVENT_LOG_GROUP, "find.variable.started", createFeatureUsageData(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FeatureUsageData createFeatureUsageData(JavaVariableFindUsagesOptions options) {
|
||||
FeatureUsageData data = super.createFeatureUsageData(options);
|
||||
data.addData("searchForBaseAccessors", options.isSearchForBaseAccessors);
|
||||
data.addData("searchForAccessors", options.isSearchForAccessors);
|
||||
data.addData("searchInOverriding", options.isSearchInOverridingMethods);
|
||||
data.addData("readAccess", options.isReadAccess);
|
||||
data.addData("writeAccess", options.isWriteAccess);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JPanel createAllOptionsPanel() {
|
||||
return getPsiElement() instanceof PsiField ? super.createAllOptionsPanel() : createUsagesOptionsPanel();
|
||||
protected JPanel createFindWhatPanel() {
|
||||
JPanel findWhatPanel = new JPanel();
|
||||
findWhatPanel.setLayout(new BoxLayout(findWhatPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
PsiElement element = getPsiElement();
|
||||
if (element instanceof PsiField) {
|
||||
myCbSearchForAccessors = addCheckboxToPanel(JavaBundle.message("find.options.include.accessors.checkbox"),
|
||||
getFindUsagesOptions().isSearchForAccessors, findWhatPanel, true);
|
||||
|
||||
PsiField field = (PsiField)element;
|
||||
JavaFindUsagesHandler handler = (JavaFindUsagesHandler)myUsagesHandler;
|
||||
if (!handler.getFieldAccessors(field).isEmpty()) {
|
||||
myCbSearchForBase = createCheckbox(JavaBundle.message("find.options.include.accessors.base.checkbox"),
|
||||
getFindUsagesOptions().isSearchForBaseAccessors, true);
|
||||
JComponent decoratedCheckbox = new ComponentPanelBuilder(myCbSearchForBase).
|
||||
withComment(JavaBundle.message("find.options.include.accessors.base.checkbox.comment")).createPanel();
|
||||
decoratedCheckbox.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
findWhatPanel.add(decoratedCheckbox);
|
||||
}
|
||||
}
|
||||
|
||||
if (element instanceof PsiParameter) {
|
||||
myCbSearchInOverridingMethods = addCheckboxToPanel(JavaBundle.message("find.options.search.overriding.methods.checkbox"),
|
||||
getFindUsagesOptions().isSearchInOverridingMethods, findWhatPanel, true);
|
||||
}
|
||||
|
||||
return findWhatPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2021 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.
|
||||
package com.intellij.find.findUsages;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.find.FindBundle;
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.java.JavaBundle;
|
||||
@@ -10,7 +9,6 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
@@ -38,7 +36,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
public class JavaFindUsagesHandler extends FindUsagesHandler {
|
||||
private static final Logger LOG = Logger.getInstance(JavaFindUsagesHandler.class);
|
||||
|
||||
private final PsiElement[] myElementsToSearch;
|
||||
@@ -76,14 +74,6 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
return super.getFindUsagesDialog(isSingleFile, toShowInNewTab, mustOpenInNewTab);
|
||||
}
|
||||
|
||||
private static boolean askWhetherShouldSearchForParameterInOverridingMethods(@NotNull PsiElement psiElement, @NotNull PsiParameter parameter) {
|
||||
return Messages.showOkCancelDialog(psiElement.getProject(),
|
||||
JavaBundle.message("find.parameter.usages.in.overriding.methods.prompt", parameter.getName()),
|
||||
JavaBundle.message("find.parameter.usages.in.overriding.methods.title"),
|
||||
CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText(),
|
||||
Messages.getQuestionIcon()) == Messages.OK;
|
||||
}
|
||||
|
||||
private static PsiElement @NotNull [] getParameterElementsToSearch(@NotNull PsiParameter parameter, @NotNull PsiMethod method) {
|
||||
PsiMethod[] overrides = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
|
||||
for (int i = 0; i < overrides.length; i++) {
|
||||
@@ -130,16 +120,21 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
LOG.assertTrue(aClass != null); //Otherwise can not be overridden
|
||||
|
||||
Boolean hasOverridden = ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
|
||||
return OverridingMethodsSearch.search(method).findFirst() != null ||
|
||||
FunctionalExpressionSearch.search(aClass).findFirst() != null;
|
||||
}, JavaBundle.message("progress.title.detect.overridden.methods"), true, getProject());
|
||||
if (hasOverridden != null && hasOverridden.booleanValue() && askWhetherShouldSearchForParameterInOverridingMethods(element, parameter)) {
|
||||
return ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> getParameterElementsToSearch(parameter, method), JavaBundle.message("progress.title.detect.overridden.methods"), true, getProject()) ;
|
||||
ProgressManager pm = ProgressManager.getInstance();
|
||||
boolean hasOverriden = pm.runProcessWithProgressSynchronously(() ->
|
||||
OverridingMethodsSearch.search(method).findFirst() != null || FunctionalExpressionSearch.search(aClass).findFirst() != null,
|
||||
JavaBundle.message("progress.title.detect.overridden.methods"), true, getProject()) == Boolean.TRUE;
|
||||
|
||||
if (hasOverriden && myFactory.getFindVariableOptions().isSearchInOverridingMethods) {
|
||||
return pm.runProcessWithProgressSynchronously(() -> getParameterElementsToSearch(parameter, method),
|
||||
JavaBundle.message("progress.title.detect.overridden.methods"), true, getProject());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiMethod && myFactory.getFindMethodOptions().isSearchForBaseMethod) {
|
||||
return SuperMethodWarningUtil.getTargetMethodCandidates((PsiMethod)element, Collections.emptyList());
|
||||
}
|
||||
return myElementsToSearch.length == 0 ? new PsiElement[]{element} : myElementsToSearch;
|
||||
}
|
||||
|
||||
@@ -148,42 +143,40 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
PsiElement element = getPsiElement();
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY;
|
||||
if (element instanceof PsiField) {
|
||||
final PsiField field = (PsiField)element;
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
String fieldName = field.getName();
|
||||
final String propertyName = JavaCodeStyleManager.getInstance(getProject()).variableNameToPropertyName(fieldName, VariableKind.FIELD);
|
||||
Set<PsiMethod> accessors = new HashSet<>();
|
||||
boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
|
||||
Collection<PsiMethod> methods = Arrays.asList(containingClass.getMethods());
|
||||
PsiMethod getter = PropertyUtilBase.findPropertyGetterWithType(propertyName, isStatic, field.getType(), methods);
|
||||
if (getter != null) accessors.add(getter);
|
||||
PsiMethod setter = PropertyUtilBase.findPropertySetterWithType(propertyName, isStatic, field.getType(), methods);
|
||||
if (setter != null) accessors.add(setter);
|
||||
accessors.addAll(PropertyUtilBase.getAccessors(containingClass, fieldName));
|
||||
accessors.removeIf(accessor -> field != PropertyUtilBase.findPropertyFieldByMember(accessor));
|
||||
if (!accessors.isEmpty()) {
|
||||
boolean containsPhysical = ContainerUtil.find(accessors, psiMethod -> psiMethod.isPhysical()) != null;
|
||||
final boolean doSearch = !containsPhysical || askShouldSearchAccessors(fieldName);
|
||||
if (doSearch) {
|
||||
final Set<PsiElement> elements = new HashSet<>();
|
||||
Set<PsiMethod> accessors = getFieldAccessors((PsiField)element);
|
||||
if (!accessors.isEmpty()) {
|
||||
boolean containsPhysical = ContainerUtil.find(accessors, psiMethod -> psiMethod.isPhysical()) != null;
|
||||
boolean doSearch = !containsPhysical || myFactory.getFindVariableOptions().isSearchForAccessors;
|
||||
if (doSearch) {
|
||||
Set<PsiElement> elements = new HashSet<>();
|
||||
if (myFactory.getFindVariableOptions().isSearchForBaseAccessors) {
|
||||
for (PsiMethod accessor : accessors) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(accessor, getActionString()));
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.getTargetMethodCandidates(accessor, Collections.emptyList()));
|
||||
}
|
||||
return PsiUtilCore.toPsiElementArray(elements);
|
||||
}
|
||||
return PsiUtilCore.toPsiElementArray(elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getSecondaryElements();
|
||||
}
|
||||
|
||||
public static boolean askShouldSearchAccessors(@NotNull String fieldName) {
|
||||
int ret = Messages.showOkCancelDialog(JavaBundle.message("find.field.accessors.prompt", fieldName),
|
||||
JavaBundle.message("find.field.accessors.title"),
|
||||
JavaBundle.message("include.accessors"),
|
||||
JavaBundle.message("exclude.accessors"), Messages.getQuestionIcon());
|
||||
return ret == Messages.OK;
|
||||
Set<PsiMethod> getFieldAccessors(PsiField field) {
|
||||
Set<PsiMethod> accessors = new HashSet<>();
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
String fieldName = field.getName();
|
||||
final String propertyName = JavaCodeStyleManager.getInstance(getProject()).variableNameToPropertyName(fieldName, VariableKind.FIELD);
|
||||
boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
|
||||
Collection<PsiMethod> methods = Arrays.asList(containingClass.getMethods());
|
||||
PsiMethod getter = PropertyUtilBase.findPropertyGetterWithType(propertyName, isStatic, field.getType(), methods);
|
||||
if (getter != null) accessors.add(getter);
|
||||
PsiMethod setter = PropertyUtilBase.findPropertySetterWithType(propertyName, isStatic, field.getType(), methods);
|
||||
if (setter != null) accessors.add(setter);
|
||||
accessors.addAll(PropertyUtilBase.getAccessors(containingClass, fieldName));
|
||||
accessors.removeIf(accessor -> field != PropertyUtilBase.findPropertyFieldByMember(accessor));
|
||||
}
|
||||
return accessors;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
// Copyright 2000-2018 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.
|
||||
package com.intellij.find.findUsages;
|
||||
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.lang.java.JavaFindUsagesProvider;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -41,31 +40,10 @@ public class JavaFindUsagesHandlerFactory extends FindUsagesHandlerFactory {
|
||||
@Override
|
||||
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, @NotNull OperationMode operationMode) {
|
||||
if (element instanceof PsiDirectory) {
|
||||
final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
|
||||
PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
|
||||
return psiPackage == null ? null : new JavaFindUsagesHandler(psiPackage, this);
|
||||
}
|
||||
|
||||
if (element instanceof PsiMethod && operationMode != OperationMode.HIGHLIGHT_USAGES) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
final PsiMethod[] methods;
|
||||
|
||||
if (operationMode == OperationMode.USAGES_WITH_DEFAULT_OPTIONS &&
|
||||
Registry.is("java.find.usages.always.use.top.hierarchy.methods")) {
|
||||
methods = SuperMethodWarningUtil.getTargetMethodCandidates(method, Collections.emptyList());
|
||||
}
|
||||
else {
|
||||
methods = SuperMethodWarningUtil.checkSuperMethods(method, JavaFindUsagesHandler.getActionString());
|
||||
}
|
||||
|
||||
if (methods.length > 1) {
|
||||
return new JavaFindUsagesHandler(element, methods, this);
|
||||
}
|
||||
if (methods.length == 1) {
|
||||
return new JavaFindUsagesHandler(methods[0], this);
|
||||
}
|
||||
return FindUsagesHandler.NULL_HANDLER;
|
||||
}
|
||||
|
||||
return new JavaFindUsagesHandler(element, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@ public class JavaUsageViewDescriptionProvider implements ElementDescriptionProvi
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
PsiMethod psiMethod = (PsiMethod)element;
|
||||
return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY,
|
||||
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
|
||||
return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
annotation.name.is.missing=Annotation attribute must be of the form 'name=value'
|
||||
anonymous.class.context.display=Anonymous in {0}
|
||||
anonymous.class.derived.display=Anonymous class derived from {0}
|
||||
aux.context.display=(in {0})
|
||||
aux.context.display=of {0}
|
||||
bound.not.expected=Unexpected bound
|
||||
catch.without.try='catch' without 'try'
|
||||
class.context.display={0} in {1}
|
||||
|
||||
@@ -248,13 +248,21 @@ external.annotations.suggestion.message=<html><body>If you do not want annotatio
|
||||
To configure external annotations please specify root directory where files with annotations would be placed</body></html>
|
||||
find.field.accessors.prompt=Search for accessors of field ''{0}''?
|
||||
find.field.accessors.title=Field Accessors Found
|
||||
find.options.include.overloaded.methods.checkbox=Include o&verloaded methods
|
||||
find.options.include.overloaded.methods.checkbox=O&verloaded methods
|
||||
find.options.include.accessors.checkbox=Search for &accessors
|
||||
find.options.include.accessors.base.checkbox=S&earch for base methods of accessors
|
||||
find.options.include.accessors.base.checkbox.comment=Use top level hierarchy methods as find usage targets by default
|
||||
find.options.search.overriding.methods.checkbox=Search in &overriding methods
|
||||
#Deprecated
|
||||
find.parameter.usages.in.overriding.methods.prompt=Do you want to search usages of parameter ''{0}'' in overriding methods?
|
||||
find.parameter.usages.in.overriding.methods.title=Search in Overriding Methods
|
||||
find.what.group=Find
|
||||
#End deprecated
|
||||
find.what.derived.classes.checkbox=&Derived classes
|
||||
find.what.derived.interfaces.checkbox=&Derived interfaces
|
||||
find.what.fields.usages.checkbox=Usages of &fields
|
||||
find.what.group=Find
|
||||
find.what.search.for.base.methods.checkbox=S&earch for base method usages
|
||||
find.what.search.for.base.methods.checkbox.comment=Use top level hierarchy methods as find usage targets by default
|
||||
find.what.implementing.classes.checkbox=&Implementing classes
|
||||
find.what.implementing.methods.checkbox=&Implementing methods
|
||||
find.what.implicit.to.string.checkbox=I&mplicit calls
|
||||
|
||||
@@ -8,7 +8,7 @@ find.search.again.from.bottom.action.message={0}, perform \"Find Previous\" agai
|
||||
select.next.occurence.not.found.message=Not found, try again to search from top
|
||||
|
||||
find.no.usages.at.cursor.error=Cannot search for usages. \nPosition to an element to find usages for, and try again.
|
||||
find.what.group=Find
|
||||
find.what.group=Find:
|
||||
find.what.usages.checkbox=&Usages
|
||||
find.dialog.find.button=Find
|
||||
find.popup.find.button=Open in Find Window
|
||||
@@ -20,13 +20,14 @@ find.usages.progress.title=Find usages
|
||||
find.open.in.new.tab.checkbox=Open results in new ta&b
|
||||
find.open.in.new.tab.action=Open Results in New Ta&b
|
||||
find.options.group=General
|
||||
find.options.search.for.text.occurrences.checkbox=Search for text &occurrences
|
||||
find.options.search.for.text.occurrences.checkbox=Text &occurrences
|
||||
find.options.skip.results.tab.with.one.usage.checkbox=S&kip results tab with one usage
|
||||
find.scope.label=&Scope
|
||||
find.options.skip.results.tab.with.one.usage.action=S&kip Results Tab with One Usage
|
||||
find.scope.label=&Scope:
|
||||
find.searched.elements.have.been.changed.error=Searched elements have been changed.\nCannot search for usages.
|
||||
cannot.search.for.usages.title=Cannot Search for Usages
|
||||
find.super.method.warning.action.verb=to find usages of
|
||||
find.usages.of.element.in.scope.panel.title={0} of {1} in {2}
|
||||
find.usages.of.element.in.scope.panel.title={0} in {1}
|
||||
find.usages.of.element.tab.name={0} of {1}
|
||||
usages.search.title.default=Usages of ''{0}''
|
||||
recent.find.usages.action.popup={0} ''{1}'' in {2}
|
||||
|
||||
@@ -7,20 +7,24 @@ import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
|
||||
import com.intellij.internal.statistic.eventLog.FeatureUsageData;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.panel.ComponentPanelBuilder;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SeparatorFactory;
|
||||
import com.intellij.ui.RelativeFont;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.usageView.UsageViewContentManager;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.StartupUiUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
@@ -44,6 +48,7 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
protected JCheckBox myCbToSkipResultsWhenOneUsage;
|
||||
|
||||
private ScopeChooserCombo myScopeCombo;
|
||||
private int myFindOptionsCount;
|
||||
|
||||
protected AbstractFindUsagesDialog(@NotNull Project project,
|
||||
@NotNull FindUsagesOptions findUsagesOptions,
|
||||
@@ -82,13 +87,13 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
gbConstraints.insets = new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0);
|
||||
gbConstraints.insets = JBUI.insetsBottom(UIUtil.DEFAULT_VGAP);
|
||||
gbConstraints.fill = GridBagConstraints.NONE;
|
||||
gbConstraints.weightx = 1;
|
||||
gbConstraints.weighty = 1;
|
||||
gbConstraints.anchor = GridBagConstraints.WEST;
|
||||
final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
|
||||
coloredComponent.setIpad(new Insets(0,0,0,0));
|
||||
coloredComponent.setIpad(JBUI.emptyInsets());
|
||||
coloredComponent.setMyBorder(null);
|
||||
configureLabelComponent(coloredComponent);
|
||||
panel.add(coloredComponent, gbConstraints);
|
||||
@@ -102,22 +107,21 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
JPanel _panel = new JPanel(new BorderLayout());
|
||||
panel.add(_panel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
JPanel allOptionsPanel = createAllOptionsPanel();
|
||||
if (allOptionsPanel != null) {
|
||||
panel.add(allOptionsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
|
||||
JBUI.emptyInsets(), 0, 0));
|
||||
}
|
||||
|
||||
if (myIsShowInNewTabVisible) {
|
||||
myCbToOpenInNewTab = new JCheckBox(FindBundle.message("find.open.in.new.tab.checkbox"));
|
||||
myCbToOpenInNewTab.setSelected(myToShowInNewTab);
|
||||
myCbToOpenInNewTab.setEnabled(myIsShowInNewTabEnabled);
|
||||
_panel.add(myCbToOpenInNewTab, BorderLayout.EAST);
|
||||
|
||||
panel.add(myCbToOpenInNewTab, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
|
||||
JBUI.insets(15, 0, 13, 0), 0, 0));
|
||||
}
|
||||
|
||||
JPanel allOptionsPanel = createAllOptionsPanel();
|
||||
if (allOptionsPanel != null) {
|
||||
panel.add(allOptionsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -189,74 +193,70 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
protected StateRestoringCheckBox addCheckboxToPanel(@NlsContexts.Checkbox String name, boolean toSelect, JPanel panel, boolean toUpdate) {
|
||||
StateRestoringCheckBox cb = createCheckbox(name, toSelect, toUpdate);
|
||||
JComponent decoratedCheckbox = new ComponentPanelBuilder(cb).createPanel();
|
||||
decoratedCheckbox.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
decoratedCheckbox.setBorder(JBUI.Borders.emptyBottom(8));
|
||||
|
||||
panel.add(decoratedCheckbox);
|
||||
return cb;
|
||||
}
|
||||
|
||||
protected StateRestoringCheckBox createCheckbox(@NlsContexts.Checkbox String name, boolean toSelect, boolean toUpdate) {
|
||||
StateRestoringCheckBox cb = new StateRestoringCheckBox(name);
|
||||
cb.setSelected(toSelect);
|
||||
panel.add(cb);
|
||||
cb.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
if (toUpdate) {
|
||||
cb.addActionListener(___ -> update());
|
||||
}
|
||||
myFindOptionsCount++;
|
||||
return cb;
|
||||
}
|
||||
|
||||
protected JPanel createAllOptionsPanel() {
|
||||
JPanel allOptionsPanel = new JPanel();
|
||||
|
||||
JPanel findWhatPanel = createFindWhatPanel();
|
||||
JPanel usagesOptionsPanel = createUsagesOptionsPanel();
|
||||
int grids = 0;
|
||||
if (findWhatPanel != null) {
|
||||
grids++;
|
||||
}
|
||||
if (usagesOptionsPanel != null) {
|
||||
grids++;
|
||||
}
|
||||
if (grids != 0) {
|
||||
allOptionsPanel.setLayout(new GridLayout(1, grids, 8, 0));
|
||||
if (findWhatPanel != null) {
|
||||
allOptionsPanel.add(findWhatPanel);
|
||||
}
|
||||
if (usagesOptionsPanel != null) {
|
||||
allOptionsPanel.add(usagesOptionsPanel);
|
||||
addUsagesOptions(findWhatPanel);
|
||||
|
||||
if (myFindOptionsCount > 2) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(new Title(FindBundle.message("find.what.group"), JBUI.Borders.emptyBottom(8), null), BorderLayout.NORTH);
|
||||
findWhatPanel.setBorder(JBUI.Borders.emptyLeft(17));
|
||||
panel.add(findWhatPanel, BorderLayout.CENTER);
|
||||
|
||||
findWhatPanel = panel;
|
||||
}
|
||||
}
|
||||
|
||||
JComponent scopePanel = createSearchScopePanel();
|
||||
if (scopePanel != null) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(allOptionsPanel, BorderLayout.NORTH);
|
||||
if (findWhatPanel != null) {
|
||||
panel.add(findWhatPanel, BorderLayout.NORTH);
|
||||
scopePanel.setBorder(JBUI.Borders.emptyTop(9));
|
||||
}
|
||||
panel.add(scopePanel, BorderLayout.SOUTH);
|
||||
return panel;
|
||||
}
|
||||
|
||||
return allOptionsPanel;
|
||||
return findWhatPanel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract JPanel createFindWhatPanel();
|
||||
|
||||
protected void addUsagesOptions(JPanel optionsPanel) {
|
||||
protected void addUsagesOptions(JPanel panel) {
|
||||
if (mySearchForTextOccurrencesAvailable) {
|
||||
myCbToSearchForTextOccurrences = addCheckboxToPanel(FindBundle.message("find.options.search.for.text.occurrences.checkbox"),
|
||||
myFindUsagesOptions.isSearchForTextOccurrences, optionsPanel, false);
|
||||
|
||||
myFindUsagesOptions.isSearchForTextOccurrences, panel, false);
|
||||
}
|
||||
|
||||
if (myIsShowInNewTabVisible) {
|
||||
myCbToSkipResultsWhenOneUsage = addCheckboxToPanel(FindBundle.message("find.options.skip.results.tab.with.one.usage.checkbox"),
|
||||
FindSettings.getInstance().isSkipResultsWithOneUsage(), optionsPanel, false);
|
||||
|
||||
FindSettings.getInstance().isSkipResultsWithOneUsage(), panel, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected JPanel createUsagesOptionsPanel() {
|
||||
JPanel optionsPanel = new JPanel();
|
||||
optionsPanel.setBorder(IdeBorderFactory.createTitledBorder(FindBundle.message("find.options.group")));
|
||||
optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
|
||||
addUsagesOptions(optionsPanel);
|
||||
return optionsPanel.getComponents().length == 0 ? null : optionsPanel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JComponent createSearchScopePanel() {
|
||||
if (isInFileOnly()) return null;
|
||||
@@ -265,8 +265,9 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
myScopeCombo = new ScopeChooserCombo(myProject, mySearchInLibrariesAvailable, true, scope);
|
||||
Disposer.register(myDisposable, myScopeCombo);
|
||||
optionsPanel.add(myScopeCombo, BorderLayout.CENTER);
|
||||
JComponent separator = SeparatorFactory.createSeparator(FindBundle.message("find.scope.label"), myScopeCombo.getComboBox());
|
||||
optionsPanel.add(separator, BorderLayout.NORTH);
|
||||
|
||||
Title scopeTitle = new Title(FindBundle.message("find.scope.label"), JBUI.Borders.emptyBottom(4), myScopeCombo.getComboBox());
|
||||
optionsPanel.add(scopeTitle, BorderLayout.NORTH);
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
@@ -288,4 +289,47 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
data.addData("searchScope", scope.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class Title extends JPanel {
|
||||
private Title(@NlsContexts.Separator String text, @NotNull Border border, @Nullable JComponent labelFor) {
|
||||
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||||
setBorder(border);
|
||||
setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
|
||||
add(new TitleLabel(text, labelFor));
|
||||
add(Box.createVerticalGlue());
|
||||
}
|
||||
}
|
||||
|
||||
private static class TitleLabel extends JBLabel {
|
||||
private @NlsContexts.Separator String originalText;
|
||||
|
||||
private TitleLabel(@NlsContexts.Separator String text, @Nullable JComponent labelFor) {
|
||||
originalText = text;
|
||||
setLabelFor(labelFor);
|
||||
updateLabelFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
super.updateUI();
|
||||
updateLabelFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NlsContexts.Separator String getText() {
|
||||
return originalText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(@NlsContexts.Separator String text) {
|
||||
originalText = text;
|
||||
super.setText(text != null && text.startsWith("<html>") ? text : UIUtil.replaceMnemonicAmpersand(originalText));
|
||||
}
|
||||
|
||||
private void updateLabelFont() {
|
||||
Font labelFont = StartupUiUtil.getLabelFont();
|
||||
setFont(RelativeFont.NORMAL.fromResource("TitledSeparator.fontSizeOffset", 0).derive(labelFont));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.swing.*;
|
||||
public class CommonFindUsagesDialog extends AbstractFindUsagesDialog {
|
||||
@NotNull protected final PsiElement myPsiElement;
|
||||
@Nullable private final String myHelpId;
|
||||
@NotNull protected final FindUsagesHandlerBase myUsagesHandler;
|
||||
|
||||
public CommonFindUsagesDialog(@NotNull PsiElement element,
|
||||
@NotNull Project project,
|
||||
@@ -32,6 +33,7 @@ public class CommonFindUsagesDialog extends AbstractFindUsagesDialog {
|
||||
super(project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, isTextSearch(element, isSingleFile, handler),
|
||||
true);
|
||||
myPsiElement = element;
|
||||
myUsagesHandler = handler;
|
||||
String helpId = handler instanceof FindUsagesHandlerUi?
|
||||
((FindUsagesHandlerUi)handler).getHelpId(): null;
|
||||
myHelpId = ObjectUtils.chooseNotNull(helpId, HelpID.FIND_OTHER_USAGES);
|
||||
|
||||
@@ -487,7 +487,7 @@ public final class FindUsagesManager {
|
||||
String scopeString = options.searchScope.getDisplayName();
|
||||
presentation.setScopeText(scopeString);
|
||||
presentation.setSearchString(FindBundle.message("find.usages.of.element.tab.name", usagesString, longName));
|
||||
presentation.setTabText(FindBundle.message("find.usages.of.element.in.scope.panel.title", usagesString, longName, scopeString));
|
||||
presentation.setTabText(FindBundle.message("find.usages.of.element.in.scope.panel.title", longName, scopeString));
|
||||
presentation.setTabName(FindBundle.message("find.usages.of.element.tab.name", usagesString, UsageViewUtil.getShortName(psiElement)));
|
||||
presentation.setTargetsNodeText(StringUtil.capitalize(UsageViewUtil.getType(psiElement)));
|
||||
presentation.setOpenInNewTab(toOpenInNewTab);
|
||||
|
||||
@@ -230,13 +230,12 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
|
||||
int top = 8, left = 2, bottom = 0;
|
||||
|
||||
if (component instanceof JRadioButton || component instanceof JCheckBox) {
|
||||
top = 0;
|
||||
bottom = isWin10 ? 10 : isMacDefault ? 8 : 9;
|
||||
if (component instanceof JCheckBox) {
|
||||
left = UIUtil.getCheckBoxTextHorizontalOffset((JCheckBox)component); // the value returned from this method is already scaled
|
||||
|
||||
//noinspection UseDPIAwareInsets
|
||||
return new Insets(top, left, JBUIScale.scale(bottom), 0);
|
||||
return new Insets(0, left, JBUIScale.scale(bottom), 0);
|
||||
}
|
||||
else {
|
||||
left = isMacDefault ? 26 : isWin10 ? 17 : 23;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
node.targets=Targets
|
||||
node.non.code.usages=Non-code usages
|
||||
node.found.usages=Found usages
|
||||
node.found.usages=Usages
|
||||
usage.name={0, choice, 1#usage|2#usages}
|
||||
usages.title=Usages
|
||||
usages.n={0,choice, 0#no usages|1#1 usage|2#{0,number} usages} found
|
||||
@@ -121,3 +121,4 @@ usage.view.results.node.non.code=In Strings, Comments, and Text
|
||||
usage.view.results.node.dynamic=Dynamic
|
||||
# 0 - one of usage.view.results.node.* strings; 1 - text obtained from plugins, e.g. "References to be updated"
|
||||
usage.view.results.node.prefix=[{0}] {1}
|
||||
usage.view.results.node.scope={0} in {1}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class UsageViewPresentation {
|
||||
private static final Logger LOG = Logger.getInstance(UsageViewPresentation.class);
|
||||
|
||||
private @NlsContexts.TabTitle String myTabText;
|
||||
private String myScopeText = ""; // Default value. to be overwritten in most cases.
|
||||
private @NlsSafe String myScopeText = ""; // Default value. to be overwritten in most cases.
|
||||
private @NlsSafe String myUsagesString;
|
||||
private @NlsSafe String mySearchString;
|
||||
private @NlsContexts.ListItem String myTargetsNodeText = UsageViewBundle.message("node.targets");
|
||||
@@ -55,11 +55,12 @@ public class UsageViewPresentation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NlsSafe
|
||||
public String getScopeText() {
|
||||
return myScopeText;
|
||||
}
|
||||
|
||||
public void setScopeText(@NotNull String scopeText) {
|
||||
public void setScopeText(@NotNull @NlsSafe String scopeText) {
|
||||
myScopeText = scopeText;
|
||||
}
|
||||
|
||||
|
||||
@@ -998,14 +998,14 @@ public class UsageViewImpl implements UsageViewEx {
|
||||
actionsManager.createPrevOccurenceAction(myRootPanel),
|
||||
actionsManager.createNextOccurenceAction(myRootPanel),
|
||||
new Separator(),
|
||||
canShowSettings() ? new ShowSettings() : null,
|
||||
canShowSettings() ? new Separator() : null,
|
||||
group,
|
||||
filteringSubgroup,
|
||||
expandAllAction,
|
||||
collapseAllAction,
|
||||
new Separator(),
|
||||
isPreviewUsageActionEnabled() ? new PreviewUsageAction() : null,
|
||||
new Separator(),
|
||||
canShowSettings() ? new ShowSettings() : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ final class UsageViewTreeCellRenderer extends ColoredTreeCellRenderer {
|
||||
Icon tagIcon = TagManager.appendTags(element, this);
|
||||
append(group.getText(myView),
|
||||
patchAttrs(node, showAsReadOnly ? UsageTreeColors.READ_ONLY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES));
|
||||
Icon icon = node.getGroup().getIcon(expanded);
|
||||
Icon icon = group.getIcon(expanded);
|
||||
if (tagIcon != null) {
|
||||
icon = new RowIcon(tagIcon, icon);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,10 @@ class NonCodeUsageGroupingRule extends SingleParentUsageGroupingRule implements
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText(UsageView view) {
|
||||
return view == null ? UsageViewBundle.message("node.group.code.usages") : view.getPresentation().getCodeUsagesString();
|
||||
if (view == null) return UsageViewBundle.message("node.group.code.usages");
|
||||
|
||||
UsageViewPresentation presentation = view.getPresentation();
|
||||
return UsageViewBundle.message("usage.view.results.node.scope", presentation.getCodeUsagesString(), presentation.getScopeText());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -41,7 +44,10 @@ class NonCodeUsageGroupingRule extends SingleParentUsageGroupingRule implements
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText(UsageView view) {
|
||||
return view == null ? UsageViewBundle.message("node.non.code.usages") : view.getPresentation().getNonCodeUsagesString();
|
||||
if (view == null) return UsageViewBundle.message("node.non.code.usages");
|
||||
|
||||
UsageViewPresentation presentation = view.getPresentation();
|
||||
return UsageViewBundle.message("usage.view.results.node.scope", presentation.getNonCodeUsagesString(), presentation.getScopeText());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -867,7 +867,6 @@ public final class UIUtil {
|
||||
Insets i = cb.getInsets();
|
||||
|
||||
size = cb.getSize(size);
|
||||
viewRect.x = i.left;
|
||||
viewRect.y = i.top;
|
||||
viewRect.width = size.width - (i.right + viewRect.x);
|
||||
viewRect.height = size.height - (i.bottom + viewRect.y);
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAc
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,20 +52,23 @@ public final class GroovyFieldFindUsagesHandlerFactory extends JavaFindUsagesHan
|
||||
final boolean doSearch;
|
||||
if (arePhysical(getters) || arePhysical(setters)) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY;
|
||||
doSearch = askShouldSearchAccessors(field.getName());
|
||||
doSearch = getFindVariableOptions().isSearchForAccessors;
|
||||
}
|
||||
else {
|
||||
doSearch = true;
|
||||
}
|
||||
if (doSearch) {
|
||||
final List<PsiElement> elements = new ArrayList<>();
|
||||
for (PsiMethod getter : getters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(getter, getActionString()));
|
||||
if (getFindVariableOptions().isSearchForBaseAccessors) {
|
||||
for (PsiMethod getter : getters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.getTargetMethodCandidates(getter, Collections.emptyList()));
|
||||
}
|
||||
|
||||
for (PsiMethod setter : setters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.getTargetMethodCandidates(setter, Collections.emptyList()));
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiMethod setter : setters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(setter, getActionString()));
|
||||
}
|
||||
for (Iterator<PsiElement> iterator = elements.iterator(); iterator.hasNext(); ) {
|
||||
if (iterator.next() instanceof GrAccessorMethod) iterator.remove();
|
||||
}
|
||||
|
||||
@@ -16,28 +16,24 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.findUsages
|
||||
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.find.FindBundle
|
||||
import com.intellij.find.findUsages.FindUsagesHandler
|
||||
import com.intellij.find.findUsages.FindUsagesHandler.NULL_HANDLER
|
||||
import com.intellij.find.findUsages.FindUsagesHandlerFactory
|
||||
import com.intellij.find.findUsages.FindUsagesOptions
|
||||
import com.intellij.find.findUsages.JavaFindUsagesHandlerFactory
|
||||
import com.intellij.java.JavaBundle
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch
|
||||
import org.jetbrains.kotlin.idea.asJava.LightClassProvider.Companion.providedToLightMethods
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.idea.KotlinBundleIndependent
|
||||
import org.jetbrains.kotlin.idea.asJava.LightClassProvider.Companion.providedToLightMethods
|
||||
import org.jetbrains.kotlin.idea.findUsages.KotlinFindUsagesSupport.Companion.checkSuperMethods
|
||||
import org.jetbrains.kotlin.idea.search.KotlinSearchUsagesSupport.Companion.isOverridable
|
||||
import org.jetbrains.kotlin.idea.findUsages.handlers.DelegatingFindMemberUsagesHandler
|
||||
import org.jetbrains.kotlin.idea.findUsages.handlers.KotlinFindClassUsagesHandler
|
||||
import org.jetbrains.kotlin.idea.findUsages.handlers.KotlinFindMemberUsagesHandler
|
||||
import org.jetbrains.kotlin.idea.findUsages.handlers.KotlinTypeParameterFindUsagesHandler
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.search.KotlinSearchUsagesSupport.Companion.isOverridable
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
|
||||
@@ -96,7 +92,7 @@ class KotlinFindUsagesHandlerFactory(project: Project) : FindUsagesHandlerFactor
|
||||
val psiMethod = function.providedToLightMethods().singleOrNull()
|
||||
if (psiMethod != null) {
|
||||
val hasOverridden = OverridingMethodsSearch.search(psiMethod).any()
|
||||
if (hasOverridden && askWhetherShouldSearchForParameterInOverridingMethods(element)) {
|
||||
if (hasOverridden && findFunctionOptions.isSearchForBaseMethod) {
|
||||
val parametersCount = psiMethod.parameterList.parametersCount
|
||||
val parameterIndex = element.parameterIndex()
|
||||
assert(parameterIndex < parametersCount)
|
||||
@@ -153,14 +149,4 @@ class KotlinFindUsagesHandlerFactory(project: Project) : FindUsagesHandlerFactor
|
||||
else -> DelegatingFindMemberUsagesHandler(originalDeclaration, declarations, factory = this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun askWhetherShouldSearchForParameterInOverridingMethods(parameter: KtParameter): Boolean {
|
||||
return Messages.showOkCancelDialog(
|
||||
parameter.project,
|
||||
JavaBundle.message("find.parameter.usages.in.overriding.methods.prompt", parameter.name),
|
||||
JavaBundle.message("find.parameter.usages.in.overriding.methods.title"),
|
||||
CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText(),
|
||||
Messages.getQuestionIcon()
|
||||
) == Messages.OK
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class KotlinFunctionFindUsagesOptions(project: Project) : KotlinCallableFindUsag
|
||||
javaOptions.isOverridingMethods = isOverridingMethods
|
||||
javaOptions.isSearchForTextOccurrences = isSearchForTextOccurrences
|
||||
javaOptions.isSkipImportStatements = isSkipImportStatements
|
||||
javaOptions.isSearchForBaseMethod = isSearchForBaseMethod
|
||||
javaOptions.isUsages = isUsages
|
||||
javaOptions.searchScope = searchScope
|
||||
|
||||
@@ -88,6 +89,9 @@ class KotlinPropertyFindUsagesOptions(
|
||||
javaOptions.isWriteAccess = isWriteAccess
|
||||
javaOptions.isUsages = isUsages
|
||||
javaOptions.searchScope = searchScope
|
||||
javaOptions.isSearchForAccessors = isSearchForAccessors
|
||||
javaOptions.isSearchInOverridingMethods = isSearchInOverridingMethods
|
||||
javaOptions.isSearchForBaseAccessors = isSearchForBaseAccessors
|
||||
return javaOptions
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user