@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")); }
@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")); }
@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()); }
private static Element doSerializationTest(@NotNull StdArrangementSettings settings, @NotNull StdArrangementSettings defaultSettings) { Element holder = new Element("holder"); ArrangementSettingsSerializer instance = new TestArrangementSettingsSerializer(defaultSettings); instance.serialize(settings, holder); ArrangementSettings restored = instance.deserialize(holder); assertEquals(settings, restored); return holder; }
@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()); }
@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()); }
@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()); }
@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; }
@Test public void all() { StdArrangementSettings settings = new StdRulePriorityAwareSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); Element holder = new Element("holder"); ArrangementSettingsSerializer instance = DefaultArrangementSettingsSerializer.INSTANCE; instance.serialize(settings, holder); ArrangementSettings restored = instance.deserialize(holder); assertEquals(settings, restored); }
@Override public void serialize(@NotNull ArrangementSettings s, @NotNull Element holder) { if (!(s instanceof StdArrangementSettings)) { return; } StdArrangementSettings settings = (StdArrangementSettings)s; List<ArrangementGroupingRule> groupings = settings.getGroupings(); if (!groupings.isEmpty()) { 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())); } } List<StdArrangementMatchRule> rules = settings.getRules(); if (!rules.isEmpty()) { Element rulesElement = new Element(RULES_ELEMENT_NAME); holder.addContent(rulesElement); for (StdArrangementMatchRule rule : rules) { rulesElement.addContent(serialize(rule)); } } }
@Test public void all() { StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); Element holder = new Element("holder"); ArrangementSettingsSerializer instance = new DefaultArrangementSettingsSerializer(settings); instance.serialize(settings, holder); ArrangementSettings restored = instance.deserialize(holder); assertEquals(settings, restored); }
private static StdArrangementSettings settings(@NotNull List<ArrangementGroupingRule> groupings, @NotNull List<ArrangementSectionRule> sections) { return new StdArrangementSettings(groupings, sections); }
private static StdArrangementSettings emptySettings() { return new StdArrangementSettings(ContainerUtil.<ArrangementGroupingRule>emptyList(), ContainerUtil.<ArrangementSectionRule>emptyList()); }
public TestArrangementSettingsSerializer(@NotNull StdArrangementSettings defaultSettings) { super(defaultSettings); }
/** * @see ArrangementStandardSettingsAware#getDefaultSettings() */ @Nullable public StdArrangementSettings getDefaultSettings() { return myDefaultSettings; }
@Nullable @Override public StdArrangementSettings getDefaultSettings() { return DEFAULT_SETTINGS; }
@NotNull @Override public StdArrangementSettings getDefaultSettings() { return DEFAULT_SETTINGS; }