Search in sources :

Example 11 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule in project intellij-community by JetBrains.

the class ArrangementMatchingRuleEditor method apply.

private void apply() {
    final Pair<ArrangementMatchCondition, ArrangementSettingsToken> pair = buildCondition();
    final Object modelValue;
    if (pair == null) {
        modelValue = new EmptyArrangementRuleComponent(myControl.getRowHeight(myRow));
    } else {
        modelValue = new StdArrangementMatchRule(new StdArrangementEntryMatcher(pair.first), pair.second);
    }
    myControl.getModel().set(myRow, modelValue);
    myControl.repaintRows(myRow, myRow, true);
}
Also used : StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 12 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule in project intellij-community by JetBrains.

the class ArrangementSectionRuleManager method createDefaultSectionRule.

@NotNull
public StdArrangementMatchRule createDefaultSectionRule() {
    final ArrangementAtomMatchCondition type = new ArrangementAtomMatchCondition(START_SECTION);
    final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(TEXT, createDefaultSectionText());
    final ArrangementMatchCondition condition = ArrangementUtil.combine(type, text);
    return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition));
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule in project intellij-community by JetBrains.

the class ArrangementSectionRulesControl method getSections.

public List<ArrangementSectionRule> getSections() {
    if (getModel().getSize() <= 0) {
        return Collections.emptyList();
    }
    final List<ArrangementSectionRule> result = ContainerUtil.newArrayList();
    final List<StdArrangementMatchRule> buffer = ContainerUtil.newArrayList();
    String currentSectionStart = null;
    for (int i = 0; i < getModel().getSize(); i++) {
        final Object element = getModel().getElementAt(i);
        if (element instanceof StdArrangementMatchRule) {
            final ArrangementSectionRuleData sectionRule = mySectionRuleManager == null ? null : mySectionRuleManager.getSectionRuleData((StdArrangementMatchRule) element);
            if (sectionRule != null) {
                if (sectionRule.isSectionStart()) {
                    appendBufferedSectionRules(result, buffer, currentSectionStart);
                    currentSectionStart = sectionRule.getText();
                } else {
                    result.add(ArrangementSectionRule.create(StringUtil.notNullize(currentSectionStart), sectionRule.getText(), buffer));
                    buffer.clear();
                    currentSectionStart = null;
                }
            } else {
                if (currentSectionStart == null) {
                    result.add(ArrangementSectionRule.create((StdArrangementMatchRule) element));
                } else {
                    buffer.add((StdArrangementMatchRule) element);
                }
            }
        }
    }
    appendBufferedSectionRules(result, buffer, currentSectionStart);
    return result;
}
Also used : ArrangementSectionRuleData(com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRuleManager.ArrangementSectionRuleData) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 14 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule in project intellij-community by JetBrains.

the class ArrangementRuleAliasControl method setRuleSequences.

public void setRuleSequences(Collection<StdArrangementMatchRule> sequences) {
    myComponents.clear();
    getModel().clear();
    if (sequences == null) {
        return;
    }
    for (StdArrangementMatchRule rule : sequences) {
        getModel().add(rule);
    }
}
Also used : StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 15 with StdArrangementMatchRule

use of com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule 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;
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) ArrayList(java.util.ArrayList) XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Aggregations

StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)22 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)13 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)13 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)7 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)6 StdArrangementSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings)6 Test (org.junit.Test)6 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)5 Element (org.jdom.Element)5 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)2 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)2 ArrayList (java.util.ArrayList)2 ArrangementSectionRuleData (com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRuleManager.ArrangementSectionRuleData)1 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 ArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule)1 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)1 THashMap (gnu.trove.THashMap)1