From 405223081db9da23ec24dfd3584bd40c77cf6a81 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 20 Dec 2017 15:13:12 +0100 Subject: [PATCH] =?UTF-8?q?UsageViewSettings=20=E2=80=94=20use=20BaseState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/unscramble/ThreadDumpPanel.java | 30 ++--------- .../usages/impl/rules/MethodGroupingRule.java | 16 +----- .../psi/usages/JavaUsageViewTreeTest.java | 12 +++-- .../FavoritesTreeViewPanel.java | 28 +--------- .../ExporterToTextFileHierarchy.java | 30 +---------- .../ui/DependenciesPanel.java | 16 ------ .../src/com/intellij/slicer/SlicePanel.java | 20 ++----- .../slicer/SliceToTextFileExporter.java | 34 ++---------- .../com/intellij/ide/ExporterToTextFile.java | 38 +++++++------- .../usages/impl/UsageViewTreeTest.java | 22 ++------ .../intellij/usages/ShowUsagesSettings.java | 24 ++++----- .../com/intellij/usages/UsageViewSettings.kt | 10 ++-- .../usages/impl/ExporterToTextFile.java | 34 ++---------- .../usages/impl/PreviewUsageAction.java | 18 ++----- .../impl/SortMembersAlphabeticallyAction.java | 19 ++----- .../impl/UsageGroupingRuleProviderImpl.java | 52 +++++++------------ .../intellij/usages/impl/UsageViewImpl.java | 10 ++-- 17 files changed, 99 insertions(+), 314 deletions(-) diff --git a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java index 5705fd5edd35..788e63162302 100644 --- a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java +++ b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.unscramble; @@ -47,14 +35,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.intellij.icons.AllIcons.Debugger.ThreadStates.*; @@ -413,17 +402,6 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { myThreadStates = threadStates; } - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException {} - - @Override - public void removeSettingsChangedListener(ChangeListener listener) {} - @NotNull @Override public String getReportText() { diff --git a/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java b/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java index 910dc6a36063..ac2533582b1f 100644 --- a/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java +++ b/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.usages.impl.rules; @@ -169,7 +157,7 @@ public class MethodGroupingRule extends SingleParentUsageGroupingRule { if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) { return 0; } - if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) { + if (!UsageViewSettings.getInstance().isSortAlphabetically()) { Segment segment1 = myMethodPointer.getRange(); Segment segment2 = other.myMethodPointer.getRange(); if (segment1 != null && segment2 != null) { diff --git a/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java b/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java index a5fe6d68bcc6..af5f8317edf7 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 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. +/* + * Copyright 2000-2017 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.java.psi.usages; import com.intellij.openapi.util.Disposer; @@ -23,10 +25,10 @@ public class JavaUsageViewTreeTest extends LightCodeInsightFixtureTestCase { XmlSerializerUtil.copyBean(settings.getState(), oldSettingsState); disposeOnTearDown(() -> settings.loadState(oldSettingsState)); - settings.GROUP_BY_MODULE = false; - settings.GROUP_BY_FILE_STRUCTURE = true; - settings.GROUP_BY_USAGE_TYPE = false; - settings.GROUP_BY_PACKAGE = false; + settings.setGroupByModule(false); + settings.setGroupByFileStructure(true); + settings.setGroupByUsageType(false); + settings.setGroupByPackage(false); } public void testSimpleModule() { diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java index 5cf59c0ed235..8da40f904d3d 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.ide.favoritesTreeView; @@ -68,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; @@ -258,19 +245,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider, Dock private ExporterToTextFile createTextExporter() { return new ExporterToTextFile() { - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java index 5095aa645704..1b4414bf9318 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.ide.hierarchy; @@ -20,11 +8,8 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import java.util.Enumeration; -import java.util.TooManyListenersException; class ExporterToTextFileHierarchy implements ExporterToTextFile { private static final Logger LOG = Logger.getInstance(ExporterToTextFileHierarchy.class); @@ -34,19 +19,6 @@ class ExporterToTextFileHierarchy implements ExporterToTextFile { myHierarchyBrowserBase = hierarchyBrowserBase; } - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java index 07e9ea32616b..2f40c8ebe8c3 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java @@ -60,7 +60,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeModel; @@ -673,22 +672,7 @@ public class DependenciesPanel extends JPanel implements Disposable, DataProvide } } - private class DependenciesExporterToTextFile implements ExporterToTextFile { - - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { diff --git a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java index 981e6170e451..708463faa7c5 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java +++ b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.slicer; @@ -143,7 +131,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.RIGHT)); boolean vertical = myToolWindow.getAnchor() == ToolWindowAnchor.LEFT || myToolWindow.getAnchor() == ToolWindowAnchor.RIGHT; - Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS); + Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().getPreviewUsagesSplitterProportion()); splitter.setFirstComponent(pane); myUsagePreviewPanel = new UsagePreviewPanel(myProject, new UsageViewPresentation()); myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT)); @@ -167,7 +155,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, @Override public void dispose() { if (myUsagePreviewPanel != null) { - UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS = ((Splitter)myUsagePreviewPanel.getParent()).getProportion(); + UsageViewSettings.getInstance().setPreviewUsagesSplitterProportion(((Splitter)myUsagePreviewPanel.getParent()).getProportion()); myUsagePreviewPanel = null; } @@ -175,7 +163,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, ToolTipManager.sharedInstance().unregisterComponent(myTree); } - class MultiLanguageTreeCellRenderer implements TreeCellRenderer { + static class MultiLanguageTreeCellRenderer implements TreeCellRenderer { @NotNull private final SliceUsageCellRendererBase rootRenderer; diff --git a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java index 106a544196a4..b08c55ca4a65 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java +++ b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.slicer; @@ -20,10 +8,7 @@ import com.intellij.usages.UsageViewSettings; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.ChangeListener; import java.util.List; -import java.util.TooManyListenersException; /** * @author nik @@ -36,19 +21,6 @@ public class SliceToTextFileExporter implements ExporterToTextFile { myBuilder = builder; } - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { @@ -78,12 +50,12 @@ public class SliceToTextFileExporter implements ExporterToTextFile { @NotNull @Override public String getDefaultFilePath() { - return UsageViewSettings.getInstance().EXPORT_FILE_NAME; + return UsageViewSettings.getInstance().getExportFileName(); } @Override public void exportedTo(String filePath) { - UsageViewSettings.getInstance().EXPORT_FILE_NAME = filePath; + UsageViewSettings.getInstance().setExportFileName(filePath); } @Override diff --git a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java index 4fdf61f1b2ba..90dc48cff6a1 100644 --- a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java +++ b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java @@ -1,32 +1,34 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.ide; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ChangeListener; import java.util.TooManyListenersException; public interface ExporterToTextFile { - JComponent getSettingsEditor(); - void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException; - void removeSettingsChangedListener(ChangeListener listener); - @NotNull String getReportText(); - @NotNull String getDefaultFilePath(); + @Nullable + default JComponent getSettingsEditor() { + return null; + } + + default void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { + } + + default void removeSettingsChangedListener(ChangeListener listener) { + } + + @NotNull + String getReportText(); + + @NotNull + String getDefaultFilePath(); + void exportedTo(String filePath); + boolean canExport(); } diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java index 2416f18b16e1..9d1927aaa7fd 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 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.usages.impl; @@ -61,9 +49,9 @@ public class UsageViewTreeTest extends UsefulTestCase { XmlSerializerUtil.copyBean(settings.getState(), oldSettingsState); disposeOnTearDown(() -> settings.loadState(oldSettingsState)); - settings.GROUP_BY_FILE_STRUCTURE = false; - settings.GROUP_BY_USAGE_TYPE = false; - settings.GROUP_BY_PACKAGE = false; + settings.setGroupByFileStructure(false); + settings.setGroupByUsageType(false); + settings.setGroupByPackage(false); } public void testSimpleModule() throws Exception { @@ -81,7 +69,7 @@ public class UsageViewTreeTest extends UsefulTestCase { addModule("xxx.main"); PsiFile file = myFixture.addFileToProject("xxx.main/A.txt", "hello"); Usage[] usages = {new UsageInfo2UsageAdapter(new UsageInfo(file))}; - UsageViewSettings.getInstance().FLATTEN_MODULES = false; + UsageViewSettings.getInstance().setFlattenModules(false); ModuleGroupTestsKt.runWithQualifiedModuleNamesEnabled(() -> { assertUsageViewStructureEquals(usages, "Usage (1 usage)\n" + " Non-code usages (1 usage)\n" + diff --git a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java index d3e2ecbc4d3b..d3c633dd6682 100644 --- a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java +++ b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 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. +/* + * Copyright 2000-2017 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.usages; import com.intellij.openapi.components.PersistentStateComponent; @@ -6,14 +8,10 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.xmlb.XmlSerializerUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@State( - name = "ShowUsagesSettings", - storages = { - @Storage("usageView.xml") - } -) +@State(name = "ShowUsagesSettings", storages = @Storage("usageView.xml")) public class ShowUsagesSettings implements PersistentStateComponent { private final UsageViewSettings myState = new UsageViewSettings(); @@ -24,7 +22,7 @@ public class ShowUsagesSettings implements PersistentStateComponent