Search in sources :

Example 6 with ArrangementMatchCondition

use of com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition 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 7 with ArrangementMatchCondition

use of com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition in project intellij-community by JetBrains.

the class ArrangementMatchingRuleEditor method refreshConditions.

/**
   * Disable conditions not applicable at the current context (e.g. disable 'synchronized' if no 'method' is selected).
   */
private void refreshConditions() {
    Pair<ArrangementMatchCondition, ArrangementSettingsToken> pair = buildCondition();
    ArrangementMatchCondition condition = pair == null ? null : pair.first;
    for (ArrangementUiComponent component : myComponents.values()) {
        ArrangementSettingsToken token = component.getToken();
        if (token == null) {
            continue;
        }
        boolean enabled = isEnabled(condition, token);
        component.setEnabled(enabled);
        if (!enabled) {
            component.setSelected(false);
        }
    }
}
Also used : ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)

Example 8 with ArrangementMatchCondition

use of com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition 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 9 with ArrangementMatchCondition

use of com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition 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 10 with ArrangementMatchCondition

use of com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition in project intellij-community by JetBrains.

the class ArrangementUtil method combine.

//endregion
@NotNull
public static ArrangementMatchCondition combine(@NotNull ArrangementMatchCondition... nodes) {
    final ArrangementCompositeMatchCondition result = new ArrangementCompositeMatchCondition();
    final ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition node) {
            result.addOperand(node);
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition node) {
            for (ArrangementMatchCondition operand : node.getOperands()) {
                operand.invite(this);
            }
        }
    };
    for (ArrangementMatchCondition node : nodes) {
        node.invite(visitor);
    }
    return result.getOperands().size() == 1 ? result.getOperands().iterator().next() : result;
}
Also used : ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) NotNull(org.jetbrains.annotations.NotNull) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)14 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)11 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)8 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)8 NotNull (org.jetbrains.annotations.NotNull)8 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)6 Nullable (org.jetbrains.annotations.Nullable)4 Ref (com.intellij.openapi.util.Ref)3 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)3 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 ArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule)1 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)1 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)1 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)1 THashSet (gnu.trove.THashSet)1