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;
}
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);
}
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());
}
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");
}
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);
}
Aggregations