Search in sources :

Example 1 with ArrangementSectionRule

use of com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule in project intellij-community by JetBrains.

the class StdArrangementExtendableSettings method getExtendedSectionRules.

@Override
public List<ArrangementSectionRule> getExtendedSectionRules() {
    synchronized (myExtendedSectionRules) {
        if (myExtendedSectionRules.isEmpty()) {
            final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition = new THashMap<>(myRulesAliases.size());
            for (StdArrangementRuleAliasToken alias : myRulesAliases) {
                final String id = alias.getId();
                tokenIdToDefinition.put(id, alias);
            }
            final List<ArrangementSectionRule> sections = getSections();
            for (ArrangementSectionRule section : sections) {
                final List<StdArrangementMatchRule> extendedRules = new ArrayList<>();
                for (StdArrangementMatchRule rule : section.getMatchRules()) {
                    appendExpandedRules(rule, extendedRules, tokenIdToDefinition);
                }
                myExtendedSectionRules.add(ArrangementSectionRule.create(section.getStartComment(), section.getEndComment(), extendedRules));
            }
        }
    }
    return myExtendedSectionRules;
}
Also used : THashMap(gnu.trove.THashMap) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 2 with ArrangementSectionRule

use of com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testCustomTokenSerializeAndDeserialize.

@Test
public void testCustomTokenSerializeAndDeserialize() {
    final StdArrangementRuleAliasToken visibility = visibilityToken();
    final StdArrangementRuleAliasToken modifiers = modifiersToken();
    final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibility, modifiers);
    final ArrayList<ArrangementGroupingRule> groupings = ContainerUtil.newArrayList(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
    final ArrayList<ArrangementSectionRule> rules = ContainerUtil.newArrayList(section(true, FIELD, visibility));
    final StdArrangementExtendableSettings settings = extendableSettings(groupings, rules, tokens);
    final StdArrangementExtendableSettings defaultSettings = new StdArrangementExtendableSettings();
    doSerializationTest(settings, defaultSettings);
}
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) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) Test(org.junit.Test)

Example 3 with ArrangementSectionRule

use of com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testDefaultCustomTokenSerialize.

@Test
public void testDefaultCustomTokenSerialize() {
    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 Element holder = doSerializationTest(settings, settings.clone());
    assertTrue(holder.getChildren().isEmpty());
}
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 4 with ArrangementSectionRule

use of com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testSectionSerialize.

@Test
public void testSectionSerialize() {
    final ArrayList<ArrangementSectionRule> sections = ContainerUtil.newArrayList(section("start section", "end section", rule(true, METHOD, PRIVATE), rule(false, METHOD, PUBLIC)), section("start section", "end section", rule(true, FIELD)));
    final StdArrangementSettings settings = settings(ContainerUtil.newArrayList(group(OVERRIDDEN_METHODS)), sections);
    final Element holder = doSerializationTest(settings, emptySettings());
    assertTrue(holder.getChildren().size() == 2);
    assertNotNull(holder.getChild("groups"));
    final Element rules = holder.getChild("rules");
    assertNotNull(rules);
    assertTrue(rules.getChildren().size() == 2);
    final Element section = rules.getChild("section");
    assertEquals(section.getAttribute("start_comment").getValue(), "start section");
    assertEquals(section.getAttribute("end_comment").getValue(), "end section");
}
Also used : Element(org.jdom.Element) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) Test(org.junit.Test)

Example 5 with ArrangementSectionRule

use of com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule in project intellij-community by JetBrains.

the class ArrangementSettingsSerializationTest method testCustomTokenSerializeMoreThanDefault.

@Test
public void testCustomTokenSerializeMoreThanDefault() throws IOException {
    final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibilityToken(), modifiersToken());
    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());
    final StdArrangementExtendableSettings defaultSettings = extendableSettings(groupings, rules, defaultTokens);
    final Element holder = doSerializationTest(settings, defaultSettings);
    final String expected = "<holder>\n" + "  <tokens>\n" + "    <token id=\"modifiers\" name=\"modifiers\">\n" + "      <rules>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PUBLIC>true</PUBLIC>\n" + "              <STATIC>true</STATIC>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PROTECTED>true</PROTECTED>\n" + "              <STATIC>true</STATIC>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\n" + "        <rule>\n" + "          <match>\n" + "            <AND>\n" + "              <PRIVATE>true</PRIVATE>\n" + "              <STATIC>true</STATIC>\n" + "            </AND>\n" + "          </match>\n" + "        </rule>\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" + "    <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)

Aggregations

ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)13 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)6 Test (org.junit.Test)6 StdArrangementExtendableSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementExtendableSettings)5 StdArrangementRuleAliasToken (com.intellij.psi.codeStyle.arrangement.std.StdArrangementRuleAliasToken)5 Element (org.jdom.Element)5 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)3 TextRange (com.intellij.openapi.util.TextRange)2 HashSet (com.intellij.util.containers.HashSet)2 NotNull (org.jetbrains.annotations.NotNull)2 ArrangementSectionRuleData (com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRuleManager.ArrangementSectionRuleData)1 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 Language (com.intellij.lang.Language)1 FoldRegion (com.intellij.openapi.editor.FoldRegion)1 FoldingModel (com.intellij.openapi.editor.FoldingModel)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 ArrangementEngine (com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine)1 ArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule)1