mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
Java: avoid changing code style api for import setting (IJ-CR-147745)
(cherry picked from commit b6d8223525eabd52a7973ef10927403063b3b89a) GitOrigin-RevId: 19da9f718812ff0f553d5363cd2b5ce6724e7f49
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2ec44412eb
commit
2ce2af7f8e
@@ -291,12 +291,10 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
|
||||
LAYOUT_STATIC_IMPORTS_SEPARATELY = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLayoutOnDemandImportFromSamePackageFirst() {
|
||||
return LAYOUT_ON_DEMAND_IMPORT_FROM_SAME_PACKAGE_FIRST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutOnDemandImportFromSamePackageFirst(boolean value) {
|
||||
this.LAYOUT_ON_DEMAND_IMPORT_FROM_SAME_PACKAGE_FIRST = value;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public abstract class CodeStyleImportsPanelBase extends JPanel {
|
||||
private final PackageEntryTable myPackageList = new PackageEntryTable();
|
||||
private final CodeStyleImportsBaseUI kotlinUI;
|
||||
private final JBTable myPackageTable;
|
||||
private final ImportLayoutPanel myImportLayoutPanel;
|
||||
protected final ImportLayoutPanel myImportLayoutPanel;
|
||||
|
||||
public CodeStyleImportsPanelBase() {
|
||||
myImportLayoutPanel = new ImportLayoutPanel() {
|
||||
myImportLayoutPanel = new ImportLayoutPanel(isShowLayoutOnDemandImportFromSamePackageFirstCheckbox()) {
|
||||
@Override
|
||||
public void refresh() {
|
||||
refreshTable(myPackageTable, myPackageList);
|
||||
@@ -63,7 +63,6 @@ public abstract class CodeStyleImportsPanelBase extends JPanel {
|
||||
myPackageList.copyFrom(settings.getPackagesToUseImportOnDemand());
|
||||
|
||||
myImportLayoutPanel.getCbLayoutStaticImportsSeparately().setSelected(settings.isLayoutStaticImportsSeparately());
|
||||
myImportLayoutPanel.getCbLayoutOnDemandImportsFromSamePackageFirst().setSelected(settings.isLayoutOnDemandImportFromSamePackageFirst());
|
||||
|
||||
final JBTable importLayoutTable = myImportLayoutPanel.getImportLayoutTable();
|
||||
AbstractTableModel model = (AbstractTableModel)importLayoutTable.getModel();
|
||||
@@ -84,7 +83,6 @@ public abstract class CodeStyleImportsPanelBase extends JPanel {
|
||||
stopTableEditing();
|
||||
|
||||
settings.setLayoutStaticImportsSeparately(myImportLayoutPanel.areStaticImportsEnabled());
|
||||
settings.setLayoutOnDemandImportFromSamePackageFirst(myImportLayoutPanel.isLayoutOnDemandImportsFromSamePackageFirst());
|
||||
kotlinUI.apply(settings);
|
||||
PackageEntryTable list = myImportLayoutPanel.getImportLayoutList();
|
||||
settings.getImportLayoutTable().copyFrom(getCopyWithoutEmptyPackages(list));
|
||||
@@ -93,7 +91,6 @@ public abstract class CodeStyleImportsPanelBase extends JPanel {
|
||||
|
||||
public boolean isModifiedLayoutSettings(ImportsLayoutSettings settings) {
|
||||
boolean isModified = isModified(myImportLayoutPanel.getCbLayoutStaticImportsSeparately(), settings.isLayoutStaticImportsSeparately());
|
||||
isModified |= isModified(myImportLayoutPanel.getCbLayoutOnDemandImportsFromSamePackageFirst(), settings.isLayoutOnDemandImportFromSamePackageFirst());
|
||||
isModified |= kotlinUI.isModified(settings);
|
||||
|
||||
PackageEntryTable list = myImportLayoutPanel.getImportLayoutList();
|
||||
@@ -138,4 +135,8 @@ public abstract class CodeStyleImportsPanelBase extends JPanel {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isShowLayoutOnDemandImportFromSamePackageFirstCheckbox() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,7 @@ import java.awt.*;
|
||||
public abstract class ImportLayoutPanel extends JPanel {
|
||||
private final JBCheckBox myCbLayoutStaticImportsSeparately =
|
||||
new JBCheckBox(JavaBundle.message("import.layout.static.imports.separately"));
|
||||
private final JBCheckBox myCbLayoutOnDemandImportsFromSamePackageFirst =
|
||||
new JBCheckBox(JavaBundle.message("import.layout.on.demand.import.from.same.package.first"));
|
||||
@Nullable private final JBCheckBox myCbLayoutOnDemandImportsFromSamePackageFirst;
|
||||
private final JBTable myImportLayoutTable;
|
||||
|
||||
private final PackageEntryTable myImportLayoutList = new PackageEntryTable();
|
||||
@@ -55,11 +54,12 @@ public abstract class ImportLayoutPanel extends JPanel {
|
||||
return myCbLayoutStaticImportsSeparately;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JBCheckBox getCbLayoutOnDemandImportsFromSamePackageFirst() {
|
||||
return myCbLayoutOnDemandImportsFromSamePackageFirst;
|
||||
}
|
||||
|
||||
public ImportLayoutPanel() {
|
||||
public ImportLayoutPanel(boolean showLayoutOnDemandImportFromSamePackageFirstCheckbox) {
|
||||
super(new BorderLayout());
|
||||
|
||||
myCbLayoutStaticImportsSeparately.addItemListener(e -> {
|
||||
@@ -114,6 +114,10 @@ public abstract class ImportLayoutPanel extends JPanel {
|
||||
.setPreferredSize(new Dimension(-1, JBUI.scale(180)))
|
||||
.createPanel();
|
||||
|
||||
myCbLayoutOnDemandImportsFromSamePackageFirst =
|
||||
showLayoutOnDemandImportFromSamePackageFirstCheckbox
|
||||
? new JBCheckBox(JavaBundle.message("import.layout.on.demand.import.from.same.package.first"))
|
||||
: null;
|
||||
final ImportLayoutPanelUI UI = new ImportLayoutPanelUI(myCbLayoutStaticImportsSeparately,
|
||||
myCbLayoutOnDemandImportsFromSamePackageFirst,
|
||||
importLayoutPanel);
|
||||
@@ -224,7 +228,7 @@ public abstract class ImportLayoutPanel extends JPanel {
|
||||
}
|
||||
|
||||
public boolean isLayoutOnDemandImportsFromSamePackageFirst() {
|
||||
return myCbLayoutOnDemandImportsFromSamePackageFirst.isSelected();
|
||||
return myCbLayoutOnDemandImportsFromSamePackageFirst != null && myCbLayoutOnDemandImportsFromSamePackageFirst.isSelected();
|
||||
}
|
||||
|
||||
public static JBTable createTableForPackageEntries(final PackageEntryTable packageTable, final ImportLayoutPanel panel) {
|
||||
|
||||
@@ -7,10 +7,10 @@ import com.intellij.ui.dsl.builder.Align
|
||||
import com.intellij.ui.dsl.builder.panel
|
||||
import javax.swing.JPanel
|
||||
|
||||
internal class ImportLayoutPanelUI(staticImportsCb: JBCheckBox, onDemandBeforeSingleClassCb: JBCheckBox, importLayoutPanel: JPanel) {
|
||||
internal class ImportLayoutPanelUI(staticImportsCb: JBCheckBox, onDemandBeforeSingleClassCb: JBCheckBox?, importLayoutPanel: JPanel) {
|
||||
val panel = panel {
|
||||
group(JavaBundle.message("title.import.layout")) {
|
||||
row { cell(onDemandBeforeSingleClassCb) }
|
||||
if (onDemandBeforeSingleClassCb != null) row { cell(onDemandBeforeSingleClassCb) }
|
||||
row { cell(staticImportsCb) }
|
||||
row { cell(importLayoutPanel).align(Align.FILL) }.resizableRow()
|
||||
}.resizableRow()
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
@@ -52,6 +53,7 @@ class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
|
||||
applyLayoutSettings(javaSettings);
|
||||
myFqnInJavadocOption.apply(settings);
|
||||
javaSettings.setDoNotImportInner(getInnerClassesNames());
|
||||
javaSettings.setLayoutOnDemandImportFromSamePackageFirst(myImportLayoutPanel.isLayoutOnDemandImportsFromSamePackageFirst());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,6 +64,8 @@ class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
|
||||
for (String name : javaSettings.getDoNotImportInner()) {
|
||||
doNotInsertInnerListModel.addRow(new InnerClassItem(name));
|
||||
}
|
||||
JBCheckBox checkBox = myImportLayoutPanel.getCbLayoutOnDemandImportsFromSamePackageFirst();
|
||||
if (checkBox != null) checkBox.setSelected(javaSettings.isLayoutOnDemandImportFromSamePackageFirst());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,6 +74,8 @@ class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
|
||||
boolean isModified = isModifiedLayoutSettings(javaSettings);
|
||||
isModified |= myFqnInJavadocOption.isModified(settings);
|
||||
isModified |= !javaSettings.getDoNotImportInner().equals(getInnerClassesNames());
|
||||
JBCheckBox checkBox = myImportLayoutPanel.getCbLayoutOnDemandImportsFromSamePackageFirst();
|
||||
if (checkBox != null) isModified |= isModified(checkBox, javaSettings.isLayoutOnDemandImportFromSamePackageFirst());
|
||||
return isModified;
|
||||
}
|
||||
|
||||
@@ -96,6 +102,11 @@ class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isShowLayoutOnDemandImportFromSamePackageFirstCheckbox() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private abstract static class MyColumnInfo extends ColumnInfo<InnerClassItem, String> {
|
||||
MyColumnInfo(final @NlsContexts.ColumnName String name) {
|
||||
super(name);
|
||||
|
||||
@@ -974,13 +974,11 @@ com.intellij.psi.codeStyle.ImportsLayoutSettings
|
||||
- a:getNamesCountToUseImportOnDemand():I
|
||||
- a:getPackagesToUseImportOnDemand():com.intellij.psi.codeStyle.PackageEntryTable
|
||||
- a:isInsertInnerClassImports():Z
|
||||
- isLayoutOnDemandImportFromSamePackageFirst():Z
|
||||
- a:isLayoutStaticImportsSeparately():Z
|
||||
- a:isUseFqClassNames():Z
|
||||
- a:isUseSingleClassImports():Z
|
||||
- a:setClassCountToUseImportOnDemand(I):V
|
||||
- a:setInsertInnerClassImports(Z):V
|
||||
- setLayoutOnDemandImportFromSamePackageFirst(Z):V
|
||||
- a:setLayoutStaticImportsSeparately(Z):V
|
||||
- a:setNamesCountToUseImportOnDemand(I):V
|
||||
- a:setUseFqClassNames(Z):V
|
||||
|
||||
@@ -4,8 +4,6 @@ package com.intellij.psi.codeStyle;
|
||||
public interface ImportsLayoutSettings {
|
||||
boolean isLayoutStaticImportsSeparately();
|
||||
void setLayoutStaticImportsSeparately(boolean value);
|
||||
default boolean isLayoutOnDemandImportFromSamePackageFirst() { return false; }
|
||||
default void setLayoutOnDemandImportFromSamePackageFirst(boolean value) {}
|
||||
int getNamesCountToUseImportOnDemand();
|
||||
void setNamesCountToUseImportOnDemand(int value);
|
||||
int getClassCountToUseImportOnDemand();
|
||||
|
||||
Reference in New Issue
Block a user