From 448453030bfe21054ecce5a792d168f8c25c4fdb Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Sat, 19 Aug 2017 13:41:38 +0300 Subject: [PATCH] cleanup --- .../src/com/intellij/openapi/ui/ComboBox.java | 7 ------- .../intellij/openapi/ui/ComboBoxWithWidePopup.java | 12 +++++------- .../src/com/intellij/ui/TextFieldWithHistory.java | 14 +++++++------- .../intellij/ui/TextFieldWithStoredHistory.java | 4 ++-- .../openapi/fileTypes/impl/FileTypesTest.java | 4 ++-- .../util/src/com/intellij/util/ObjectUtils.java | 2 +- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java b/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java index f29bdabbbedf..b4cdbb42567b 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java @@ -54,12 +54,10 @@ public class ComboBox extends ComboBoxWithWidePopup implements AWTEventLis protected boolean myPaintingNow; public ComboBox() { - super(); init(-1); } public ComboBox(int width) { - super(); init(width); } @@ -262,11 +260,6 @@ public class ComboBox extends ComboBoxWithWidePopup implements AWTEventLis return new Dimension(width, UIUtil.fixComboBoxHeight(preferredSize.height)); } - @Override - protected Dimension getOriginalPreferredSize() { - return super.getPreferredSize(); - } - @Override public void paint(Graphics g) { try { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComboBoxWithWidePopup.java b/platform/platform-api/src/com/intellij/openapi/ui/ComboBoxWithWidePopup.java index 29d21f857976..4395d9d6792c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComboBoxWithWidePopup.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComboBoxWithWidePopup.java @@ -27,7 +27,6 @@ public class ComboBoxWithWidePopup extends JComboBox { private int myMinLength = 20; public ComboBoxWithWidePopup() { - super(); init(); } @@ -96,29 +95,28 @@ public class ComboBoxWithWidePopup extends JComboBox { private final ListCellRenderer myOldRenderer; private final ComboBoxWithWidePopup myComboBox; - public AdjustingListCellRenderer(ComboBoxWithWidePopup comboBox, ListCellRenderer oldRenderer) { + AdjustingListCellRenderer(ComboBoxWithWidePopup comboBox, ListCellRenderer oldRenderer) { myComboBox = comboBox; myOldRenderer = oldRenderer; } @Override public Component getListCellRendererComponent(JList list, E value, int index, boolean isSelected, boolean cellHasFocus) { - E _value = value; - if (index == -1 && _value instanceof String && !myComboBox.isValid()) { + if (index == -1 && value instanceof String && !myComboBox.isValid()) { int minLength = getMinLength(); Dimension size = myComboBox._getSuperSize(); - String stringValue = (String)_value; + String stringValue = (String)value; if (size.width == 0) { if (stringValue.length() > minLength) { @SuppressWarnings("unchecked") E e = (E)stringValue.substring(0, minLength); - _value = e; + value = e; } } } - return myOldRenderer.getListCellRendererComponent(list, _value, index, isSelected, cellHasFocus); + return myOldRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } } } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ui/TextFieldWithHistory.java b/platform/platform-api/src/com/intellij/ui/TextFieldWithHistory.java index 30aaf60b7983..ad045c63e35c 100644 --- a/platform/platform-api/src/com/intellij/ui/TextFieldWithHistory.java +++ b/platform/platform-api/src/com/intellij/ui/TextFieldWithHistory.java @@ -35,12 +35,6 @@ public class TextFieldWithHistory extends ComboBox { setEditable(true); } - // API compatibility with 7.0.1 - @SuppressWarnings({"UnusedDeclaration"}) - public TextFieldWithHistory(boolean cropList) { - this(); - } - public void addDocumentListener(DocumentListener listener) { getTextEditor().getDocument().addDocumentListener(listener); } @@ -81,6 +75,7 @@ public class TextFieldWithHistory extends ComboBox { return getTextEditor().getText(); } + @Override public void removeNotify() { super.removeNotify(); hidePopup(); @@ -121,10 +116,12 @@ public class TextFieldWithHistory extends ComboBox { private Object mySelectedItem; + @Override public Object getElementAt(int index) { return myFullList.get(index); } + @Override public int getSize() { return Math.min(myHistorySize == -1 ? Integer.MAX_VALUE : myHistorySize, myFullList.size()); } @@ -132,7 +129,7 @@ public class TextFieldWithHistory extends ComboBox { public void addElement(Object obj) { String newItem = ((String)obj).trim(); - if (0 == newItem.length()) { + if (newItem.isEmpty()) { return; } @@ -149,10 +146,12 @@ public class TextFieldWithHistory extends ComboBox { fireIntervalAdded(this, index, index); } + @Override public Object getSelectedItem() { return mySelectedItem; } + @Override public void setSelectedItem(Object anItem) { mySelectedItem = anItem; fireContentsChanged(); @@ -173,6 +172,7 @@ public class TextFieldWithHistory extends ComboBox { } protected static class TextFieldWithProcessing extends JTextField { + @Override public void processKeyEvent(KeyEvent e) { super.processKeyEvent(e); } diff --git a/platform/platform-api/src/com/intellij/ui/TextFieldWithStoredHistory.java b/platform/platform-api/src/com/intellij/ui/TextFieldWithStoredHistory.java index 9fe2f761b4a1..c767e71b035e 100644 --- a/platform/platform-api/src/com/intellij/ui/TextFieldWithStoredHistory.java +++ b/platform/platform-api/src/com/intellij/ui/TextFieldWithStoredHistory.java @@ -25,7 +25,6 @@ public class TextFieldWithStoredHistory extends TextFieldWithHistory { private final String myPropertyName; // API compatibility with 7.0.1 - @SuppressWarnings({"UnusedDeclaration"}) public TextFieldWithStoredHistory(@NonNls final String propertyName, boolean cropList) { this(propertyName); } @@ -35,6 +34,7 @@ public class TextFieldWithStoredHistory extends TextFieldWithHistory { reset(); } + @Override public void addCurrentTextToHistory() { super.addCurrentTextToHistory(); PropertiesComponent.getInstance().setValue(myPropertyName, StringUtil.join(getHistory(), "\n")); @@ -47,7 +47,7 @@ public class TextFieldWithStoredHistory extends TextFieldWithHistory { final String[] items = history.split("\n"); ArrayList result = new ArrayList<>(); for (String item : items) { - if (item != null && item.length() > 0) { + if (item != null && !item.isEmpty()) { result.add(item); } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java index 49c4f63fade5..c97a341efe92 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java @@ -341,9 +341,9 @@ public class FileTypesTest extends PlatformTestCase { myFileTypeManager.drainReDetectQueue(); log("T: ensureRedetected: drain. re-detect queue: "+myFileTypeManager.dumpReDetectQueue()); UIUtil.dispatchAllInvocationEvents(); - log("T: ensureRedetected: dispatch"); + log("T: ensureRedetected: dispatch. re-detect queue: "+myFileTypeManager.dumpReDetectQueue()); FileType type = vFile.getFileType(); - log("T: ensureRedetected: getFileType ("+type.getName()+")"); + log("T: ensureRedetected: getFileType ("+type.getName()+") re-detect queue: "+myFileTypeManager.dumpReDetectQueue()); assertTrue(detectorCalled.contains(vFile)); detectorCalled.clear(); log("T: ensureRedetected: clear"); diff --git a/platform/util/src/com/intellij/util/ObjectUtils.java b/platform/util/src/com/intellij/util/ObjectUtils.java index 3d1e3936bf0e..15c59a7675a7 100644 --- a/platform/util/src/com/intellij/util/ObjectUtils.java +++ b/platform/util/src/com/intellij/util/ObjectUtils.java @@ -51,7 +51,7 @@ public class ObjectUtils { @Contract("null,null->null") public static T coalesce(@Nullable T t1, @Nullable T t2) { - return t1 != null ? t1 : t2; + return chooseNotNull(t1, t2); } @Contract("null,null,null->null")