From e8c43d33fd9b4fe232c1dab7c32e7c40707b56b2 Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Thu, 6 Sep 2018 20:43:29 +0300 Subject: [PATCH] Make ArrangementSettingsPanel not abstract because all its implementations are equal, and all abstract methods were useless anyway because Arrangement tab contains no text preview. --- .../options/JavaArrangementPanel.java | 50 ------------------- .../options/JavaCodeStyleMainPanel.java | 20 ++------ .../arrangement/ArrangementSettingsPanel.java | 43 +++++++++------- .../options/HtmlCodeStyleMainPanel.java | 21 ++------ .../options/XmlCodeStyleMainPanel.java | 21 ++------ .../xml/arrangement/XmlArrangementPanel.java | 35 ------------- 6 files changed, 34 insertions(+), 156 deletions(-) delete mode 100644 java/java-impl/src/com/intellij/application/options/JavaArrangementPanel.java delete mode 100644 xml/impl/src/com/intellij/xml/arrangement/XmlArrangementPanel.java diff --git a/java/java-impl/src/com/intellij/application/options/JavaArrangementPanel.java b/java/java-impl/src/com/intellij/application/options/JavaArrangementPanel.java deleted file mode 100644 index 00739c884670..000000000000 --- a/java/java-impl/src/com/intellij/application/options/JavaArrangementPanel.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2000-2012 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. - */ -package com.intellij.application.options; - -import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel; -import com.intellij.ide.highlighter.JavaFileType; -import com.intellij.lang.java.JavaLanguage; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import org.jetbrains.annotations.NotNull; - -/** - * @author Denis Zhdanov - * @since 8/8/12 8:57 AM - */ -public class JavaArrangementPanel extends ArrangementSettingsPanel { - - public JavaArrangementPanel(@NotNull CodeStyleSettings settings) { - super(settings, JavaLanguage.INSTANCE); - } - - @Override - protected int getRightMargin() { - return 80; - } - - @NotNull - @Override - protected FileType getFileType() { - return JavaFileType.INSTANCE; - } - - @Override - protected String getPreviewText() { - return null; - } -} diff --git a/java/java-impl/src/com/intellij/application/options/JavaCodeStyleMainPanel.java b/java/java-impl/src/com/intellij/application/options/JavaCodeStyleMainPanel.java index b264f3266a9c..1789dcfc3cbd 100644 --- a/java/java-impl/src/com/intellij/application/options/JavaCodeStyleMainPanel.java +++ b/java/java-impl/src/com/intellij/application/options/JavaCodeStyleMainPanel.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2012 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-2018 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.application.options; +import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.extensions.Extensions; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -34,12 +21,11 @@ public class JavaCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { super.initTabs(settings); addTab(new JavaDocFormattingPanel(settings)); addTab(new CodeStyleImportsPanelWrapper(settings)); - addTab(new JavaArrangementPanel(settings)); + addTab(new ArrangementSettingsPanel(settings, JavaLanguage.INSTANCE)); for (CodeStyleSettingsProvider provider : Extensions.getExtensions(CodeStyleSettingsProvider.EXTENSION_POINT_NAME)) { if (provider.getLanguage() == JavaLanguage.INSTANCE && !provider.hasSettingsPage()) { createTab(provider); } } } - } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/ArrangementSettingsPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/ArrangementSettingsPanel.java index eb46480089f3..2a70321df580 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/ArrangementSettingsPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/ArrangementSettingsPanel.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2012 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-2018 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.application.options.codeStyle.arrangement; import com.intellij.application.options.CodeStyleAbstractPanel; @@ -23,8 +9,11 @@ import com.intellij.application.options.codeStyle.arrangement.group.ArrangementG import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesPanel; import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationBundle; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.highlighter.EditorHighlighter; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.util.Comparing; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; @@ -32,6 +21,7 @@ import com.intellij.psi.codeStyle.arrangement.Rearranger; import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule; import com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule; import com.intellij.psi.codeStyle.arrangement.std.*; +import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtilRt; import com.intellij.util.ui.GridBag; import org.jetbrains.annotations.NotNull; @@ -48,7 +38,7 @@ import java.util.List; * @author Denis Zhdanov * @since 10/30/12 5:17 PM */ -public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel { +public class ArrangementSettingsPanel extends CodeStyleAbstractPanel { @NotNull private final JPanel myContent = new JPanel(new GridBagLayout()); @@ -85,8 +75,6 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel { myContent.add(myGroupingRulesPanel, new GridBag().coverLine().fillCellHorizontally().weightx(1)); myContent.add(myMatchingRulesPanel, new GridBag().fillCell().weightx(1).weighty(1).coverLine()); - - if (settings.getCommonSettings(myLanguage).isForceArrangeMenuAvailable()) { myForceArrangementPanel = new ForceArrangementPanel(); myForceArrangementPanel.setSelectedMode(settings.getCommonSettings(language).FORCE_REARRANGE_MODE); @@ -182,4 +170,23 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel { protected String getTabTitle() { return ApplicationBundle.message("arrangement.title.settings.tab"); } + + @Nullable + @Override + protected String getPreviewText() { + return null; + } + + @Override + protected int getRightMargin() { + Logger.getInstance(ArrangementSettingsPanel.class).error("This method should not be called because getPreviewText() returns null"); + return 0; + } + + @NotNull + @Override + protected FileType getFileType() { + Logger.getInstance(ArrangementSettingsPanel.class).error("This method should not be called because getPreviewText() returns null"); + return ObjectUtils.notNull(myLanguage.getAssociatedFileType(), FileTypes.UNKNOWN); + } } diff --git a/xml/impl/src/com/intellij/application/options/HtmlCodeStyleMainPanel.java b/xml/impl/src/com/intellij/application/options/HtmlCodeStyleMainPanel.java index f4fa53b85b37..0837cf3783f1 100644 --- a/xml/impl/src/com/intellij/application/options/HtmlCodeStyleMainPanel.java +++ b/xml/impl/src/com/intellij/application/options/HtmlCodeStyleMainPanel.java @@ -1,24 +1,9 @@ -/* - * Copyright 2000-2014 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-2018 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.application.options; -import com.intellij.ide.highlighter.HtmlFileType; +import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel; import com.intellij.lang.html.HTMLLanguage; import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.xml.arrangement.XmlArrangementPanel; /** * @author Rustam Vishnyakov @@ -32,6 +17,6 @@ public class HtmlCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { protected void initTabs(CodeStyleSettings settings) { addIndentOptionsTab(settings); addTab(new CodeStyleHtmlPanel(settings)); - addTab(new XmlArrangementPanel(settings, HTMLLanguage.INSTANCE, HtmlFileType.INSTANCE)); + addTab(new ArrangementSettingsPanel(settings, HTMLLanguage.INSTANCE)); } } diff --git a/xml/impl/src/com/intellij/application/options/XmlCodeStyleMainPanel.java b/xml/impl/src/com/intellij/application/options/XmlCodeStyleMainPanel.java index 27b1d55351c3..8633b1501245 100644 --- a/xml/impl/src/com/intellij/application/options/XmlCodeStyleMainPanel.java +++ b/xml/impl/src/com/intellij/application/options/XmlCodeStyleMainPanel.java @@ -1,26 +1,11 @@ -/* - * Copyright 2000-2011 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-2018 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.application.options; -import com.intellij.ide.highlighter.XmlFileType; +import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel; import com.intellij.lang.xml.XMLLanguage; import com.intellij.openapi.extensions.Extensions; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; -import com.intellij.xml.arrangement.XmlArrangementPanel; /** * @author Rustam Vishnyakov @@ -34,7 +19,7 @@ public class XmlCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { protected void initTabs(CodeStyleSettings settings) { addIndentOptionsTab(settings); addTab(new CodeStyleXmlPanel(settings)); - addTab(new XmlArrangementPanel(settings, XMLLanguage.INSTANCE, XmlFileType.INSTANCE)); + addTab(new ArrangementSettingsPanel(settings, XMLLanguage.INSTANCE)); for (CodeStyleSettingsProvider provider : Extensions.getExtensions(CodeStyleSettingsProvider.EXTENSION_POINT_NAME)) { if (provider.getLanguage() == XMLLanguage.INSTANCE && !provider.hasSettingsPage()) { diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementPanel.java b/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementPanel.java deleted file mode 100644 index 6d8bb287e089..000000000000 --- a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementPanel.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.intellij.xml.arrangement; - -import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel; -import com.intellij.lang.xml.XMLLanguage; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import org.jetbrains.annotations.NotNull; - -/** - * @author Eugene.Kudelevsky - */ -public class XmlArrangementPanel extends ArrangementSettingsPanel { - private final FileType myFileType; - - public XmlArrangementPanel(@NotNull CodeStyleSettings settings, XMLLanguage language, FileType fileType) { - super(settings, language); - myFileType = fileType; - } - - @Override - protected int getRightMargin() { - return 80; - } - - @NotNull - @Override - protected FileType getFileType() { - return myFileType; - } - - @Override - protected String getPreviewText() { - return null; - } -}