Java 类com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule 实例源码

项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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"));
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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"));
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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());
}
项目:intellij-ce-playground    文件:DefaultArrangementSettingsSerializer.java   
@Nullable
@Override
public ArrangementSettings deserialize(@NotNull Element element) {
  final Set<StdArrangementRuleAliasToken> tokensDefinition = deserializeTokensDefinition(element, myDefaultSettings);
  final List<ArrangementGroupingRule> groupingRules = deserializeGropings(element, myDefaultSettings);
  final Element rulesElement = element.getChild(RULES_ELEMENT_NAME);
  final List<ArrangementSectionRule> sectionRules = ContainerUtil.newArrayList();
  if(rulesElement == null) {
    sectionRules.addAll(myDefaultSettings.getSections());
  }
  else {
    sectionRules.addAll(deserializeSectionRules(rulesElement, tokensDefinition));
    if (sectionRules.isEmpty()) {
      // for backward compatibility
      final List<StdArrangementMatchRule> rules = deserializeRules(rulesElement, tokensDefinition);
      return StdArrangementSettings.createByMatchRules(groupingRules, rules);
    }
  }

  if (tokensDefinition == null) {
    return new StdArrangementSettings(groupingRules, sectionRules);
  }
  return new StdArrangementExtendableSettings(groupingRules, sectionRules, tokensDefinition);
}
项目:intellij-ce-playground    文件:ArrangementGroupingRulesControl.java   
@NotNull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:ArrangementSettingsPanel.java   
@Override
protected void resetImpl(CodeStyleSettings settings) {
  StdArrangementSettings s = getSettings(settings);
  if (s == null) {
    myGroupingRulesPanel.setRules(null);
    myMatchingRulesPanel.setSections(null);
  }
  else {
    List<ArrangementGroupingRule> groupings = s.getGroupings();
    myGroupingRulesPanel.setRules(ContainerUtilRt.newArrayList(groupings));
    myMatchingRulesPanel.setSections(copy(s.getSections()));
    if (s instanceof StdArrangementExtendableSettings) {
      myMatchingRulesPanel.setRulesAliases(((StdArrangementExtendableSettings)s).getRuleAliases());
    }

    if (myForceArrangementPanel != null) {
      myForceArrangementPanel.setSelectedMode(settings.getCommonSettings(myLanguage).FORCE_REARRANGE_MODE);
    }
  }
}
项目:tools-idea    文件:JavaRearranger.java   
@NotNull
@Override
public List<JavaElementArrangementEntry> parse(@NotNull PsiElement root,
                                               @Nullable Document document,
                                               @NotNull Collection<TextRange> ranges,
                                               @Nullable ArrangementSettings settings)
{
  // Following entries are subject to arrangement: class, interface, field, method.
  JavaArrangementParseInfo parseInfo = new JavaArrangementParseInfo();
  root.accept(new JavaArrangementVisitor(parseInfo, document, ranges, getGroupingRules(settings)));
  if (settings != null) {
    for (ArrangementGroupingRule rule : settings.getGroupings()) {
      if (GETTERS_AND_SETTERS.equals(rule.getGroupingType())) {
        setupGettersAndSetters(parseInfo);
      }
      else if (DEPENDENT_METHODS.equals(rule.getGroupingType())) {
        setupUtilityMethods(parseInfo, rule.getOrderType());
      }
      else if (OVERRIDDEN_METHODS.equals(rule.getGroupingType())) {
        setupOverriddenMethods(parseInfo);
      }
    }
  }
  return parseInfo.getEntries();
}
项目:tools-idea    文件:ArrangementGroupingRulesControl.java   
@NotNull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:tools-idea    文件:ArrangementSettingsPanel.java   
@Override
protected void resetImpl(CodeStyleSettings settings) {
  StdArrangementSettings s = getSettings(settings);
  if (s == null) {
    myGroupingRulesPanel.setRules(null);
    myMatchingRulesPanel.setRules(null);
  }
  else {
    List<ArrangementGroupingRule> groupings = s.getGroupings();
    myGroupingRulesPanel.setVisible(!groupings.isEmpty());
    if (!groupings.isEmpty()) {
      myGroupingRulesPanel.setRules(ContainerUtilRt.newArrayList(groupings));
    }
    myMatchingRulesPanel.setRules(copy(s.getRules()));
  }
}
项目:consulo    文件:DefaultArrangementSettingsSerializer.java   
@Nullable
@Override
public ArrangementSettings deserialize(@Nonnull Element element) {
  final Set<StdArrangementRuleAliasToken> tokensDefinition = deserializeTokensDefinition(element, myDefaultSettings);
  final List<ArrangementGroupingRule> groupingRules = deserializeGropings(element, myDefaultSettings);
  final Element rulesElement = element.getChild(RULES_ELEMENT_NAME);
  final List<ArrangementSectionRule> sectionRules = ContainerUtil.newArrayList();
  if(rulesElement == null) {
    sectionRules.addAll(myDefaultSettings.getSections());
  }
  else {
    sectionRules.addAll(deserializeSectionRules(rulesElement, tokensDefinition));
    if (sectionRules.isEmpty()) {
      // for backward compatibility
      final List<StdArrangementMatchRule> rules = deserializeRules(rulesElement, tokensDefinition);
      return StdArrangementSettings.createByMatchRules(groupingRules, rules);
    }
  }

  if (tokensDefinition == null) {
    return new StdArrangementSettings(groupingRules, sectionRules);
  }
  return new StdArrangementExtendableSettings(groupingRules, sectionRules, tokensDefinition);
}
项目:consulo    文件:ArrangementGroupingRulesControl.java   
@Nonnull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:consulo    文件:ArrangementSettingsPanel.java   
@Override
protected void resetImpl(CodeStyleSettings settings) {
  StdArrangementSettings s = getSettings(settings);
  if (s == null) {
    myGroupingRulesPanel.setRules(null);
    myMatchingRulesPanel.setSections(null);
  }
  else {
    List<ArrangementGroupingRule> groupings = s.getGroupings();
    myGroupingRulesPanel.setRules(ContainerUtilRt.newArrayList(groupings));
    myMatchingRulesPanel.setSections(copy(s.getSections()));
    if (myForceArrangementPanel != null) {
      myForceArrangementPanel.setSelectedMode(settings.getCommonSettings(myLanguage).FORCE_REARRANGE_MODE);
    }
  }
}
项目:intellij-ce-playground    文件:JavaRearranger.java   
@NotNull
@Override
public List<JavaElementArrangementEntry> parse(@NotNull PsiElement root,
                                               @Nullable Document document,
                                               @NotNull Collection<TextRange> ranges,
                                               @NotNull ArrangementSettings settings)
{
  // Following entries are subject to arrangement: class, interface, field, method.
  JavaArrangementParseInfo parseInfo = new JavaArrangementParseInfo();
  root.accept(new JavaArrangementVisitor(parseInfo, document, ranges, settings));
  for (ArrangementGroupingRule rule : settings.getGroupings()) {
    if (GETTERS_AND_SETTERS.equals(rule.getGroupingType())) {
      setupGettersAndSetters(parseInfo);
    }
    else if (DEPENDENT_METHODS.equals(rule.getGroupingType())) {
      setupUtilityMethods(parseInfo, rule.getOrderType());
    }
    else if (OVERRIDDEN_METHODS.equals(rule.getGroupingType())) {
      setupOverriddenMethods(parseInfo);
    }
  }
  List<ArrangementEntryDependencyInfo> fieldDependencyRoots = parseInfo.getFieldDependencyRoots();
  if (!fieldDependencyRoots.isEmpty()) {
    setupFieldInitializationDependencies(fieldDependencyRoots, settings, parseInfo);
  }
  return parseInfo.getEntries();
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@NotNull
private static Set<ArrangementSettingsToken> getGroupingRules(@NotNull ArrangementSettings settings) {
  Set<ArrangementSettingsToken> groupingRules = ContainerUtilRt.newHashSet();
  for (ArrangementGroupingRule rule : settings.getGroupings()) {
    groupingRules.add(rule.getGroupingType());
  }
  return groupingRules;
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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());
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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());
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@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());
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@Test
public void testDefaultCustomTokenSerialize() {
  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 Element holder = doSerializationTest(settings, settings.clone());
  assertTrue(holder.getChildren().isEmpty());
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@Test
public void testUseCustomTokenSerialize() throws IOException {
  final StdArrangementRuleAliasToken visibility = visibilityToken();
  final StdArrangementRuleAliasToken modifiers = modifiersToken();
  final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibility, modifiers);
  final ArrayList<ArrangementGroupingRule> groupings = ContainerUtil.newArrayList(
    new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
  final ArrayList<ArrangementSectionRule> rules = ContainerUtil.newArrayList(section(true, FIELD, visibility));
  final StdArrangementExtendableSettings settings = extendableSettings(groupings, rules, tokens);

  final ArrayList<ArrangementSectionRule> defaultRules = ContainerUtil.newArrayList(section(true, FIELD));
  final StdArrangementExtendableSettings defaultSettings = extendableSettings(groupings, defaultRules, tokens);

  final Element holder = doSerializationTest(settings, defaultSettings);
  final String expected = "<holder>\n" +
                          "  <rules>\n" +
                          "    <section>\n" +
                          "      <rule>\n" +
                          "        <match>\n" +
                          "          <AND>\n" +
                          "            <FIELD>true</FIELD>\n" +
                          "            <visibility />\n" +
                          "          </AND>\n" +
                          "        </match>\n" +
                          "        <order>BY_NAME</order>\n" +
                          "      </rule>\n" +
                          "    </section>\n" +
                          "  </rules>\n" +
                          "</holder>";
  assertXmlOutputEquals(expected, holder);
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
@Test
public void testCustomTokenSerializeAndDeserialize() {
  final StdArrangementRuleAliasToken visibility = visibilityToken();
  final StdArrangementRuleAliasToken modifiers = modifiersToken();
  final Set<StdArrangementRuleAliasToken> tokens = ContainerUtil.newHashSet(visibility, modifiers);
  final ArrayList<ArrangementGroupingRule> groupings = ContainerUtil.newArrayList(
    new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
  final ArrayList<ArrangementSectionRule> rules = ContainerUtil.newArrayList(section(true, FIELD, visibility));
  final StdArrangementExtendableSettings settings = extendableSettings(groupings, rules, tokens);
  final StdArrangementExtendableSettings defaultSettings = new StdArrangementExtendableSettings();
  doSerializationTest(settings, defaultSettings);
}
项目:intellij-ce-playground    文件:StdArrangementSettings.java   
public static StdArrangementSettings createByMatchRules(@NotNull List<ArrangementGroupingRule> groupingRules,
                                                        @NotNull List<StdArrangementMatchRule> matchRules) {
  final List<ArrangementSectionRule> sectionRules = new ArrayList<ArrangementSectionRule>();
  for (StdArrangementMatchRule rule : matchRules) {
    sectionRules.add(ArrangementSectionRule.create(rule));
  }
  return new StdArrangementSettings(groupingRules, sectionRules);
}
项目:intellij-ce-playground    文件:StdArrangementSettings.java   
@NotNull
protected List<ArrangementGroupingRule> cloneGroupings() {
  final ArrayList<ArrangementGroupingRule> groupings = new ArrayList<ArrangementGroupingRule>();
  for (ArrangementGroupingRule grouping : myGroupings) {
    groupings.add(grouping.clone());
  }
  return groupings;
}
项目:intellij-ce-playground    文件:StdArrangementExtendableSettings.java   
public static StdArrangementExtendableSettings createByMatchRules(@NotNull List<ArrangementGroupingRule> groupingRules,
                                                                  @NotNull List<StdArrangementMatchRule> matchRules,
                                                                  @NotNull Collection<StdArrangementRuleAliasToken> rulesAliases) {
  final List<ArrangementSectionRule> sectionRules = new ArrayList<ArrangementSectionRule>();
  for (StdArrangementMatchRule rule : matchRules) {
    sectionRules.add(ArrangementSectionRule.create(rule));
  }
  return new StdArrangementExtendableSettings(groupingRules, sectionRules, rulesAliases);
}
项目:intellij-ce-playground    文件:DefaultArrangementSettingsSerializer.java   
@NotNull
private List<ArrangementGroupingRule> deserializeGropings(@NotNull Element element, @Nullable ArrangementSettings defaultSettings) {
  Element groups = element.getChild(GROUPS_ELEMENT_NAME);
  if (groups == null) {
    return defaultSettings == null ? ContainerUtil.<ArrangementGroupingRule>newSmartList() : defaultSettings.getGroupings();
  }

  final List<ArrangementGroupingRule> groupings = new ArrayList<ArrangementGroupingRule>();
  for (Object group : groups.getChildren(GROUP_ELEMENT_NAME)) {
    Element groupElement = (Element)group;

    // Grouping type.
    String groupingTypeId = groupElement.getChildText(TYPE_ELEMENT_NAME);
    ArrangementSettingsToken groupingType = StdArrangementTokens.byId(groupingTypeId);
    if (groupingType == null) {
      groupingType = myMixin.deserializeToken(groupingTypeId);
    }
    if (groupingType == null) {
      LOG.warn(String.format("Can't deserialize grouping type token by id '%s'", groupingTypeId));
      continue;
    }

    // Order type.
    String orderTypeId = groupElement.getChildText(ORDER_TYPE_ELEMENT_NAME);
    ArrangementSettingsToken orderType = StdArrangementTokens.byId(orderTypeId);
    if (orderType == null) {
      orderType = myMixin.deserializeToken(orderTypeId);
    }
    if (orderType == null) {
      LOG.warn(String.format("Can't deserialize grouping order type token by id '%s'", orderTypeId));
      continue;
    }
    groupings.add(new ArrangementGroupingRule(groupingType, orderType));
  }
  return groupings;
}
项目:intellij-ce-playground    文件:ArrangementSettingsPanel.java   
private StdArrangementSettings createSettings() {
  final List<ArrangementGroupingRule> groupingRules = myGroupingRulesPanel.getRules();
  final List<ArrangementSectionRule> sections = myMatchingRulesPanel.getSections();
  final Collection<StdArrangementRuleAliasToken> tokens = myMatchingRulesPanel.getRulesAliases();
  if (tokens != null) {
    return new StdArrangementExtendableSettings(groupingRules, sections, tokens);
  }
  return new StdArrangementSettings(groupingRules, sections);
}
项目:intellij-ce-playground    文件:AndroidXmlPredefinedCodeStyle.java   
@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;
}
项目:tools-idea    文件:JavaRearranger.java   
@NotNull
private static Set<ArrangementSettingsToken> getGroupingRules(@Nullable ArrangementSettings settings) {
  Set<ArrangementSettingsToken> groupingRules = ContainerUtilRt.newHashSet();
  if (settings != null) {
    for (ArrangementGroupingRule rule : settings.getGroupings()) {
      groupingRules.add(rule.getGroupingType());
    }
  }
  return groupingRules;
}
项目:tools-idea    文件:ArrangementSettingsSerializationTest.java   
@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);
}
项目:tools-idea    文件:DefaultArrangementSettingsSerializer.java   
@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));
    }
  }
}
项目:consulo    文件:StdArrangementSettings.java   
public static StdArrangementSettings createByMatchRules(@Nonnull List<ArrangementGroupingRule> groupingRules,
                                                        @Nonnull List<StdArrangementMatchRule> matchRules) {
  final List<ArrangementSectionRule> sectionRules = new ArrayList<ArrangementSectionRule>();
  for (StdArrangementMatchRule rule : matchRules) {
    sectionRules.add(ArrangementSectionRule.create(rule));
  }
  return new StdArrangementSettings(groupingRules, sectionRules);
}
项目:consulo    文件:StdArrangementSettings.java   
@Nonnull
protected List<ArrangementGroupingRule> cloneGroupings() {
  final ArrayList<ArrangementGroupingRule> groupings = new ArrayList<ArrangementGroupingRule>();
  for (ArrangementGroupingRule grouping : myGroupings) {
    groupings.add(grouping.clone());
  }
  return groupings;
}
项目:consulo    文件:StdArrangementExtendableSettings.java   
public static StdArrangementExtendableSettings createByMatchRules(@Nonnull List<ArrangementGroupingRule> groupingRules,
                                                                  @Nonnull List<StdArrangementMatchRule> matchRules,
                                                                  @Nonnull Collection<StdArrangementRuleAliasToken> rulesAliases) {
  final List<ArrangementSectionRule> sectionRules = new ArrayList<ArrangementSectionRule>();
  for (StdArrangementMatchRule rule : matchRules) {
    sectionRules.add(ArrangementSectionRule.create(rule));
  }
  return new StdArrangementExtendableSettings(groupingRules, sectionRules, rulesAliases);
}
项目:consulo    文件:DefaultArrangementSettingsSerializer.java   
@Nonnull
private List<ArrangementGroupingRule> deserializeGropings(@Nonnull Element element, @Nullable ArrangementSettings defaultSettings) {
  Element groups = element.getChild(GROUPS_ELEMENT_NAME);
  if (groups == null) {
    return defaultSettings == null ? ContainerUtil.<ArrangementGroupingRule>newSmartList() : defaultSettings.getGroupings();
  }

  final List<ArrangementGroupingRule> groupings = new ArrayList<ArrangementGroupingRule>();
  for (Object group : groups.getChildren(GROUP_ELEMENT_NAME)) {
    Element groupElement = (Element)group;

    // Grouping type.
    String groupingTypeId = groupElement.getChildText(TYPE_ELEMENT_NAME);
    ArrangementSettingsToken groupingType = StdArrangementTokens.byId(groupingTypeId);
    if (groupingType == null) {
      groupingType = myMixin.deserializeToken(groupingTypeId);
    }
    if (groupingType == null) {
      LOG.warn(String.format("Can't deserialize grouping type token by id '%s'", groupingTypeId));
      continue;
    }

    // Order type.
    String orderTypeId = groupElement.getChildText(ORDER_TYPE_ELEMENT_NAME);
    ArrangementSettingsToken orderType = StdArrangementTokens.byId(orderTypeId);
    if (orderType == null) {
      orderType = myMixin.deserializeToken(orderTypeId);
    }
    if (orderType == null) {
      LOG.warn(String.format("Can't deserialize grouping order type token by id '%s'", orderTypeId));
      continue;
    }
    groupings.add(new ArrangementGroupingRule(groupingType, orderType));
  }
  return groupings;
}
项目:consulo    文件:ArrangementSettingsSerializationTest.java   
@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);
}
项目:consulo-java    文件:JavaRearranger.java   
@NotNull
@Override
public List<JavaElementArrangementEntry> parse(
        @NotNull PsiElement root,
        @Nullable Document document,
        @NotNull Collection<TextRange> ranges,
        @NotNull ArrangementSettings settings)
{
    // Following entries are subject to arrangement: class, interface, field, method.
    JavaArrangementParseInfo parseInfo = new JavaArrangementParseInfo();
    root.accept(new JavaArrangementVisitor(parseInfo, document, ranges, settings));
    for(ArrangementGroupingRule rule : settings.getGroupings())
    {
        if(GETTERS_AND_SETTERS.equals(rule.getGroupingType()))
        {
            setupGettersAndSetters(parseInfo);
        }
        else if(DEPENDENT_METHODS.equals(rule.getGroupingType()))
        {
            setupUtilityMethods(parseInfo, rule.getOrderType());
        }
        else if(OVERRIDDEN_METHODS.equals(rule.getGroupingType()))
        {
            setupOverriddenMethods(parseInfo);
        }
    }
    setupFieldInitializationDependencies(parseInfo.getFieldDependencyRoots());
    return parseInfo.getEntries();
}
项目:consulo-java    文件:JavaArrangementVisitor.java   
@NotNull
private static Set<ArrangementSettingsToken> getGroupingRules(@NotNull ArrangementSettings settings)
{
    Set<ArrangementSettingsToken> groupingRules = ContainerUtilRt.newHashSet();
    for(ArrangementGroupingRule rule : settings.getGroupings())
    {
        groupingRules.add(rule.getGroupingType());
    }
    return groupingRules;
}
项目:intellij-ce-playground    文件:AbstractRearrangerTest.java   
@NotNull
protected static ArrangementGroupingRule group(@NotNull ArrangementSettingsToken type) {
  return group(type, KEEP);
}
项目:intellij-ce-playground    文件:AbstractRearrangerTest.java   
@NotNull
protected static ArrangementGroupingRule group(@NotNull ArrangementSettingsToken type, @NotNull ArrangementSettingsToken order) {
  return new ArrangementGroupingRule(type, order);
}
项目:intellij-ce-playground    文件:AbstractRearrangerTest.java   
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(new Runnable() {
      @Override
      public void run() {
        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);
  engine.arrange(myFixture.getEditor(), myFixture.getFile(), info.ranges);

  // Check expectation.
  info = parse(expected);
  assertEquals(info.text, myFixture.getEditor().getDocument().getText());
  for (FoldingInfo it : info.foldings) {
    FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(it.start);
    assertNotNull("Expected to find fold region at offset " + it.start, foldRegion);
    assertEquals(it.end, foldRegion.getEndOffset());
  }
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
private static ArrangementGroupingRule group(@NotNull ArrangementSettingsToken token) {
  return new ArrangementGroupingRule(token);
}