Search in sources :

Example 6 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule 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());
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 7 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule 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());
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 8 with StdArrangementMatchRule

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

the class ArrangementSettingsSerializationTest method testDefaultRulesFilter.

@Test
public void testDefaultRulesFilter() {
    final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME);
    final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
    final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
    final StdArrangementSettings settings = new StdArrangementSettings();
    settings.addGrouping(groupingRule);
    settings.addRule(rule);
    final StdArrangementSettings defaultSettings = new StdArrangementSettings();
    defaultSettings.addRule(rule);
    final Element holder = doSerializationTest(settings, defaultSettings);
    assertTrue(holder.getChildren().size() == 1);
    assertNotNull(holder.getChild("groups"));
    assertNull(holder.getChild("rules"));
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 9 with StdArrangementMatchRule

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

the class ArrangementSettingsSerializationTest method testDefaultFilter.

@Test
public void testDefaultFilter() {
    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));
    final Element holder = doSerializationTest(settings, settings);
    assertTrue(holder.getChildren().isEmpty());
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Example 10 with StdArrangementMatchRule

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

the class ArrangementMatchingRuleEditor method reset.

/**
   * Asks current editor to refresh its state in accordance with the arrangement rule shown at the given row.
   *
   * @param row  row index of the rule which match condition should be edited (if defined);
   *              {@code '-1'} as an indication that no settings should be active
   */
public void reset(int row) {
    // Reset state.
    myRow = row;
    myFocusRequestor = myDefaultFocusRequestor;
    mySkipStateChange = true;
    try {
        for (ArrangementUiComponent component : myComponents.values()) {
            component.reset();
        }
    } finally {
        mySkipStateChange = false;
    }
    ArrangementMatchingRulesModel model = myControl.getModel();
    if (row < 0 || row >= model.getSize()) {
        myRow = -1;
        return;
    }
    Object element = model.getElementAt(row);
    ArrangementSettingsToken orderType = element instanceof ArrangementMatchRule ? ((ArrangementMatchRule) element).getOrderType() : null;
    final ArrangementMatchCondition condition;
    final Map<ArrangementSettingsToken, Object> conditionTokens;
    if (element instanceof EmptyArrangementRuleComponent) {
        // We need to disable conditions which are not applicable for empty rules (e.g. we don't want to enable 'volatile' condition
        // for java rearranger if no 'field' condition is selected.
        condition = null;
        conditionTokens = ContainerUtilRt.newHashMap();
    } else if (!(element instanceof StdArrangementMatchRule)) {
        return;
    } else {
        condition = ((StdArrangementMatchRule) element).getMatcher().getCondition();
        conditionTokens = ArrangementUtil.extractTokens(condition);
    }
    mySkipStateChange = true;
    try {
        for (ArrangementUiComponent component : myComponents.values()) {
            ArrangementSettingsToken token = component.getToken();
            if (token != null && (component.getAvailableTokens().contains(orderType) || isEnabled(condition, token))) {
                component.setEnabled(true);
                if (component.getAvailableTokens().contains(orderType)) {
                    component.chooseToken(orderType);
                } else {
                    component.setSelected(conditionTokens.containsKey(token));
                }
                Object value = conditionTokens.get(token);
                if (value != null) {
                    component.setData(value);
                }
            }
        }
        refreshConditions();
    } finally {
        mySkipStateChange = false;
    }
}
Also used : StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) ArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Aggregations

StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)22 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)13 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)13 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)7 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)6 StdArrangementSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings)6 Test (org.junit.Test)6 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)5 Element (org.jdom.Element)5 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)2 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)2 ArrayList (java.util.ArrayList)2 ArrangementSectionRuleData (com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRuleManager.ArrangementSectionRuleData)1 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 ArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule)1 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)1 THashMap (gnu.trove.THashMap)1