Search in sources :

Example 1 with StdArrangementMatchRule

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

the class AbstractRearrangerTest method nameRule.

@NotNull
protected static StdArrangementMatchRule nameRule(@NotNull String nameFilter, @NotNull ArrangementSettingsToken... tokens) {
    if (tokens.length == 0) {
        return new StdArrangementMatchRule(new StdArrangementEntryMatcher(atom(nameFilter)));
    } else {
        ArrangementAtomMatchCondition[] conditions = new ArrangementAtomMatchCondition[tokens.length + 1];
        conditions[0] = atom(nameFilter);
        for (int i = 0; i < tokens.length; i++) conditions[i + 1] = atom(tokens[i]);
        ArrangementMatchCondition compositeCondition = ArrangementUtil.combine(conditions);
        return new StdArrangementMatchRule(new StdArrangementEntryMatcher(compositeCondition));
    }
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with StdArrangementMatchRule

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

the class ActionScriptRearranger method getDefaultMatchRules.

public static List<StdArrangementMatchRule> getDefaultMatchRules() {
    // more or less close to Coding Conventions at http://sourceforge.net/adobe/flexsdk/wiki/Coding%20Conventions/
    final List<StdArrangementMatchRule> matchRules = new ArrayList<>();
    final Set<ArrangementSettingsToken> visibility = VISIBILITY_MODIFIERS;
    // static initialization blocks
    addRule(matchRules, STATIC_INIT);
    // constants
    addRule(matchRules, CONST);
    // static vars
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, VAR, modifier, STATIC);
    }
    // static properties
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, PROPERTY, modifier, STATIC);
    }
    // static methods
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, METHOD, modifier, STATIC);
    }
    // constructor
    addRule(matchRules, CONSTRUCTOR);
    // vars
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, VAR, modifier);
    }
    // properties
    addRule(matchRules, PROPERTY, OVERRIDE);
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, PROPERTY, modifier);
    }
    // methods
    addRule(matchRules, METHOD, OVERRIDE);
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, METHOD, modifier);
    }
    // event handlers
    addRule(matchRules, EVENT_HANDLER, OVERRIDE);
    for (ArrangementSettingsToken modifier : visibility) {
        addRule(matchRules, EVENT_HANDLER, modifier);
    }
    return matchRules;
}
Also used : ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 3 with StdArrangementMatchRule

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

the class StdArrangementExtendableSettings method appendExpandedRules.

public void appendExpandedRules(@NotNull final StdArrangementMatchRule rule, @NotNull final List<StdArrangementMatchRule> rules, @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
    final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition);
    if (sequence == null || sequence.isEmpty()) {
        rules.add(rule);
        return;
    }
    final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition());
    for (StdArrangementMatchRule matchRule : sequence) {
        final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone();
        extendedRule.addOperand(matchRule.getMatcher().getCondition());
        rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule)));
    }
}
Also used : ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 4 with StdArrangementMatchRule

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

the class StdArrangementExtendableSettings method getExtendedSectionRules.

@Override
public List<ArrangementSectionRule> getExtendedSectionRules() {
    synchronized (myExtendedSectionRules) {
        if (myExtendedSectionRules.isEmpty()) {
            final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition = new THashMap<>(myRulesAliases.size());
            for (StdArrangementRuleAliasToken alias : myRulesAliases) {
                final String id = alias.getId();
                tokenIdToDefinition.put(id, alias);
            }
            final List<ArrangementSectionRule> sections = getSections();
            for (ArrangementSectionRule section : sections) {
                final List<StdArrangementMatchRule> extendedRules = new ArrayList<>();
                for (StdArrangementMatchRule rule : section.getMatchRules()) {
                    appendExpandedRules(rule, extendedRules, tokenIdToDefinition);
                }
                myExtendedSectionRules.add(ArrangementSectionRule.create(section.getStartComment(), section.getEndComment(), extendedRules));
            }
        }
    }
    return myExtendedSectionRules;
}
Also used : THashMap(gnu.trove.THashMap) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 5 with StdArrangementMatchRule

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

the class ArrangementSettingsSerializationTest method rule.

private static StdArrangementMatchRule rule(boolean byName, @NotNull ArrangementSettingsToken... tokens) {
    final List<ArrangementAtomMatchCondition> conditions = new ArrayList<>();
    for (ArrangementSettingsToken token : tokens) {
        conditions.add(new ArrangementAtomMatchCondition(token));
    }
    final StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(new ArrangementCompositeMatchCondition(conditions));
    return byName ? new StdArrangementMatchRule(matcher, BY_NAME) : new StdArrangementMatchRule(matcher);
}
Also used : ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrayList(java.util.ArrayList) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) 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