mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup, notnull
This commit is contained in:
@@ -17,37 +17,31 @@ package com.intellij.find.findUsages;
|
||||
|
||||
import com.intellij.find.FindBundle;
|
||||
import com.intellij.find.FindSettings;
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public abstract class JavaFindUsagesDialog<T extends JavaFindUsagesOptions> extends AbstractFindUsagesDialog {
|
||||
protected final PsiElement myPsiElement;
|
||||
public abstract class JavaFindUsagesDialog<T extends JavaFindUsagesOptions> extends CommonFindUsagesDialog {
|
||||
private StateRestoringCheckBox myCbIncludeOverloadedMethods;
|
||||
private boolean myIncludeOverloadedMethodsAvailable = false;
|
||||
|
||||
protected JavaFindUsagesDialog(PsiElement element, Project project, FindUsagesOptions findUsagesOptions, boolean toShowInNewTab, boolean mustOpenInNewTab,
|
||||
protected JavaFindUsagesDialog(@NotNull PsiElement element,
|
||||
@NotNull Project project,
|
||||
@NotNull FindUsagesOptions findUsagesOptions,
|
||||
boolean toShowInNewTab,
|
||||
boolean mustOpenInNewTab,
|
||||
boolean isSingleFile,
|
||||
FindUsagesHandler handler) {
|
||||
super(project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, isTextSearch(element, isSingleFile, handler), !isSingleFile && !element.getManager().isInProject(element));
|
||||
myPsiElement = element;
|
||||
super(element, project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, handler);
|
||||
myIncludeOverloadedMethodsAvailable = element instanceof PsiMethod && MethodSignatureUtil.hasOverloads((PsiMethod)element);
|
||||
init();
|
||||
}
|
||||
|
||||
private static boolean isTextSearch(PsiElement element, boolean isSingleFile, FindUsagesHandler handler) {
|
||||
return FindUsagesUtil.isSearchForTextOccurrencesAvailable(element, isSingleFile, handler);
|
||||
}
|
||||
|
||||
public void calcFindUsagesOptions(T options) {
|
||||
if (options instanceof JavaMethodFindUsagesOptions) {
|
||||
@@ -85,28 +79,10 @@ public abstract class JavaFindUsagesDialog<T extends JavaFindUsagesOptions> exte
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInFileOnly() {
|
||||
return super.isInFileOnly() ||
|
||||
myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureLabelComponent(final SimpleColoredComponent coloredComponent) {
|
||||
coloredComponent.append(StringUtil.capitalize(UsageViewUtil.getType(myPsiElement)));
|
||||
coloredComponent.append(" ");
|
||||
coloredComponent.append(UsageViewUtil.getDescriptiveName(myPsiElement));
|
||||
}
|
||||
|
||||
protected final PsiElement getPsiElement() {
|
||||
return myPsiElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHelpAction() {
|
||||
HelpManager.getInstance().invokeHelp(FindUsagesManager.getHelpID(myPsiElement));
|
||||
}
|
||||
|
||||
protected T getFindUsagesOptions() {
|
||||
return (T)myFindUsagesOptions;
|
||||
}
|
||||
|
||||
@@ -66,18 +66,17 @@ import java.util.*;
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.find.findUsages.DefaultFindUsagesHandler");
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.find.findUsages.JavaFindUsagesHandler");
|
||||
public static final String ACTION_STRING = FindBundle.message("find.super.method.warning.action.verb");
|
||||
|
||||
private final PsiElement[] myElementsToSearch;
|
||||
private final JavaFindUsagesHandlerFactory myFactory;
|
||||
|
||||
public JavaFindUsagesHandler(@NotNull PsiElement psiElement, JavaFindUsagesHandlerFactory factory) {
|
||||
public JavaFindUsagesHandler(@NotNull PsiElement psiElement, @NotNull JavaFindUsagesHandlerFactory factory) {
|
||||
this(psiElement, PsiElement.EMPTY_ARRAY, factory);
|
||||
}
|
||||
|
||||
|
||||
public JavaFindUsagesHandler(@NotNull PsiElement psiElement, @NotNull PsiElement[] elementsToSearch, JavaFindUsagesHandlerFactory factory) {
|
||||
public JavaFindUsagesHandler(@NotNull PsiElement psiElement, @NotNull PsiElement[] elementsToSearch, @NotNull JavaFindUsagesHandlerFactory factory) {
|
||||
super(psiElement);
|
||||
myElementsToSearch = elementsToSearch;
|
||||
myFactory = factory;
|
||||
@@ -714,14 +713,14 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isSearchForTextOccurencesAvailable(PsiElement psiElement, boolean isSingleFile) {
|
||||
protected boolean isSearchForTextOccurencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) {
|
||||
if (isSingleFile) return false;
|
||||
return new JavaNonCodeSearchElementDescriptionProvider().getElementDescription(psiElement, NonCodeSearchDescriptionLocation.NON_JAVA) != null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PsiReference> findReferencesToHighlight(final PsiElement target, final SearchScope searchScope) {
|
||||
public Collection<PsiReference> findReferencesToHighlight(@NotNull final PsiElement target, final SearchScope searchScope) {
|
||||
if (target instanceof PsiMethod) {
|
||||
final PsiMethod[] superMethods = ((PsiMethod)target).findDeepestSuperMethods();
|
||||
if (superMethods.length == 0) {
|
||||
|
||||
+3
-3
@@ -16,23 +16,23 @@
|
||||
package com.intellij.refactoring.util;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JavaNonCodeSearchElementDescriptionProvider implements ElementDescriptionProvider {
|
||||
@Override
|
||||
public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
|
||||
if (!(location instanceof NonCodeSearchDescriptionLocation)) return null;
|
||||
NonCodeSearchDescriptionLocation ncdLocation = (NonCodeSearchDescriptionLocation) location;
|
||||
if (element instanceof PsiPackage) {
|
||||
return ncdLocation.isNonJava() ? ((PsiPackage)element).getQualifiedName() : ((PsiPackage)element).getName();
|
||||
}
|
||||
else if (element instanceof PsiClass) {
|
||||
if (element instanceof PsiClass) {
|
||||
return ncdLocation.isNonJava() ? ((PsiClass)element).getQualifiedName() : ((PsiClass)element).getName();
|
||||
}
|
||||
else if (element instanceof PsiMember) {
|
||||
if (element instanceof PsiMember) {
|
||||
PsiMember member = (PsiMember)element;
|
||||
String name = member.getName();
|
||||
if (name == null) return null;
|
||||
|
||||
@@ -280,7 +280,6 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
||||
continueSearch = false;
|
||||
}
|
||||
pingEDT.ping();
|
||||
//rebuildPopup(usageView, usages, table, popup, presentation, popupPosition);
|
||||
return continueSearch;
|
||||
}
|
||||
}
|
||||
@@ -579,14 +578,14 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
||||
}.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
|
||||
}
|
||||
|
||||
InplaceButton button = createSettingsButton(handler, popupPosition, editor, maxUsages, new Runnable() {
|
||||
InplaceButton settingsButton = createSettingsButton(handler, popupPosition, editor, maxUsages, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
popup[0].cancel();
|
||||
}
|
||||
});
|
||||
|
||||
ActiveComponent iconComp = new ActiveComponent() {
|
||||
ActiveComponent spinningProgress = new ActiveComponent() {
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
}
|
||||
@@ -596,7 +595,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
||||
return processIcon;
|
||||
}
|
||||
};
|
||||
builder.setCommandButton(new CompositeActiveComponent(iconComp, button));
|
||||
builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton));
|
||||
|
||||
DefaultActionGroup toolbar = new DefaultActionGroup();
|
||||
usageView.addFilteringActions(toolbar);
|
||||
@@ -631,7 +630,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
||||
|
||||
myWidth = (int)(toolBar.getPreferredSize().getWidth()
|
||||
+ new JLabel(getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1)).getPreferredSize().getWidth()
|
||||
+ button.getPreferredSize().getWidth());
|
||||
+ settingsButton.getPreferredSize().getWidth());
|
||||
myWidth = -1;
|
||||
for (AnAction action : toolbar.getChildren(null)) {
|
||||
action.unregisterCustomShortcutSet(usageView.getComponent());
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractFindUsagesDialog extends DialogWrapper {
|
||||
return panel;
|
||||
}
|
||||
|
||||
public abstract void configureLabelComponent(final SimpleColoredComponent coloredComponent);
|
||||
public abstract void configureLabelComponent(@NotNull SimpleColoredComponent coloredComponent);
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -34,13 +35,15 @@ import javax.swing.*;
|
||||
public class CommonFindUsagesDialog extends AbstractFindUsagesDialog {
|
||||
protected final PsiElement myPsiElement;
|
||||
|
||||
public CommonFindUsagesDialog(PsiElement element,
|
||||
Project project,
|
||||
FindUsagesOptions findUsagesOptions,
|
||||
public CommonFindUsagesDialog(@NotNull PsiElement element,
|
||||
@NotNull Project project,
|
||||
@NotNull FindUsagesOptions findUsagesOptions,
|
||||
boolean toShowInNewTab,
|
||||
boolean mustOpenInNewTab,
|
||||
boolean isSingleFile, FindUsagesHandler handler) {
|
||||
super(project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, isTextSearch(element, isSingleFile, handler), !isSingleFile && !element.getManager().isInProject(element));
|
||||
boolean isSingleFile,
|
||||
FindUsagesHandler handler) {
|
||||
super(project, findUsagesOptions, toShowInNewTab, mustOpenInNewTab, isSingleFile, isTextSearch(element, isSingleFile, handler),
|
||||
!isSingleFile && !element.getManager().isInProject(element));
|
||||
myPsiElement = element;
|
||||
init();
|
||||
}
|
||||
@@ -52,7 +55,7 @@ public class CommonFindUsagesDialog extends AbstractFindUsagesDialog {
|
||||
@Override
|
||||
protected boolean isInFileOnly() {
|
||||
return super.isInFileOnly() ||
|
||||
myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope;
|
||||
PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement) instanceof LocalSearchScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +64,7 @@ public class CommonFindUsagesDialog extends AbstractFindUsagesDialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureLabelComponent(final SimpleColoredComponent coloredComponent) {
|
||||
public void configureLabelComponent(@NotNull SimpleColoredComponent coloredComponent) {
|
||||
coloredComponent.append(StringUtil.capitalize(UsageViewUtil.getType(myPsiElement)));
|
||||
coloredComponent.append(" ");
|
||||
coloredComponent.append(UsageViewUtil.getDescriptiveName(myPsiElement), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
|
||||
|
||||
@@ -193,11 +193,11 @@ public abstract class FindUsagesHandler {
|
||||
return Collections.singleton(element.getText());
|
||||
}
|
||||
|
||||
protected boolean isSearchForTextOccurencesAvailable(PsiElement psiElement, boolean isSingleFile) {
|
||||
protected boolean isSearchForTextOccurencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<PsiReference> findReferencesToHighlight(PsiElement target, SearchScope searchScope) {
|
||||
public Collection<PsiReference> findReferencesToHighlight(@NotNull PsiElement target, SearchScope searchScope) {
|
||||
return ReferencesSearch.search(target, searchScope, false).findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
if (handler == null) return;
|
||||
|
||||
boolean singleFile = scopeFile != null;
|
||||
final AbstractFindUsagesDialog dialog = handler.getFindUsagesDialog(singleFile, shouldOpenInNewTab(), mustOpenInNewTab());
|
||||
AbstractFindUsagesDialog dialog = handler.getFindUsagesDialog(singleFile, shouldOpenInNewTab(), mustOpenInNewTab());
|
||||
if (showDialog) {
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
@@ -26,6 +25,7 @@ import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.psi.search.SearchRequestCollector;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -80,13 +80,13 @@ public class FindUsagesOptions extends UserDataHolderBase implements Cloneable {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (searchScope != null ? searchScope.hashCode() : 0);
|
||||
int result = searchScope == null ? 0 : searchScope.hashCode();
|
||||
result = 31 * result + (isSearchForTextOccurrences ? 1 : 0);
|
||||
result = 31 * result + (isUsages ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{" +
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
@@ -18,12 +17,13 @@
|
||||
package com.intellij.find.findUsages;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FindUsagesUtil {
|
||||
private FindUsagesUtil() {
|
||||
}
|
||||
|
||||
public static boolean isSearchForTextOccurrencesAvailable(PsiElement element, boolean isSingleFile, FindUsagesHandler handler) {
|
||||
public static boolean isSearchForTextOccurrencesAvailable(@NotNull PsiElement element, boolean isSingleFile, FindUsagesHandler handler) {
|
||||
return !isSingleFile && handler != null && handler.isSearchForTextOccurencesAvailable(element, isSingleFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ public class FindSettingsImpl extends FindSettings implements PersistentStateCom
|
||||
|
||||
@Override
|
||||
public void addDirectory(String s) {
|
||||
if (s == null || s.length() == 0){
|
||||
if (s == null || s.isEmpty()){
|
||||
return;
|
||||
}
|
||||
addStringToList(s, RECENT_DIR_STRINGS, MAX_RECENT_SIZE);
|
||||
@@ -345,7 +345,7 @@ public class FindSettingsImpl extends FindSettings implements PersistentStateCom
|
||||
@Override
|
||||
public void setFileMask(String _fileMask) {
|
||||
FILE_MASK = _fileMask;
|
||||
if (_fileMask != null && _fileMask.length() > 0) {
|
||||
if (_fileMask != null && !_fileMask.isEmpty()) {
|
||||
addStringToList(_fileMask, RECENT_FILE_MASKS, MAX_RECENT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user