Commit 4b5f7512 authored by Alexey Kudravtsev's avatar Alexey Kudravtsev
Browse files

cleanup

parent 9f57deb9
Showing with 73 additions and 94 deletions
+73 -94
......@@ -59,7 +59,8 @@ public class JavaSharedImplUtil {
}
// collects annotations bound to C-style arrays
private static List<PsiAnnotation[]> collectAnnotations(PsiElement anchor, PsiAnnotation stopAt) {
@Nullable
private static List<PsiAnnotation[]> collectAnnotations(@NotNull PsiElement anchor, @Nullable PsiAnnotation stopAt) {
List<PsiAnnotation[]> annotations = ContainerUtil.newSmartList();
List<PsiAnnotation> current = null;
......@@ -175,7 +176,7 @@ public class JavaSharedImplUtil {
}
}
public static void setInitializer(PsiVariable variable, PsiExpression initializer) throws IncorrectOperationException {
public static void setInitializer(@NotNull PsiVariable variable, PsiExpression initializer) throws IncorrectOperationException {
PsiExpression oldInitializer = variable.getInitializer();
if (oldInitializer != null) {
oldInitializer.delete();
......@@ -203,7 +204,7 @@ public class JavaSharedImplUtil {
private final TypeAnnotationProvider myOriginalProvider;
private volatile PsiAnnotation[] myCache;
private FilteringTypeAnnotationProvider(PsiAnnotation[] candidates, TypeAnnotationProvider originalProvider) {
private FilteringTypeAnnotationProvider(@NotNull PsiAnnotation[] candidates, @NotNull TypeAnnotationProvider originalProvider) {
myCandidates = candidates;
myOriginalProvider = originalProvider;
}
......
......@@ -29,8 +29,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Predicate;
import static com.intellij.psi.SyntaxTraverser.psiTraverser;
public class PsiTreeUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.util.PsiTreeUtil");
......@@ -752,6 +750,7 @@ public class PsiTreeUtil {
return null;
}
@SafeVarargs
@Nullable
@Contract("null, _ -> null")
public static PsiElement skipSiblingsForward(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... elementClasses) {
......@@ -776,6 +775,7 @@ public class PsiTreeUtil {
return skipSiblingsForward(element, WS_COMMENTS);
}
@SafeVarargs
@Nullable
@Contract("null, _ -> null")
public static PsiElement skipSiblingsBackward(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... elementClasses) {
......@@ -800,6 +800,7 @@ public class PsiTreeUtil {
return skipSiblingsBackward(element, WS_COMMENTS);
}
@SafeVarargs
@Nullable
@Contract("null, _ -> null")
public static PsiElement skipParentsOfType(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentClasses) {
......@@ -1089,7 +1090,7 @@ public class PsiTreeUtil {
}
public static boolean hasErrorElements(@NotNull PsiElement element) {
return !psiTraverser(element).traverse().filter(PsiErrorElement.class).isEmpty();
return !SyntaxTraverser.psiTraverser(element).traverse().filter(PsiErrorElement.class).isEmpty();
}
@NotNull
......@@ -1217,7 +1218,7 @@ public class PsiTreeUtil {
/** use {@link SyntaxTraverser#psiTraverser()} (to be removed in IDEA 2019) */
@Deprecated
public static <T extends PsiElement> Iterator<T> childIterator(@NotNull PsiElement element, @NotNull Class<T> aClass) {
return psiTraverser().children(element).filter(aClass).iterator();
return SyntaxTraverser.psiTraverser().children(element).filter(aClass).iterator();
}
//</editor-fold>
}
......@@ -98,7 +98,7 @@ public class TodoView implements PersistentStateComponent<TodoView.State>, Dispo
if (myContentManager != null) {
// all panel were constructed
Content content = myContentManager.getSelectedContent();
state.selectedIndex = myContentManager.getIndexOfContent(content);
state.selectedIndex = content == null ? -1 : myContentManager.getIndexOfContent(content);
}
return state;
}
......
......@@ -9,6 +9,7 @@ import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolder;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
......@@ -64,7 +65,7 @@ public interface Content extends UserDataHolder, ComponentContainer {
/**
* @param disposer a Disposable object which dispose() method will be invoked upon this content release.
*/
void setDisposer(Disposable disposer);
void setDisposer(@NotNull Disposable disposer);
void setShouldDisposeContent(boolean value);
boolean shouldDisposeContent();
......
......@@ -83,9 +83,9 @@ public interface ContentManager extends Disposable, BusyObject {
@Nullable
Content getContent(int index);
Content getContent(JComponent component);
Content getContent(@NotNull JComponent component);
int getIndexOfContent(Content content);
int getIndexOfContent(@NotNull Content content);
@NotNull
String getCloseActionName();
......@@ -115,6 +115,7 @@ public interface ContentManager extends Disposable, BusyObject {
@NotNull
String getNextContentActionName();
@NotNull
List<AnAction> getAdditionalPopupActions(@NotNull Content content);
void removeFromSelection(@NotNull Content content);
......
......@@ -522,6 +522,7 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx {
return null;
}
@NotNull
@Override
public List<AnAction> getAdditionalPopupActions(@NotNull final Content content) {
return Collections.emptyList();
......@@ -558,7 +559,7 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx {
}
@Override
public Content getContent(final JComponent component) {
public Content getContent(@NotNull final JComponent component) {
Content[] contents = getContents();
for (Content content : contents) {
if (Comparing.equal(component, content.getComponent())) {
......@@ -586,7 +587,7 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx {
}
@Override
public int getIndexOfContent(final Content content) {
public int getIndexOfContent(@NotNull final Content content) {
return myContents.indexOf(content);
}
......
......@@ -27,8 +27,6 @@ import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import java.util.Map;
import java.util.Optional;
......@@ -36,15 +34,16 @@ import java.util.Optional;
class ContentTabLabel extends BaseLabel {
private static final int MAX_WIDTH = JBUI.scale(300);
private static final int DEFAULT_HORIZONTAL_INSET = JBUI.scale(12);
protected static final int ICONS_GAP = JBUI.scale(3);
private static final int ICONS_GAP = JBUI.scale(3);
private final ActiveIcon myCloseIcon = new ActiveIcon(JBUI.CurrentTheme.ToolWindow.closeTabIcon(true),
JBUI.CurrentTheme.ToolWindow.closeTabIcon(false));
@NotNull
private final Content myContent;
private final TabContentLayout myLayout;
private final List<AdditionalIcon> myAdditionalIcons = new SmartList<>();
private String myText = null;
private String myText;
private int myIconWithInsetsWidth;
private final AdditionalIcon closeTabIcon = new AdditionalIcon(myCloseIcon) {
......@@ -125,7 +124,7 @@ class ContentTabLabel extends BaseLabel {
currentIconTooltip = null;
}
BaseButtonBehavior behavior = new BaseButtonBehavior(this) {
private final BaseButtonBehavior behavior = new BaseButtonBehavior(this) {
@Override
protected void execute(final MouseEvent e) {
......@@ -176,7 +175,7 @@ class ContentTabLabel extends BaseLabel {
super.setText(myText);
}
protected final boolean mouseOverIcon(AdditionalIcon icon) {
final boolean mouseOverIcon(AdditionalIcon icon) {
if (!isHovered() || !icon.getAvailable()) return false;
PointerInfo info = MouseInfo.getPointerInfo();
......@@ -196,20 +195,17 @@ class ContentTabLabel extends BaseLabel {
behavior.setActionTrigger(MouseEvent.MOUSE_RELEASED);
behavior.setMouseDeadzone(TimedDeadzone.NULL);
myContent.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
final String property = event.getPropertyName();
if (Content.IS_CLOSABLE.equals(property)) {
repaint();
}
myContent.addPropertyChangeListener(event -> {
final String property = event.getPropertyName();
if (Content.IS_CLOSABLE.equals(property)) {
repaint();
}
});
setMaximumSize(new Dimension(MAX_WIDTH, getMaximumSize().height));
}
protected void fillIcons(List<AdditionalIcon> icons) {
protected void fillIcons(@NotNull List<? super AdditionalIcon> icons) {
icons.add(closeTabIcon);
}
......@@ -263,7 +259,6 @@ class ContentTabLabel extends BaseLabel {
@Override
public Dimension getPreferredSize() {
final Dimension size = super.getPreferredSize();
int iconWidth = 0;
Map<Boolean, List<AdditionalIcon>> map = new THashMap<>();
for (AdditionalIcon myAdditionalIcon : myAdditionalIcons) {
if (myAdditionalIcon.getAvailable()) {
......@@ -271,9 +266,9 @@ class ContentTabLabel extends BaseLabel {
}
}
int right = DEFAULT_HORIZONTAL_INSET;
int left = DEFAULT_HORIZONTAL_INSET;
int iconWidth = 0;
if (map.get(false) != null) {
iconWidth = ICONS_GAP;
......@@ -286,6 +281,7 @@ class ContentTabLabel extends BaseLabel {
iconWidth = 0;
}
int right = DEFAULT_HORIZONTAL_INSET;
if (map.get(true) != null) {
right = ICONS_GAP + JBUI.scale(4);
......@@ -303,7 +299,7 @@ class ContentTabLabel extends BaseLabel {
@Override
protected boolean allowEngravement() {
return isSelected() || (myUi != null && myUi.myWindow.isActive());
return isSelected() || myUi != null && myUi.myWindow.isActive();
}
@Override
......
......@@ -61,7 +61,7 @@ public class TabbedContentTabLabel extends ContentTabLabel {
}
@Override
protected void fillIcons(List<AdditionalIcon> icons) {
protected void fillIcons(@NotNull List<? super AdditionalIcon> icons) {
icons.add(new AdditionalIcon(new ActiveIcon(JBUI.CurrentTheme.ToolWindow.comboTabIcon(true),
JBUI.CurrentTheme.ToolWindow.comboTabIcon(false))) {
@NotNull
......
......@@ -663,7 +663,9 @@ public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyCh
final Content selectedContent = myManager.getSelectedContent();
final SelectContentStep step = new SelectContentStep(contents);
step.setDefaultOptionIndex(myManager.getIndexOfContent(selectedContent));
if (selectedContent != null) {
step.setDefaultOptionIndex(myManager.getIndexOfContent(selectedContent));
}
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
getCurrentLayout().showContentPopup(popup);
......
......@@ -103,7 +103,7 @@ public class TabbedPaneContentUI implements ContentUI, PropertyChangeListener {
private Content getSelectedContent() {
JComponent selectedComponent = myTabbedPaneWrapper.getSelectedComponent();
return myManager.getContent(selectedComponent);
return selectedComponent == null ? null : myManager.getContent(selectedComponent);
}
private class MyTabbedPaneWrapper extends TabbedPaneWrapper.AsJTabbedPane {
......@@ -243,11 +243,9 @@ public class TabbedPaneContentUI implements ContentUI, PropertyChangeListener {
group.add(new TabbedContentAction.MyNextTabAction(myManager));
group.add(new TabbedContentAction.MyPreviousTabAction(myManager));
final List<AnAction> additionalActions = myManager.getAdditionalPopupActions(content);
if (additionalActions != null) {
if (!additionalActions.isEmpty()) {
group.addSeparator();
for (AnAction anAction : additionalActions) {
group.add(anAction);
}
group.addAll(additionalActions);
}
ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(POPUP_PLACE, group);
menu.getComponent().show(myTabbedPaneWrapper.getComponent(), x, y);
......
......@@ -162,7 +162,7 @@ public class ContentImpl extends UserDataHolderBase implements Content {
}
@Override
public void setDisposer(Disposable disposer) {
public void setDisposer(@NotNull Disposable disposer) {
myDisposer = disposer;
}
......
......@@ -12,7 +12,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
import com.intellij.ui.components.panels.NonOpaquePanel;
import com.intellij.ui.content.*;
import com.intellij.util.EventDispatcher;
......@@ -26,12 +25,8 @@ import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.*;
import java.util.List;
import java.util.Set;
import static com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance;
/**
* @author Anton Katilin
......@@ -170,7 +165,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
@Override
public ActionCallback removeContent(@NotNull Content content, boolean dispose, final boolean requestFocus, final boolean forcedFocus) {
final ActionCallback result = new ActionCallback();
removeContent(content, true, dispose).doWhenDone(() -> {
doRemoveContent(content, dispose).doWhenDone(() -> {
if (requestFocus) {
Content current = getSelectedContent();
if (current != null) {
......@@ -189,7 +184,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
}
@NotNull
private ActionCallback removeContent(@NotNull Content content, boolean trackSelection, boolean dispose) {
private ActionCallback doRemoveContent(@NotNull Content content, boolean dispose) {
ApplicationManager.getApplication().assertIsDispatchThread();
int indexToBeRemoved = getIndexOfContent(content);
if (indexToBeRemoved == -1) return ActionCallback.REJECTED;
......@@ -198,7 +193,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
Content selection = mySelection.isEmpty() ? null : mySelection.get(mySelection.size() - 1);
int selectedIndex = selection != null ? myContents.indexOf(selection) : -1;
if (!fireContentRemoveQuery(content, indexToBeRemoved, ContentManagerEvent.ContentOperation.undefined)) {
if (!fireContentRemoveQuery(content, indexToBeRemoved)) {
return ActionCallback.REJECTED;
}
if (!content.isValid()) {
......@@ -237,9 +232,9 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
}
int newSize = myContents.size();
if (newSize > 0 && trackSelection) {
if (newSize > 0) {
if (indexToSelect > -1) {
final Content toSelect = mySelectionHistory.size() > 0 ? mySelectionHistory.get(0) : myContents.get(indexToSelect);
final Content toSelect = !mySelectionHistory.isEmpty() ? mySelectionHistory.get(0) : myContents.get(indexToSelect);
if (!isSelected(toSelect)) {
if (myUI.isSingleSelection()) {
ActionCallback result = new ActionCallback();
......@@ -302,7 +297,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
}
@Override
public Content getContent(JComponent component) {
public Content getContent(@NotNull JComponent component) {
Content[] contents = getContents();
for (Content content : contents) {
if (Comparing.equal(component, content.getComponent())) {
......@@ -313,7 +308,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
}
@Override
public int getIndexOfContent(Content content) {
public int getIndexOfContent(@NotNull Content content) {
return myContents.indexOf(content);
}
......@@ -341,9 +336,10 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
return myUI.getNextContentActionName();
}
@NotNull
@Override
public List<AnAction> getAdditionalPopupActions(@NotNull final Content content) {
return null;
return Collections.emptyList();
}
@Override
......@@ -506,7 +502,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
int contentCount = getContentCount();
LOG.assertTrue(contentCount > 1);
Content selectedContent = getSelectedContent();
int index = getIndexOfContent(selectedContent);
int index = selectedContent == null ? -1 : getIndexOfContent(selectedContent);
index = (index - 1 + contentCount) % contentCount;
final Content content = getContent(index);
if (content == null) {
......@@ -520,7 +516,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
int contentCount = getContentCount();
LOG.assertTrue(contentCount > 1);
Content selectedContent = getSelectedContent();
int index = getIndexOfContent(selectedContent);
int index = selectedContent == null ? -1 : getIndexOfContent(selectedContent);
index = (index + 1) % contentCount;
final Content content = getContent(index);
if (content == null) {
......@@ -555,8 +551,8 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
myDispatcher.getMulticaster().selectionChanged(e);
}
private boolean fireContentRemoveQuery(@NotNull Content content, int oldIndex, ContentManagerEvent.ContentOperation operation) {
ContentManagerEvent event = new ContentManagerEvent(this, content, oldIndex, operation);
private boolean fireContentRemoveQuery(@NotNull Content content, int oldIndex) {
ContentManagerEvent event = new ContentManagerEvent(this, content, oldIndex, ContentManagerEvent.ContentOperation.undefined);
for (ContentManagerListener listener : myDispatcher.getListeners()) {
listener.contentRemoveQuery(event);
if (event.isConsumed()) {
......@@ -580,28 +576,6 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
return IdeFocusManager.getInstance(myProject);
}
private static ActionCallback doRequestFocus(final Content toSelect) {
JComponent toFocus = computeWillFocusComponent(toSelect);
if (toFocus != null) {
getGlobalInstance().doWhenFocusSettlesDown(() -> {
getGlobalInstance().requestFocus(toFocus, true);
});
}
return ActionCallback.DONE;
}
private static JComponent computeWillFocusComponent(Content toSelect) {
JComponent toFocus = toSelect.getPreferredFocusableComponent();
if (toFocus != null) {
toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(toFocus);
}
if (toFocus == null) toFocus = toSelect.getPreferredFocusableComponent();
return toFocus;
}
@Override
public void addDataProvider(@NotNull final DataProvider provider) {
dataProviders.add(provider);
......
......@@ -27,6 +27,7 @@ public abstract class TabbedContentAction extends AnAction implements DumbAware
}
public abstract static class ForContent extends TabbedContentAction {
@NotNull
protected final Content myContent;
public ForContent(@NotNull Content content, @NotNull AnAction shortcutTemplate, final String text) {
......
......@@ -62,12 +62,12 @@ public class LowMemoryWatcher {
* When ALWAYS, then the runnable also will be invoked when the low-memory condition is detected before GC.
*
*/
@Contract(pure = true)
@Contract(pure = true) // to avoid ignoring the result
public static LowMemoryWatcher register(@NotNull Runnable runnable, @NotNull LowMemoryWatcherType notificationType) {
return new LowMemoryWatcher(runnable, notificationType);
}
@Contract(pure = true)
@Contract(pure = true) // to avoid ignoring the result
public static LowMemoryWatcher register(@NotNull Runnable runnable) {
return new LowMemoryWatcher(runnable, LowMemoryWatcherType.ALWAYS);
}
......
......@@ -5,8 +5,6 @@ import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
import static com.intellij.openapi.util.LowMemoryWatcher.LowMemoryWatcherType.ALWAYS;
import static com.intellij.openapi.util.LowMemoryWatcher.LowMemoryWatcherType.ONLY_AFTER_GC;
import static org.junit.Assert.assertEquals;
public class LowMemoryWatcherTest {
......@@ -15,17 +13,21 @@ public class LowMemoryWatcherTest {
AtomicInteger onlyAfterGCCounter = new AtomicInteger();
AtomicInteger alwaysCounter = new AtomicInteger();
//noinspection unused
LowMemoryWatcher onlyAfterGCWatcher = LowMemoryWatcher.register(onlyAfterGCCounter::incrementAndGet, ONLY_AFTER_GC);
//noinspection unused
LowMemoryWatcher alwaysWatcher = LowMemoryWatcher.register(alwaysCounter::incrementAndGet, ALWAYS);
LowMemoryWatcher onlyAfterGCWatcher = LowMemoryWatcher.register(onlyAfterGCCounter::incrementAndGet, LowMemoryWatcher.LowMemoryWatcherType.ONLY_AFTER_GC);
LowMemoryWatcher alwaysWatcher = LowMemoryWatcher.register(alwaysCounter::incrementAndGet, LowMemoryWatcher.LowMemoryWatcherType.ALWAYS);
LowMemoryWatcher.onLowMemorySignalReceived(false);
assertEquals(1, alwaysCounter.get());
assertEquals(0, onlyAfterGCCounter.get());
try {
LowMemoryWatcher.onLowMemorySignalReceived(false);
assertEquals(1, alwaysCounter.get());
assertEquals(0, onlyAfterGCCounter.get());
LowMemoryWatcher.onLowMemorySignalReceived(true);
assertEquals(2, alwaysCounter.get());
assertEquals(1, onlyAfterGCCounter.get());
LowMemoryWatcher.onLowMemorySignalReceived(true);
assertEquals(2, alwaysCounter.get());
assertEquals(1, onlyAfterGCCounter.get());
}
finally {
alwaysWatcher.stop();
onlyAfterGCWatcher.stop();
}
}
}
......@@ -61,7 +61,7 @@ public class CoverageViewManager implements PersistentStateComponent<CoverageVie
return myViews.get(getDisplayName(suitesBundle));
}
public void activateToolwindow(CoverageView view, boolean requestFocus) {
public void activateToolwindow(@NotNull CoverageView view, boolean requestFocus) {
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(TOOLWINDOW_ID);
if (requestFocus) {
myContentManager.setSelectedContent(myContentManager.getContent(view));
......
......@@ -85,7 +85,8 @@ public class TerminalArrangementManager implements PersistentStateComponent<Term
tabState.myCommandHistoryFileName = historyFilePath != null ? PathUtil.getFileName(historyFilePath) : null;
arrangementState.myTabStates.add(tabState);
}
arrangementState.mySelectedTabIndex = contentManager.getIndexOfContent(contentManager.getSelectedContent());
Content selectedContent = contentManager.getSelectedContent();
arrangementState.mySelectedTabIndex = selectedContent == null ? -1 : contentManager.getIndexOfContent(selectedContent);
deleteUnusedCommandHistoryFiles(getCommandHistoryFileNames(arrangementState));
return arrangementState;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment