Search in sources :

Example 6 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 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 7 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 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 8 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 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);
}
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 9 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.

the class ArrangementGroupingRulesControl method setRules.

public void setRules(@Nullable List<ArrangementGroupingRule> rules) {
    for (ArrangementGroupingComponent component : myComponents.values()) {
        component.setSelected(false);
    }
    if (rules == null) {
        return;
    }
    DefaultTableModel model = getModel();
    while (model.getRowCount() > 0) {
        model.removeRow(model.getRowCount() - 1);
    }
    final Set<ArrangementSettingsToken> groupingTokens = ContainerUtilRt.newHashSet(myComponents.keySet());
    for (ArrangementGroupingRule rule : rules) {
        final ArrangementSettingsToken groupingType = rule.getGroupingType();
        ArrangementGroupingComponent component = myComponents.get(groupingType);
        component.setSelected(true);
        component.setOrderType(rule.getOrderType());
        model.addRow(new Object[] { component });
        groupingTokens.remove(groupingType);
    }
    List<ArrangementSettingsToken> types = ContainerUtilRt.newArrayList(groupingTokens);
    types = mySettingsManager.sort(types);
    for (ArrangementSettingsToken type : types) {
        model.addRow(new Object[] { myComponents.get(type) });
    }
}
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)

Example 10 with ArrangementGroupingRule

use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.

the class AbstractRearrangerTest method doTest.

protected void doTest(@NotNull Map<String, ?> args) {
    String text = (String) args.get("initial");
    String expected = (String) args.get("expected");
    @SuppressWarnings("unchecked") List<TextRange> ranges = (List<TextRange>) args.get("ranges");
    Info info = parse(text);
    if (!isEmpty(ranges) && !isEmpty(info.ranges)) {
        fail("Duplicate ranges set: explicit: " + ranges + ", " + "derived: " + info.ranges + ", text:\n" + text);
    }
    if (isEmpty(info.ranges)) {
        info.ranges = !isEmpty(ranges) ? ranges : Arrays.asList(TextRange.from(0, text.length()));
    }
    myFixture.configureByText(fileType, info.text);
    final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
    for (final FoldingInfo foldingInfo : info.foldings) {
        foldingModel.runBatchFoldingOperation(() -> {
            FoldRegion region = foldingModel.addFoldRegion(foldingInfo.start, foldingInfo.end, foldingInfo.placeholder);
            if (region != null)
                region.setExpanded(false);
        });
    }
    @SuppressWarnings("unchecked") List<ArrangementGroupingRule> groupingRules = (List<ArrangementGroupingRule>) args.get("groups");
    if (groupingRules == null)
        groupingRules = Collections.emptyList();
    List<?> rules = (List<?>) args.get("rules");
    List<ArrangementSectionRule> sectionRules = getSectionRules(rules);
    @SuppressWarnings("unchecked") List<StdArrangementRuleAliasToken> aliases = (List<StdArrangementRuleAliasToken>) args.get("aliases");
    CommonCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings().getCommonSettings(language);
    final StdArrangementSettings arrangementSettings = aliases == null ? new StdArrangementSettings(groupingRules, sectionRules) : new StdArrangementExtendableSettings(groupingRules, sectionRules, aliases);
    settings.setArrangementSettings(arrangementSettings);
    ArrangementEngine engine = ServiceManager.getService(myFixture.getProject(), ArrangementEngine.class);
    CommandProcessor.getInstance().executeCommand(getProject(), () -> engine.arrange(myFixture.getEditor(), myFixture.getFile(), info.ranges), null, null);
    // Check expectation.
    Info after = parse(expected);
    assertEquals(after.text, myFixture.getEditor().getDocument().getText());
    for (FoldingInfo it : after.foldings) {
        FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(it.start);
        assertNotNull("Expected to find fold region at offset " + it.start, foldRegion);
        assertEquals(it.end, foldRegion.getEndOffset());
    }
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementEngine(com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine) FoldRegion(com.intellij.openapi.editor.FoldRegion) TextRange(com.intellij.openapi.util.TextRange) FoldingModel(com.intellij.openapi.editor.FoldingModel) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)

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