use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method testCustomTokenSerializeLessThanDefault.
@Test
public void testCustomTokenSerializeLessThanDefault() throws IOException {
final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibilityToken());
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(), modifiersToken());
final StdArrangementExtendableSettings defaultSettings = extendableSettings(groupings, rules, defaultTokens);
final Element holder = doSerializationTest(settings, defaultSettings);
final String expected = "<holder>\n" + " <tokens>\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 ArrangementSettingsSerializationTest method testDefaultGroupingFilter.
@Test
public void testDefaultGroupingFilter() {
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.addGrouping(groupingRule);
final Element holder = doSerializationTest(settings, defaultSettings);
assertTrue(holder.getChildren().size() == 1);
assertNull(holder.getChild("groups"));
assertNotNull(holder.getChild("rules"));
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method testEmptyRules.
@Test
public void testEmptyRules() throws Exception {
final StdArrangementSettings settings = new StdArrangementSettings();
settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
final StdArrangementSettings defaultSettings = new StdArrangementSettings();
final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
defaultSettings.addRule(rule);
final Element holder = doSerializationTest(settings, defaultSettings);
assertTrue(holder.getChildren().size() == 2);
final Element rules = holder.getChild("rules");
assertNotNull(rules);
assertTrue(rules.getChildren().isEmpty());
}
use of com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule in project android by JetBrains.
the class AndroidXmlPredefinedCodeStyle method apply.
@Override
public void apply(CodeStyleSettings settings) {
final CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(XmlFileType.INSTANCE);
indentOptions.CONTINUATION_INDENT_SIZE = indentOptions.INDENT_SIZE;
XmlCodeStyleSettings xmlSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
xmlSettings.XML_ALIGN_ATTRIBUTES = false;
xmlSettings.XML_SPACE_INSIDE_EMPTY_TAG = true;
xmlSettings.XML_KEEP_LINE_BREAKS = false;
final AndroidXmlCodeStyleSettings androidSettings = AndroidXmlCodeStyleSettings.getInstance(settings);
androidSettings.USE_CUSTOM_SETTINGS = true;
androidSettings.LAYOUT_SETTINGS = new AndroidXmlCodeStyleSettings.LayoutSettings();
androidSettings.MANIFEST_SETTINGS = new AndroidXmlCodeStyleSettings.ManifestSettings();
androidSettings.VALUE_RESOURCE_FILE_SETTINGS = new AndroidXmlCodeStyleSettings.ValueResourceFileSettings();
androidSettings.OTHER_SETTINGS = new AndroidXmlCodeStyleSettings.OtherSettings();
// arrangement
final List<StdArrangementMatchRule> rules = new ArrayList<StdArrangementMatchRule>();
rules.add(attrArrangementRule("xmlns:android", "^$", KEEP));
rules.add(attrArrangementRule("xmlns:.*", "^$", BY_NAME));
rules.add(attrArrangementRule(".*:id", SdkConstants.NS_RESOURCES, KEEP));
rules.add(attrArrangementRule(".*:name", SdkConstants.NS_RESOURCES, KEEP));
rules.add(attrArrangementRule("name", "^$", KEEP));
rules.add(attrArrangementRule("style", "^$", KEEP));
rules.add(attrArrangementRule(".*", "^$", BY_NAME));
rules.add(attrArrangementRule(".*:layout_width", SdkConstants.NS_RESOURCES, KEEP));
rules.add(attrArrangementRule(".*:layout_height", SdkConstants.NS_RESOURCES, KEEP));
rules.add(attrArrangementRule(".*:layout_.*", SdkConstants.NS_RESOURCES, BY_NAME));
rules.add(attrArrangementRule(".*:width", SdkConstants.NS_RESOURCES, BY_NAME));
rules.add(attrArrangementRule(".*:height", SdkConstants.NS_RESOURCES, BY_NAME));
rules.add(attrArrangementRule(".*", SdkConstants.NS_RESOURCES, BY_NAME));
rules.add(attrArrangementRule(".*", ".*", BY_NAME));
// TODO: Should sort name:"color",namespace:"" to the end (primarily for color state lists)
final CommonCodeStyleSettings xmlCommonSettings = settings.getCommonSettings(XMLLanguage.INSTANCE);
xmlCommonSettings.setArrangementSettings(StdArrangementSettings.createByMatchRules(ContainerUtil.<ArrangementGroupingRule>emptyList(), rules));
xmlCommonSettings.FORCE_REARRANGE_MODE = CommonCodeStyleSettings.REARRANGE_ALWAYS;
}
Aggregations