mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
@@ -143,7 +143,7 @@ public class TargetElementUtilBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean inVirtualSpace(Editor editor, int offset) {
|
||||
public static boolean inVirtualSpace(@NotNull Editor editor, int offset) {
|
||||
if (offset == editor.getCaretModel().getOffset()) {
|
||||
return EditorUtil.inVirtualSpace(editor, editor.getCaretModel().getLogicalPosition());
|
||||
}
|
||||
|
||||
@@ -48,12 +48,17 @@ public final class NavigationUtil {
|
||||
private NavigationUtil() {
|
||||
}
|
||||
|
||||
public static JBPopup getPsiElementPopup(PsiElement[] elements, String title) {
|
||||
@NotNull
|
||||
public static JBPopup getPsiElementPopup(@NotNull PsiElement[] elements, String title) {
|
||||
return getPsiElementPopup(elements, new DefaultPsiElementCellRenderer(), title);
|
||||
}
|
||||
|
||||
public static JBPopup getPsiElementPopup(final PsiElement[] elements, final PsiElementListCellRenderer<PsiElement> renderer, final String title) {
|
||||
@NotNull
|
||||
public static JBPopup getPsiElementPopup(@NotNull PsiElement[] elements,
|
||||
@NotNull final PsiElementListCellRenderer<PsiElement> renderer,
|
||||
final String title) {
|
||||
return getPsiElementPopup(elements, renderer, title, new PsiElementProcessor<PsiElement>() {
|
||||
@Override
|
||||
public boolean execute(@NotNull final PsiElement element) {
|
||||
Navigatable descriptor = EditSourceUtil.getDescriptor(element);
|
||||
if (descriptor != null && descriptor.canNavigate()) {
|
||||
@@ -64,15 +69,19 @@ public final class NavigationUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> JBPopup getPsiElementPopup(final T[] elements, final PsiElementListCellRenderer<T> renderer,
|
||||
final String title, final PsiElementProcessor<T> processor) {
|
||||
@NotNull
|
||||
public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements,
|
||||
@NotNull final PsiElementListCellRenderer<T> renderer,
|
||||
final String title,
|
||||
@NotNull final PsiElementProcessor<T> processor) {
|
||||
return getPsiElementPopup(elements, renderer, title, processor, null);
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> JBPopup getPsiElementPopup(final T[] elements,
|
||||
final PsiElementListCellRenderer<T> renderer,
|
||||
final String title,
|
||||
final PsiElementProcessor<T> processor,
|
||||
@NotNull
|
||||
public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements,
|
||||
@NotNull final PsiElementListCellRenderer<T> renderer,
|
||||
@Nullable final String title,
|
||||
@NotNull final PsiElementProcessor<T> processor,
|
||||
@Nullable final T selection) {
|
||||
final JList list = new JBList(elements);
|
||||
list.setCellRenderer(renderer);
|
||||
@@ -81,6 +90,7 @@ public final class NavigationUtil {
|
||||
}
|
||||
|
||||
final Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int[] ids = list.getSelectedIndices();
|
||||
if (ids == null || ids.length == 0) return;
|
||||
@@ -116,7 +126,8 @@ public final class NavigationUtil {
|
||||
|
||||
if (searchForOpen) {
|
||||
elt.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
elt.putUserData(FileEditorManager.USE_CURRENT_WINDOW, true);
|
||||
}
|
||||
|
||||
@@ -130,11 +141,9 @@ public final class NavigationUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen) {
|
||||
if (!elt.isValid()) return false;
|
||||
elt = elt.getNavigationElement();
|
||||
if (elt == null) return false;
|
||||
final PsiFile file = elt.getContainingFile();
|
||||
if (file == null || !file.isValid()) return false;
|
||||
|
||||
|
||||
+8
-8
@@ -124,11 +124,11 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
}
|
||||
|
||||
// returns true if processor is run or is going to be run after showing popup
|
||||
public static boolean chooseAmbiguousTarget(final Editor editor,
|
||||
public static boolean chooseAmbiguousTarget(@NotNull Editor editor,
|
||||
int offset,
|
||||
PsiElementProcessor<PsiElement> processor,
|
||||
String titlePattern,
|
||||
PsiElement[] elements) {
|
||||
@NotNull PsiElementProcessor<PsiElement> processor,
|
||||
@NotNull String titlePattern,
|
||||
@Nullable PsiElement[] elements) {
|
||||
if (TargetElementUtilBase.inVirtualSpace(editor, offset)) {
|
||||
return false;
|
||||
}
|
||||
@@ -149,16 +149,16 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
if (elements.length > 1) {
|
||||
String title;
|
||||
|
||||
if (reference != null) {
|
||||
if (reference == null) {
|
||||
title = titlePattern;
|
||||
}
|
||||
else {
|
||||
final TextRange range = reference.getRangeInElement();
|
||||
final String elementText = reference.getElement().getText();
|
||||
LOG.assertTrue(range.getStartOffset() >= 0 && range.getEndOffset() <= elementText.length(), Arrays.toString(elements));
|
||||
final String refText = range.substring(elementText);
|
||||
title = MessageFormat.format(titlePattern, refText);
|
||||
}
|
||||
else {
|
||||
title = titlePattern;
|
||||
}
|
||||
|
||||
NavigationUtil.getPsiElementPopup(elements, new DefaultPsiElementCellRenderer(), title, processor).showInBestPositionFor(editor);
|
||||
return true;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class FindBundle {
|
||||
private FindBundle() {
|
||||
}
|
||||
|
||||
public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Object... params) {
|
||||
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
|
||||
return CommonBundle.message(getBundle(), key, params);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class FindUsagesInFileAction extends AnAction {
|
||||
Presentation presentation = event.getPresentation();
|
||||
DataContext dataContext = event.getDataContext();
|
||||
boolean enabled = isEnabled(dataContext);
|
||||
presentation.setVisible(ActionPlaces.isPopupPlace(event.getPlace()) ? enabled : true);
|
||||
presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(event.getPlace()));
|
||||
presentation.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ public abstract class DataManager {
|
||||
* @return value stored by {@link #saveInDataContext(com.intellij.openapi.actionSystem.DataContext, com.intellij.openapi.util.Key, Object)}
|
||||
*/
|
||||
@Nullable
|
||||
public abstract <T> T loadFromDataContext(DataContext dataContext, Key<T> dataKey);
|
||||
public abstract <T> T loadFromDataContext(@NotNull DataContext dataContext, @NotNull Key<T> dataKey);
|
||||
|
||||
public static void registerDataProvider(JComponent component, DataProvider provider) {
|
||||
public static void registerDataProvider(@NotNull JComponent component, @NotNull DataProvider provider) {
|
||||
component.putClientProperty(CLIENT_PROPERTY_DATA_PROVIDER, provider);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.util.ui.ComponentWithEmptyText;
|
||||
import com.intellij.util.ui.StatusText;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -42,7 +43,7 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
private StatusText myEmptyText;
|
||||
private ExpandableItemsHandler<Integer> myExpandableItemsHandler;
|
||||
|
||||
private AsyncProcessIcon myBusyIcon;
|
||||
@Nullable private AsyncProcessIcon myBusyIcon;
|
||||
private boolean myBusy;
|
||||
|
||||
|
||||
@@ -50,17 +51,18 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
init();
|
||||
}
|
||||
|
||||
public JBList(ListModel dataModel) {
|
||||
public JBList(@NotNull ListModel dataModel) {
|
||||
super(dataModel);
|
||||
init();
|
||||
}
|
||||
|
||||
public JBList(Object... listData) {
|
||||
public JBList(@NotNull Object... listData) {
|
||||
super(createDefaultListModel(listData));
|
||||
init();
|
||||
}
|
||||
|
||||
public static DefaultListModel createDefaultListModel(Object... items) {
|
||||
@NotNull
|
||||
public static DefaultListModel createDefaultListModel(@NotNull Object... items) {
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
for (Object item : items) {
|
||||
model.add(model.getSize(), item);
|
||||
@@ -68,7 +70,7 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
return model;
|
||||
}
|
||||
|
||||
public JBList(Collection items) {
|
||||
public JBList(@NotNull Collection items) {
|
||||
this(ArrayUtil.toObjectArray(items));
|
||||
}
|
||||
|
||||
@@ -199,17 +201,23 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
return myExpandableItemsHandler;
|
||||
}
|
||||
|
||||
public <T> void installCellRenderer(final @NotNull NotNullFunction<T, JComponent> fun) {
|
||||
public <T> void installCellRenderer(@NotNull final NotNullFunction<T, JComponent> fun) {
|
||||
setCellRenderer(new DefaultListCellRenderer() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
public Component getListCellRendererComponent(@NotNull JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
final JComponent comp = fun.fun((T)value);
|
||||
final JComponent comp = fun.fun((T)value);
|
||||
comp.setOpaque(true);
|
||||
if (isSelected) {
|
||||
comp.setBackground(list.getSelectionBackground());
|
||||
comp.setForeground(list.getSelectionForeground());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
comp.setBackground(list.getBackground());
|
||||
comp.setForeground(list.getForeground());
|
||||
}
|
||||
@@ -218,7 +226,7 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
});
|
||||
}
|
||||
|
||||
public void setDataProvider(DataProvider provider) {
|
||||
public void setDataProvider(@NotNull DataProvider provider) {
|
||||
DataManager.registerDataProvider(this, provider);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ public class DataManagerImpl extends DataManager implements ApplicationComponent
|
||||
return data;
|
||||
}
|
||||
|
||||
public DataContext getDataContext(Component component) {
|
||||
public DataContext getDataContext(@NotNull Component component) {
|
||||
return new MyDataContext(component);
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ public class DataManagerImpl extends DataManager implements ApplicationComponent
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T loadFromDataContext(DataContext dataContext, Key<T> dataKey) {
|
||||
public <T> T loadFromDataContext(@NotNull DataContext dataContext, @NotNull Key<T> dataKey) {
|
||||
return dataContext instanceof UserDataHolder ? ((UserDataHolder)dataContext).getUserData(dataKey) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CommandLineApplication {
|
||||
return new CommandLineDataContext();
|
||||
}
|
||||
|
||||
public DataContext getDataContext(Component component) {
|
||||
public DataContext getDataContext(@NotNull Component component) {
|
||||
return getDataContext();
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -57,6 +57,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
public ProgressManagerImpl(Application application) {
|
||||
if (/*!application.isUnitTestMode() && */!DISABLED) {
|
||||
final Thread thread = new Thread(NAME) {
|
||||
@Override
|
||||
public void run() {
|
||||
while (enabled) {
|
||||
try {
|
||||
@@ -113,6 +114,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
myOld = old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
ProgressIndicator currentIndicator = myThreadIndicator.get();
|
||||
if (currentIndicator != this) {
|
||||
@@ -127,12 +129,14 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonCancelableSection startNonCancelableSection() {
|
||||
NonCancelableIndicator nonCancelor = new NonCancelableIndicator(myThreadIndicator.get());
|
||||
myThreadIndicator.set(nonCancelor);
|
||||
return nonCancelor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeNonCancelableSection(@NotNull Runnable runnable) {
|
||||
NonCancelableSection nonCancelor = startNonCancelableSection();
|
||||
try {
|
||||
@@ -143,6 +147,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelButtonText(String cancelButtonText) {
|
||||
ProgressIndicator progressIndicator = getProgressIndicator();
|
||||
if (progressIndicator != null) {
|
||||
@@ -156,20 +161,25 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProgressIndicator() {
|
||||
return getProgressIndicator() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnsafeProgressIndicator() {
|
||||
return myCurrentUnsafeProgressCount.get() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasModalProgressIndicator() {
|
||||
return myCurrentModalProgressCount.get() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runProcess(@NotNull final Runnable process, final ProgressIndicator progress) {
|
||||
executeProcessUnderProgress(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (process) {
|
||||
process.notifyAll();
|
||||
@@ -234,10 +244,12 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressIndicator getProgressIndicator() {
|
||||
return myThreadIndicator.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process,
|
||||
@NotNull String progressTitle,
|
||||
boolean canBeCanceled,
|
||||
@@ -254,6 +266,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
final Ref<T> result = new Ref<T>();
|
||||
final Ref<E> exceptionRef = new Ref<E>();
|
||||
Task.Modal task = new Task.Modal(project, progressTitle, canBeCanceled) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
try {
|
||||
T compute = process.compute();
|
||||
@@ -269,12 +282,14 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
return result.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process,
|
||||
@NotNull String progressTitle,
|
||||
boolean canBeCanceled,
|
||||
@Nullable Project project,
|
||||
@Nullable JComponent parentComponent) {
|
||||
Task.Modal task = new Task.Modal(project, progressTitle, canBeCanceled) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
process.run();
|
||||
}
|
||||
@@ -287,6 +302,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
long time = 0;
|
||||
final boolean result = ((ApplicationEx)ApplicationManager.getApplication())
|
||||
.runProcessWithProgressSynchronously(new TaskContainer(task) {
|
||||
@Override
|
||||
public void run() {
|
||||
new TaskRunnable(task, ProgressManager.getInstance().getProgressIndicator()).run();
|
||||
}
|
||||
@@ -315,6 +331,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
notificationInfo.getNotificationText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runProcessWithProgressAsynchronously(@NotNull Project project,
|
||||
@NotNull String progressTitle,
|
||||
@NotNull final Runnable process,
|
||||
@@ -323,6 +340,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
runProcessWithProgressAsynchronously(project, progressTitle, process, successRunnable, canceledRunnable, PerformInBackgroundOption.DEAF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runProcessWithProgressAsynchronously(@NotNull final Project project,
|
||||
@Nls @NotNull final String progressTitle,
|
||||
@NotNull final Runnable process,
|
||||
@@ -331,17 +349,20 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
@NotNull final PerformInBackgroundOption option) {
|
||||
|
||||
runProcessWithProgressAsynchronously(new Task.Backgroundable(project, progressTitle, true, option) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
process.run();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
if (canceledRunnable != null) {
|
||||
canceledRunnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (successRunnable != null) {
|
||||
successRunnable.run();
|
||||
@@ -374,6 +395,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
final Runnable process = new TaskRunnable(task, progressIndicator, continuation);
|
||||
|
||||
TaskContainer action = new TaskContainer(task) {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean canceled = false;
|
||||
final long start = System.currentTimeMillis();
|
||||
@@ -388,6 +410,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
|
||||
if (canceled || progressIndicator.isCanceled()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.onCancel();
|
||||
}
|
||||
@@ -402,6 +425,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.onSuccess();
|
||||
}
|
||||
@@ -421,6 +445,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull final Task task) {
|
||||
if (task.isHeadless()) {
|
||||
new TaskRunnable(task, new EmptyProgressIndicator()).run();
|
||||
@@ -467,6 +492,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
myContinuation = continuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
getTask().run(myIndicator);
|
||||
|
||||
Reference in New Issue
Block a user