use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class DefaultArrangementSettingsSerializer method serialize.
@Override
public void serialize(@NotNull ArrangementSettings s, @NotNull Element holder) {
if (!(s instanceof StdArrangementSettings)) {
return;
}
StdArrangementSettings settings = (StdArrangementSettings) s;
if (settings instanceof ArrangementExtendableSettings && myDefaultSettings instanceof ArrangementExtendableSettings) {
final Set<StdArrangementRuleAliasToken> tokensDefinition = ((ArrangementExtendableSettings) settings).getRuleAliases();
final boolean isDefault = tokensDefinition.equals(((ArrangementExtendableSettings) myDefaultSettings).getRuleAliases());
if (!isDefault) {
final Element tokensElement = new Element(TOKENS_ELEMENT_NAME);
for (StdArrangementRuleAliasToken definition : tokensDefinition) {
final Element tokenElement = new Element(TOKEN_ELEMENT_NAME);
tokenElement.setAttribute(TOKEN_ID, definition.getId());
tokenElement.setAttribute(TOKEN_NAME, definition.getName());
final Element rulesElement = new Element(RULES_ELEMENT_NAME);
for (StdArrangementMatchRule rule : definition.getDefinitionRules()) {
rulesElement.addContent(serialize(rule));
}
tokenElement.addContent(rulesElement);
tokensElement.addContent(tokenElement);
}
holder.addContent(tokensElement);
}
}
List<ArrangementGroupingRule> groupings = settings.getGroupings();
final boolean isDefaultGroupings = groupings.equals(myDefaultSettings.getGroupings());
if (!isDefaultGroupings) {
Element groupingsElement = new Element(GROUPS_ELEMENT_NAME);
holder.addContent(groupingsElement);
for (ArrangementGroupingRule group : groupings) {
Element groupElement = new Element(GROUP_ELEMENT_NAME);
groupingsElement.addContent(groupElement);
groupElement.addContent(new Element(TYPE_ELEMENT_NAME).setText(group.getGroupingType().getId()));
groupElement.addContent(new Element(ORDER_TYPE_ELEMENT_NAME).setText(group.getOrderType().getId()));
}
}
final List<ArrangementSectionRule> sections = settings.getSections();
final boolean isDefaultRules = sections.equals((myDefaultSettings).getSections());
if (!isDefaultRules) {
Element rulesElement = new Element(RULES_ELEMENT_NAME);
holder.addContent(rulesElement);
for (ArrangementSectionRule section : sections) {
rulesElement.addContent(serialize(section));
}
}
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class DefaultArrangementSettingsSerializer method deserialize.
@Nullable
@Override
public ArrangementSettings deserialize(@NotNull Element element) {
final Set<StdArrangementRuleAliasToken> tokensDefinition = deserializeTokensDefinition(element, myDefaultSettings);
final List<ArrangementGroupingRule> groupingRules = deserializeGropings(element, myDefaultSettings);
final Element rulesElement = element.getChild(RULES_ELEMENT_NAME);
final List<ArrangementSectionRule> sectionRules = ContainerUtil.newArrayList();
if (rulesElement == null) {
sectionRules.addAll(myDefaultSettings.getSections());
} else {
sectionRules.addAll(deserializeSectionRules(rulesElement, tokensDefinition));
if (sectionRules.isEmpty()) {
// for backward compatibility
final List<StdArrangementMatchRule> rules = deserializeRules(rulesElement, tokensDefinition);
return StdArrangementSettings.createByMatchRules(groupingRules, rules);
}
}
if (tokensDefinition == null) {
return new StdArrangementSettings(groupingRules, sectionRules);
}
return new StdArrangementExtendableSettings(groupingRules, sectionRules, tokensDefinition);
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class JavaRearranger method parse.
@NotNull
@Override
public List<JavaElementArrangementEntry> parse(@NotNull PsiElement root, @Nullable Document document, @NotNull Collection<TextRange> ranges, @NotNull ArrangementSettings settings) {
// Following entries are subject to arrangement: class, interface, field, method.
JavaArrangementParseInfo parseInfo = new JavaArrangementParseInfo();
root.accept(new JavaArrangementVisitor(parseInfo, document, ranges, settings));
for (ArrangementGroupingRule rule : settings.getGroupings()) {
if (GETTERS_AND_SETTERS.equals(rule.getGroupingType())) {
setupGettersAndSetters(parseInfo);
} else if (DEPENDENT_METHODS.equals(rule.getGroupingType())) {
setupUtilityMethods(parseInfo, rule.getOrderType());
} else if (OVERRIDDEN_METHODS.equals(rule.getGroupingType())) {
setupOverriddenMethods(parseInfo);
}
}
List<ArrangementEntryDependencyInfo> fieldDependencyRoots = parseInfo.getFieldDependencyRoots();
if (!fieldDependencyRoots.isEmpty()) {
setupFieldInitializationDependencies(fieldDependencyRoots, settings, parseInfo);
}
return parseInfo.getEntries();
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method testUseCustomTokenSerialize.
@Test
public void testUseCustomTokenSerialize() throws IOException {
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 ArrayList<ArrangementSectionRule> defaultRules = ContainerUtil.newArrayList(section(true, FIELD));
final StdArrangementExtendableSettings defaultSettings = extendableSettings(groupings, defaultRules, tokens);
final Element holder = doSerializationTest(settings, defaultSettings);
final String expected = "<holder>\n" + " <rules>\n" + " <section>\n" + " <rule>\n" + " <match>\n" + " <AND>\n" + " <FIELD>true</FIELD>\n" + " <visibility />\n" + " </AND>\n" + " </match>\n" + " <order>BY_NAME</order>\n" + " </rule>\n" + " </section>\n" + " </rules>\n" + "</holder>";
assertXmlOutputEquals(expected, holder);
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementGroupingRulesControl method getRules.
@NotNull
public List<ArrangementGroupingRule> getRules() {
List<ArrangementGroupingRule> result = new ArrayList<>();
DefaultTableModel model = getModel();
for (int i = 0, max = model.getRowCount(); i < max; i++) {
ArrangementGroupingComponent component = (ArrangementGroupingComponent) model.getValueAt(i, 0);
if (!component.isSelected()) {
continue;
}
ArrangementSettingsToken orderType = component.getOrderType();
if (orderType == null) {
result.add(new ArrangementGroupingRule(component.getGroupingType()));
} else {
result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
}
}
return result;
}
Aggregations