Search in sources :

Example 11 with ArrangementGroupingRule

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));
        }
    }
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) Element(org.jdom.Element)

Example 12 with ArrangementGroupingRule

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);
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) Element(org.jdom.Element) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with ArrangementGroupingRule

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();
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ArrangementGroupingRule

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);
}
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 15 with ArrangementGroupingRule

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;
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) CompositeArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken) ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

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