use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method testEmptyGroupings.
@Test
public void testEmptyGroupings() throws Exception {
final StdArrangementSettings settings = new StdArrangementSettings();
final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME));
final StdArrangementSettings defaultSettings = new StdArrangementSettings();
defaultSettings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
final Element holder = doSerializationTest(settings, defaultSettings);
assertTrue(holder.getChildren().size() == 2);
final Element groups = holder.getChild("groups");
assertNotNull(groups);
assertTrue(groups.getChildren().isEmpty());
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 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.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class DefaultArrangementSettingsSerializer method deserializeGropings.
@NotNull
private List<ArrangementGroupingRule> deserializeGropings(@NotNull Element element, @Nullable ArrangementSettings defaultSettings) {
Element groups = element.getChild(GROUPS_ELEMENT_NAME);
if (groups == null) {
return defaultSettings == null ? ContainerUtil.<ArrangementGroupingRule>newSmartList() : defaultSettings.getGroupings();
}
final List<ArrangementGroupingRule> groupings = new ArrayList<>();
for (Object group : groups.getChildren(GROUP_ELEMENT_NAME)) {
Element groupElement = (Element) group;
// Grouping type.
String groupingTypeId = groupElement.getChildText(TYPE_ELEMENT_NAME);
ArrangementSettingsToken groupingType = StdArrangementTokens.byId(groupingTypeId);
if (groupingType == null) {
groupingType = myMixin.deserializeToken(groupingTypeId);
}
if (groupingType == null) {
LOG.warn(String.format("Can't deserialize grouping type token by id '%s'", groupingTypeId));
continue;
}
// Order type.
String orderTypeId = groupElement.getChildText(ORDER_TYPE_ELEMENT_NAME);
ArrangementSettingsToken orderType = StdArrangementTokens.byId(orderTypeId);
if (orderType == null) {
orderType = myMixin.deserializeToken(orderTypeId);
}
if (orderType == null) {
LOG.warn(String.format("Can't deserialize grouping order type token by id '%s'", orderTypeId));
continue;
}
groupings.add(new ArrangementGroupingRule(groupingType, orderType));
}
return groupings;
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method all.
@Test
public void all() {
final StdArrangementSettings settings = new StdArrangementSettings();
settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME));
doSerializationTest(settings, new StdArrangementSettings());
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 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());
}
Aggregations