diff --git a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/codeStyle/PropertiesCodeStyleSettingsPanel.java b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/codeStyle/PropertiesCodeStyleSettingsPanel.java index c78a980720ad..27a27ff6928b 100644 --- a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/codeStyle/PropertiesCodeStyleSettingsPanel.java +++ b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/codeStyle/PropertiesCodeStyleSettingsPanel.java @@ -44,7 +44,7 @@ public class PropertiesCodeStyleSettingsPanel extends OptionTableWithPreviewPane @Override protected void initTables() { addOption("ALIGN_GROUP_FIELD_DECLARATIONS", "Align properties in column"); - showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS", "ALIGN_GROUP_FIELD_DECLARATIONS"); + showStandardOptions("ALIGN_GROUP_FIELD_DECLARATIONS"); showCustomOption(PropertiesCodeStyleSettings.class, "SPACES_AROUND_KEY_VALUE_DELIMITER", "Insert space around key-value delimiter", null); showCustomOption(PropertiesCodeStyleSettings.class, diff --git a/plugins/properties/src/com/intellij/lang/properties/formatting/PropertiesRootBlock.java b/plugins/properties/src/com/intellij/lang/properties/formatting/PropertiesRootBlock.java index ff5ad14e4aef..8d82813dcbaa 100644 --- a/plugins/properties/src/com/intellij/lang/properties/formatting/PropertiesRootBlock.java +++ b/plugins/properties/src/com/intellij/lang/properties/formatting/PropertiesRootBlock.java @@ -15,10 +15,7 @@ */ package com.intellij.lang.properties.formatting; -import com.intellij.formatting.Alignment; -import com.intellij.formatting.Block; -import com.intellij.formatting.Spacing; -import com.intellij.formatting.Wrap; +import com.intellij.formatting.*; import com.intellij.lang.ASTNode; import com.intellij.lang.properties.parsing.PropertiesTokenTypes; import com.intellij.lang.properties.parsing.PropertyListStubElementType; @@ -96,6 +93,9 @@ public class PropertiesRootBlock extends AbstractBlock { @Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { + if (child1 == null) { + return null; + } return mySettings.getCustomSettings(PropertiesCodeStyleSettings.class).SPACES_AROUND_KEY_VALUE_DELIMITER && (child1 instanceof SeparatorBlock || child2 instanceof SeparatorBlock) ? Spacing.createSpacing(1, 1, 0, true, 0) diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFormatterTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFormatterTest.java new file mode 100644 index 000000000000..292816d384cd --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFormatterTest.java @@ -0,0 +1,94 @@ +/* + * 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. + */ +package com.intellij.lang.properties; + +import com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.formatter.FormatterTestCase; + + +/** + * @author Dmitry Batkovich + */ +public class PropertiesFormatterTest extends FormatterTestCase { + private CommonCodeStyleSettings mySettings; + private PropertiesCodeStyleSettings myCustomSettings; + + @Override + public void setUp() throws Exception { + super.setUp(); + final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + mySettings = settings.getCommonSettings(PropertiesLanguage.INSTANCE); + myCustomSettings = settings.getCustomSettings(PropertiesCodeStyleSettings.class); + mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = false; + myCustomSettings.SPACES_AROUND_KEY_VALUE_DELIMITER = false; + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSimple1() { + doTextTest("\n\n" + + "qwe=asd\n" + + "#comment\n" + + " key1 = value1", + + "qwe=asd\n" + + "#comment\n" + + "key1=value1"); + } + + public void testSimple2() { + mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = true; + doTextTest(" qwe_very_big_property = asd\n" + + "#comment\n" + + " key1 = value1", + + "qwe_very_big_property=asd\n" + + "#comment\n" + + "key1 =value1"); + } + + public void testSimple3() { + mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = true; + myCustomSettings.SPACES_AROUND_KEY_VALUE_DELIMITER = true; + doTextTest(" qwe_very_big_property = asd\n" + + "#comment\n" + + " key1 = value1", + + "qwe_very_big_property = asd\n" + + "#comment\n" + + "key1 = value1"); + } + + protected void doTextTest(String text) { + doTextTest(text, text); + } + + @Override + protected String getBasePath() { + return ""; + } + + @Override + protected String getFileExtension() { + return PropertiesFileType.DEFAULT_EXTENSION; + } +}