Search in sources :

Example 1 with ArrangementCompositeMatchCondition

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

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

Example 3 with ArrangementCompositeMatchCondition

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

the class DefaultArrangementEntryMatcherSerializerTest method compositeMatchers.

@Test
public void compositeMatchers() {
    ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
    condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
    condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
    doTest(condition);
    condition = new ArrangementCompositeMatchCondition();
    condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
    condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));
    condition.addOperand(new ArrangementAtomMatchCondition(STATIC));
    condition.addOperand(new ArrangementAtomMatchCondition(FINAL));
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) Test(org.junit.Test)

Example 4 with ArrangementCompositeMatchCondition

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

the class DefaultArrangementEntryMatcherSerializerTest method conditionsOrder.

@Test
public void conditionsOrder() {
    // Inspired by IDEA-91826.
    ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
    ArrangementSettingsToken typeToPreserve = FIELD;
    Set<ArrangementSettingsToken> modifiersToPreserve = ContainerUtilRt.newHashSet(PUBLIC, STATIC, FINAL);
    condition.addOperand(new ArrangementAtomMatchCondition(typeToPreserve, typeToPreserve));
    for (ArrangementSettingsToken modifier : modifiersToPreserve) {
        condition.addOperand(new ArrangementAtomMatchCondition(modifier, modifier));
    }
    Element element = mySerializer.serialize(new StdArrangementEntryMatcher(condition));
    assertNotNull(element);
    // Change hash-container data distribution at the composite condition.
    for (ArrangementSettingsToken type : StdArrangementTokens.EntryType.values()) {
        if (type != typeToPreserve) {
            condition.addOperand(new ArrangementAtomMatchCondition(type, type));
        }
    }
    for (ArrangementSettingsToken modifier : StdArrangementTokens.Modifier.values()) {
        if (!modifiersToPreserve.contains(modifier)) {
            condition.addOperand(new ArrangementAtomMatchCondition(modifier, modifier));
        }
    }
    // Revert state to the initial one.
    for (ArrangementSettingsToken type : StdArrangementTokens.EntryType.values()) {
        if (type != typeToPreserve) {
            condition.removeOperand(new ArrangementAtomMatchCondition(type, type));
        }
    }
    for (ArrangementSettingsToken modifier : StdArrangementTokens.Modifier.values()) {
        if (!modifiersToPreserve.contains(modifier)) {
            condition.removeOperand(new ArrangementAtomMatchCondition(modifier, modifier));
        }
    }
    // Check that the order is the same
    Element actual = mySerializer.serialize(new StdArrangementEntryMatcher(condition));
    assertNotNull(actual);
    checkElements(element, actual);
}
Also used : ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) Test(org.junit.Test)

Example 5 with ArrangementCompositeMatchCondition

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

the class ArrangementUtil method buildMatcher.

@Nullable
public static ArrangementEntryMatcher buildMatcher(@NotNull ArrangementMatchCondition condition) {
    final Ref<ArrangementEntryMatcher> result = new Ref<>();
    final Stack<CompositeArrangementEntryMatcher> composites = new Stack<>();
    ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            ArrangementEntryMatcher matcher = buildMatcher(condition);
            if (matcher == null) {
                return;
            }
            if (composites.isEmpty()) {
                result.set(matcher);
            } else {
                composites.peek().addMatcher(matcher);
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            composites.push(new CompositeArrangementEntryMatcher());
            try {
                for (ArrangementMatchCondition operand : condition.getOperands()) {
                    operand.invite(this);
                }
            } finally {
                CompositeArrangementEntryMatcher matcher = composites.pop();
                if (composites.isEmpty()) {
                    result.set(matcher);
                }
            }
        }
    };
    condition.invite(visitor);
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) 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) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)16 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)15 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)9 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)8 NotNull (org.jetbrains.annotations.NotNull)6 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)5 Ref (com.intellij.openapi.util.Ref)4 Nullable (org.jetbrains.annotations.Nullable)4 Test (org.junit.Test)4 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)3 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)3 ArrangementAndMatchConditionComponent (com.intellij.application.options.codeStyle.arrangement.component.ArrangementAndMatchConditionComponent)1 ArrangementAtomMatchConditionComponent (com.intellij.application.options.codeStyle.arrangement.component.ArrangementAtomMatchConditionComponent)1 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 ModifierAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)1 TypeAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry)1 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)1 ArrangementUiComponent (com.intellij.psi.codeStyle.arrangement.std.ArrangementUiComponent)1 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)1 THashSet (gnu.trove.THashSet)1