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"));
}
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());
}
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);
}
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) });
}
}
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());
}
}
Aggregations