Search in sources :

Example 16 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testCustomTokenSerializeLessThanDefault.

@Test
public void testCustomTokenSerializeLessThanDefault() throws IOException {
    final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibilityToken());
    final ArrayList<ArrangementGroupingRule> groupings = ContainerUtil.newArrayList(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
    final ArrayList<ArrangementSectionRule> rules = ContainerUtil.newArrayList(section(true, FIELD));
    final StdArrangementExtendableSettings settings = extendableSettings(groupings, rules, tokens);
    final Set<StdArrangementRuleAliasToken> defaultTokens = ContainerUtil.newHashSet(visibilityToken(), modifiersToken());
    final StdArrangementExtendableSettings defaultSettings = extendableSettings(groupings, rules, defaultTokens);
    final Element holder = doSerializationTest(settings, defaultSettings);
    final String expected = "<holder>\n" + "  <tokens>\n" + "    <token id=\"visibility\" name=\"visibility\">\n" + "      <rules>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PUBLIC>true</PUBLIC>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PROTECTED>true</PROTECTED>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PRIVATE>true</PRIVATE>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\n" + "      </rules>\n" + "    </token>\n" + "  </tokens>\n" + "</holder>";
    assertXmlOutputEquals(expected, holder);
}
Also used : StdArrangementRuleAliasToken(com.intellij.psi.codeStyle.arrangement.std.StdArrangementRuleAliasToken) ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) StdArrangementExtendableSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementExtendableSettings) Element(org.jdom.Element) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) Test(org.junit.Test)

Example 17 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testDefaultGroupingFilter.

@Test
public void testDefaultGroupingFilter() {
    final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME);
    final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
    final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
    final StdArrangementSettings settings = new StdArrangementSettings();
    settings.addGrouping(groupingRule);
    settings.addRule(rule);
    final StdArrangementSettings defaultSettings = new StdArrangementSettings();
    defaultSettings.addGrouping(groupingRule);
    final Element holder = doSerializationTest(settings, defaultSettings);
    assertTrue(holder.getChildren().size() == 1);
    assertNull(holder.getChild("groups"));
    assertNotNull(holder.getChild("rules"));
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 18 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testEmptyRules.

@Test
public void testEmptyRules() throws Exception {
    final StdArrangementSettings settings = new StdArrangementSettings();
    settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
    final StdArrangementSettings defaultSettings = new StdArrangementSettings();
    final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
    final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
    defaultSettings.addRule(rule);
    final Element holder = doSerializationTest(settings, defaultSettings);
    assertTrue(holder.getChildren().size() == 2);
    final Element rules = holder.getChild("rules");
    assertNotNull(rules);
    assertTrue(rules.getChildren().isEmpty());
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 19 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project android by JetBrains.

the class AndroidXmlPredefinedCodeStyle method apply.

@Override
public void apply(CodeStyleSettings settings) {
    final CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(XmlFileType.INSTANCE);
    indentOptions.CONTINUATION_INDENT_SIZE = indentOptions.INDENT_SIZE;
    XmlCodeStyleSettings xmlSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
    xmlSettings.XML_ALIGN_ATTRIBUTES = false;
    xmlSettings.XML_SPACE_INSIDE_EMPTY_TAG = true;
    xmlSettings.XML_KEEP_LINE_BREAKS = false;
    final AndroidXmlCodeStyleSettings androidSettings = AndroidXmlCodeStyleSettings.getInstance(settings);
    androidSettings.USE_CUSTOM_SETTINGS = true;
    androidSettings.LAYOUT_SETTINGS = new AndroidXmlCodeStyleSettings.LayoutSettings();
    androidSettings.MANIFEST_SETTINGS = new AndroidXmlCodeStyleSettings.ManifestSettings();
    androidSettings.VALUE_RESOURCE_FILE_SETTINGS = new AndroidXmlCodeStyleSettings.ValueResourceFileSettings();
    androidSettings.OTHER_SETTINGS = new AndroidXmlCodeStyleSettings.OtherSettings();
    // arrangement
    final List<StdArrangementMatchRule> rules = new ArrayList<StdArrangementMatchRule>();
    rules.add(attrArrangementRule("xmlns:android", "^$", KEEP));
    rules.add(attrArrangementRule("xmlns:.*", "^$", BY_NAME));
    rules.add(attrArrangementRule(".*:id", SdkConstants.NS_RESOURCES, KEEP));
    rules.add(attrArrangementRule(".*:name", SdkConstants.NS_RESOURCES, KEEP));
    rules.add(attrArrangementRule("name", "^$", KEEP));
    rules.add(attrArrangementRule("style", "^$", KEEP));
    rules.add(attrArrangementRule(".*", "^$", BY_NAME));
    rules.add(attrArrangementRule(".*:layout_width", SdkConstants.NS_RESOURCES, KEEP));
    rules.add(attrArrangementRule(".*:layout_height", SdkConstants.NS_RESOURCES, KEEP));
    rules.add(attrArrangementRule(".*:layout_.*", SdkConstants.NS_RESOURCES, BY_NAME));
    rules.add(attrArrangementRule(".*:width", SdkConstants.NS_RESOURCES, BY_NAME));
    rules.add(attrArrangementRule(".*:height", SdkConstants.NS_RESOURCES, BY_NAME));
    rules.add(attrArrangementRule(".*", SdkConstants.NS_RESOURCES, BY_NAME));
    rules.add(attrArrangementRule(".*", ".*", BY_NAME));
    // TODO: Should sort name:"color",namespace:"" to the end (primarily for color state lists)
    final CommonCodeStyleSettings xmlCommonSettings = settings.getCommonSettings(XMLLanguage.INSTANCE);
    xmlCommonSettings.setArrangementSettings(StdArrangementSettings.createByMatchRules(ContainerUtil.<ArrangementGroupingRule>emptyList(), rules));
    xmlCommonSettings.FORCE_REARRANGE_MODE = CommonCodeStyleSettings.REARRANGE_ALWAYS;
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) ArrayList(java.util.ArrayList) XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Aggregations

ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)19 Element (org.jdom.Element)12 Test (org.junit.Test)11 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)7 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)6 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)6 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)6 StdArrangementSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings)6 StdArrangementExtendableSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementExtendableSettings)5 StdArrangementRuleAliasToken (com.intellij.psi.codeStyle.arrangement.std.StdArrangementRuleAliasToken)5 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)2 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)2 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 FoldRegion (com.intellij.openapi.editor.FoldRegion)1 FoldingModel (com.intellij.openapi.editor.FoldingModel)1 TextRange (com.intellij.openapi.util.TextRange)1 ArrangementEngine (com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine)1