mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Optionally generate commented out properties
GitOrigin-RevId: feafd56337722a07e1eaf3ad168650083d80b3d2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
31174bc27f
commit
e26683f4e9
@@ -211,4 +211,5 @@ export.topmost.file=Topmost file (root = true)
|
||||
export.properties.title=Properties
|
||||
export.properties.standard=EditorConfig Standard
|
||||
export.properties.intellij=IntelliJ IDEA-specific
|
||||
export.languages.title=Languages
|
||||
export.languages.title=Languages
|
||||
export.comment.out.properties=Comment out properties initially
|
||||
+7
-2
@@ -52,7 +52,11 @@ public class CreateEditorConfigAction extends AnAction implements DumbAware {
|
||||
final VirtualFile dirVFile = dir.getVirtualFile();
|
||||
File outputFile = getOutputFile(dirVFile);
|
||||
if (!outputFile.exists()) {
|
||||
if (export(outputFile, project, settings, dialog.isRoot(), dialog.getLanguages(), dialog.getPropertyKinds())) {
|
||||
if (export(outputFile, project, settings,
|
||||
dialog.isRoot(),
|
||||
dialog.isCommentProperties(),
|
||||
dialog.getLanguages(),
|
||||
dialog.getPropertyKinds())) {
|
||||
VirtualFile outputVFile = VfsUtil.findFileByIoFile(outputFile, true);
|
||||
if (outputVFile != null) {
|
||||
OpenFileAction.openFile(outputVFile, project);
|
||||
@@ -109,12 +113,13 @@ public class CreateEditorConfigAction extends AnAction implements DumbAware {
|
||||
@NotNull Project project,
|
||||
@NotNull CodeStyleSettings settings,
|
||||
boolean isRoot,
|
||||
boolean commentOutProperties,
|
||||
@NotNull List<Language> languages,
|
||||
@NotNull EditorConfigPropertyKind... propertyKinds) {
|
||||
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
|
||||
try (
|
||||
EditorConfigSettingsWriter settingsWriter =
|
||||
new EditorConfigSettingsWriter(project, outputStream, settings, isRoot)
|
||||
new EditorConfigSettingsWriter(project, outputStream, settings, isRoot, commentOutProperties)
|
||||
.forLanguages(languages)
|
||||
.forPropertyKinds(propertyKinds)) {
|
||||
settingsWriter.writeSettings();
|
||||
|
||||
+4
@@ -44,6 +44,10 @@ public class CreateEditorConfigDialog extends DialogWrapper {
|
||||
return myForm.isRoot();
|
||||
}
|
||||
|
||||
public boolean isCommentProperties() {
|
||||
return myForm.isCommentProperties();
|
||||
}
|
||||
|
||||
public List<Language> getLanguages() {
|
||||
return myForm.getSelectedLanguages();
|
||||
}
|
||||
|
||||
+9
@@ -62,6 +62,15 @@
|
||||
<border type="none" title="Languages"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="c7abf" class="com.intellij.ui.components.JBCheckBox" binding="myCommentProperties">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text resource-bundle="messages/EditorConfigBundle" key="export.comment.out.properties"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+11
-3
@@ -21,8 +21,9 @@ public class CreateEditorConfigForm {
|
||||
private JBCheckBox myStandardPropertiesCb;
|
||||
private JBCheckBox myIntelliJPropertiesCb;
|
||||
private JBCheckBox myRootCb;
|
||||
private JPanel myPropertiesPanel;
|
||||
private JPanel myLanguagesPanel;
|
||||
private JPanel myPropertiesPanel;
|
||||
private JPanel myLanguagesPanel;
|
||||
private JBCheckBox myCommentProperties;
|
||||
|
||||
private final List<LanguageCheckBoxRec> myLanguageCheckBoxes;
|
||||
|
||||
@@ -34,6 +35,7 @@ public class CreateEditorConfigForm {
|
||||
myLanguagesPanel.setLayout(new BoxLayout(myLanguagesPanel, BoxLayout.X_AXIS));
|
||||
myLanguageCheckBoxes = creteLanguageCheckBoxes(myLanguagesPanel);
|
||||
setLanguagePanelEnabled(false);
|
||||
myCommentProperties.setEnabled(false);
|
||||
myIntelliJPropertiesCb.addActionListener(new LanguagePanelEnabler());
|
||||
myStandardPropertiesCb.addActionListener(new LanguagePanelEnabler());
|
||||
}
|
||||
@@ -41,7 +43,9 @@ public class CreateEditorConfigForm {
|
||||
private class LanguagePanelEnabler implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setLanguagePanelEnabled(myIntelliJPropertiesCb.isSelected() || myStandardPropertiesCb.isSelected());
|
||||
final boolean addProperties = myIntelliJPropertiesCb.isSelected() || myStandardPropertiesCb.isSelected();
|
||||
setLanguagePanelEnabled(addProperties);
|
||||
myCommentProperties.setEnabled(addProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +110,10 @@ public class CreateEditorConfigForm {
|
||||
.map(rec -> rec.myLanguage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean isCommentProperties() {
|
||||
return myCommentProperties.isSelected();
|
||||
}
|
||||
|
||||
private static class LanguageCheckBoxRec {
|
||||
private final Language myLanguage;
|
||||
private final JCheckBox myCheckBox;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class EditorConfigExporter extends SchemeExporter<CodeStyleScheme> {
|
||||
@NotNull CodeStyleScheme scheme,
|
||||
@NotNull OutputStream outputStream) throws Exception {
|
||||
final CodeStyleSettings settings = scheme.getCodeStyleSettings();
|
||||
try (EditorConfigSettingsWriter writer = new EditorConfigSettingsWriter(project, outputStream, settings, false)) {
|
||||
try (EditorConfigSettingsWriter writer = new EditorConfigSettingsWriter(project, outputStream, settings, false, false)) {
|
||||
writer.writeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-5
@@ -33,6 +33,7 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
private final @Nullable Project myProject;
|
||||
private final Map<String, String> myGeneralOptions = new HashMap<>();
|
||||
private final boolean myAddRootFlag;
|
||||
private final boolean myCommentOutProperties;
|
||||
|
||||
private final static Comparator<OutPair> PAIR_COMPARATOR = (pair1, pair2) -> {
|
||||
EditorConfigPropertyKind pKind1 = getPropertyKind(pair1.getKey());
|
||||
@@ -46,11 +47,16 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
private final Set<EditorConfigPropertyKind> myPropertyKinds = EnumSet.allOf(EditorConfigPropertyKind.class);
|
||||
// endregion
|
||||
|
||||
public EditorConfigSettingsWriter(@Nullable Project project, @NotNull OutputStream out, CodeStyleSettings settings, boolean isRoot) {
|
||||
public EditorConfigSettingsWriter(@Nullable Project project,
|
||||
@NotNull OutputStream out,
|
||||
CodeStyleSettings settings,
|
||||
boolean isRoot,
|
||||
boolean commentOutProperties) {
|
||||
super(out, StandardCharsets.UTF_8);
|
||||
mySettings = settings;
|
||||
myProject = project;
|
||||
myAddRootFlag = isRoot;
|
||||
myCommentOutProperties = commentOutProperties;
|
||||
fillGeneralOptions();
|
||||
}
|
||||
|
||||
@@ -97,7 +103,7 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
|
||||
public void writeSettings() throws IOException {
|
||||
if (myAddRootFlag) {
|
||||
writeProperties(Collections.singletonList(new OutPair("root", "true")));
|
||||
writeProperties(Collections.singletonList(new OutPair("root", "true")), false);
|
||||
write("\n");
|
||||
}
|
||||
writeGeneralSection();
|
||||
@@ -130,7 +136,7 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
.map(key -> new OutPair(key, myGeneralOptions.get(key)))
|
||||
.filter(pair -> isNameAllowed(pair.getKey()))
|
||||
.sorted(PAIR_COMPARATOR).collect(Collectors.toList());
|
||||
writeProperties(pairs);
|
||||
writeProperties(pairs, myCommentOutProperties);
|
||||
}
|
||||
|
||||
private boolean writeLangSection(@NotNull LanguageCodeStylePropertyMapper mapper, @Nullable String pattern) throws IOException {
|
||||
@@ -142,7 +148,7 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
write("\n[" + pattern + "]\n");
|
||||
}
|
||||
Collections.sort(optionValueList, PAIR_COMPARATOR);
|
||||
writeProperties(optionValueList);
|
||||
writeProperties(optionValueList, myCommentOutProperties);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -185,8 +191,11 @@ public class EditorConfigSettingsWriter extends OutputStreamWriter {
|
||||
return value != null && !value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private void writeProperties(@NotNull List<OutPair> outPairs) throws IOException {
|
||||
private void writeProperties(@NotNull List<OutPair> outPairs, boolean commentOut) throws IOException {
|
||||
for (OutPair pair : outPairs) {
|
||||
if (commentOut) {
|
||||
write("# ");
|
||||
}
|
||||
write(pair.getKey() + " = " + pair.getVal() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
+29
-3
@@ -17,7 +17,7 @@ public class EditorConfigExportTest extends LightPlatformTestCase {
|
||||
setting.LINE_SEPARATOR = LineSeparator.CRLF.getSeparatorString();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try (EditorConfigSettingsWriter writer =
|
||||
new EditorConfigSettingsWriter(getProject(), output, setting, false)
|
||||
new EditorConfigSettingsWriter(getProject(), output, setting, false, false)
|
||||
.forLanguages(EditorConfigLanguage.INSTANCE, XMLLanguage.INSTANCE)) {
|
||||
writer.writeSettings();
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class EditorConfigExportTest extends LightPlatformTestCase {
|
||||
CodeStyleSettings setting = CodeStyleSettings.getDefaults().clone();
|
||||
setting.LINE_SEPARATOR = LineSeparator.CRLF.getSeparatorString();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try (EditorConfigSettingsWriter writer = new EditorConfigSettingsWriter(getProject(), output, setting, false)
|
||||
try (EditorConfigSettingsWriter writer = new EditorConfigSettingsWriter(getProject(), output, setting, false, false)
|
||||
.forLanguages(EditorConfigLanguage.INSTANCE, XMLLanguage.INSTANCE)
|
||||
.forPropertyKinds(EditorConfigPropertyKind.EDITOR_CONFIG_STANDARD)) {
|
||||
writer.writeSettings();
|
||||
@@ -83,7 +83,7 @@ public class EditorConfigExportTest extends LightPlatformTestCase {
|
||||
setting.LINE_SEPARATOR = LineSeparator.CRLF.getSeparatorString();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try (EditorConfigSettingsWriter writer =
|
||||
new EditorConfigSettingsWriter(getProject(), output, setting, true)
|
||||
new EditorConfigSettingsWriter(getProject(), output, setting, true, false)
|
||||
.forLanguages(EditorConfigLanguage.INSTANCE)
|
||||
.forPropertyKinds(EditorConfigPropertyKind.EDITOR_CONFIG_STANDARD)) {
|
||||
writer.writeSettings();
|
||||
@@ -104,4 +104,30 @@ public class EditorConfigExportTest extends LightPlatformTestCase {
|
||||
result);
|
||||
}
|
||||
|
||||
public void testCommentedOut() throws IOException {
|
||||
CodeStyleSettings setting = CodeStyleSettings.getDefaults().clone();
|
||||
setting.LINE_SEPARATOR = LineSeparator.CRLF.getSeparatorString();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try (EditorConfigSettingsWriter writer =
|
||||
new EditorConfigSettingsWriter(getProject(), output, setting, true, true)
|
||||
.forLanguages(EditorConfigLanguage.INSTANCE)
|
||||
.forPropertyKinds(EditorConfigPropertyKind.EDITOR_CONFIG_STANDARD)) {
|
||||
writer.writeSettings();
|
||||
}
|
||||
String result = output.toString("UTF-8");
|
||||
assertEquals(
|
||||
"root = true\n" +
|
||||
"\n" +
|
||||
"[*]\n" +
|
||||
"# charset = utf-8\n" +
|
||||
"# end_of_line = crlf\n" +
|
||||
"# indent_size = 4\n" +
|
||||
"# indent_style = space\n" +
|
||||
"# insert_final_newline = false\n" +
|
||||
"# max_line_length = 120\n" +
|
||||
"# tab_width = 4\n",
|
||||
|
||||
result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user