Search in sources :

Example 11 with ArrangementCompositeMatchCondition

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

the class StdArrangementExtendableSettings method getRuleSequence.

@Nullable
private List<StdArrangementMatchRule> getRuleSequence(@NotNull final StdArrangementMatchRule rule, @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
    final List<StdArrangementMatchRule> seqRule = ContainerUtil.newSmartList();
    rule.getMatcher().getCondition().invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            final StdArrangementRuleAliasToken token = tokenIdToDefinition.get(condition.getType().getId());
            if (token != null && !token.getDefinitionRules().isEmpty()) {
                seqRule.addAll(token.getDefinitionRules());
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            for (ArrangementMatchCondition operand : condition.getOperands()) {
                if (!seqRule.isEmpty()) {
                    return;
                }
                operand.invite(this);
            }
        }
    });
    return seqRule;
}
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) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ArrangementCompositeMatchCondition

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

the class JavaRearranger method and.

private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) {
    if (conditions.length == 1) {
        matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(conditions[0]))));
        return;
    }
    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for (ArrangementSettingsToken condition : conditions) {
        composite.addOperand(new ArrangementAtomMatchCondition(condition));
    }
    matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) 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 13 with ArrangementCompositeMatchCondition

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

the class ArrangementSectionRulesControl method createRuleAliasEditDialog.

@NotNull
public ArrangementRuleAliasDialog createRuleAliasEditDialog() {
    final Set<String> tokenIds = new THashSet<>();
    final List<ArrangementSectionRule> sections = getSections();
    for (ArrangementSectionRule section : sections) {
        for (StdArrangementMatchRule rule : section.getMatchRules()) {
            rule.getMatcher().getCondition().invite(new ArrangementMatchConditionVisitor() {

                @Override
                public void visit(@NotNull ArrangementAtomMatchCondition condition) {
                    if (ArrangementUtil.isAliasedCondition(condition)) {
                        tokenIds.add(condition.getType().getId());
                    }
                }

                @Override
                public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
                    for (ArrangementMatchCondition operand : condition.getOperands()) {
                        operand.invite(this);
                    }
                }
            });
        }
    }
    final Collection<StdArrangementRuleAliasToken> aliases = getRulesAliases();
    assert aliases != null;
    return new ArrangementRuleAliasDialog(null, mySettingsManager, myColorsProvider, aliases, tokenIds);
}
Also used : ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementRuleAliasDialog(com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) THashSet(gnu.trove.THashSet) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ArrangementCompositeMatchCondition

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

the class DefaultArrangementEntryMatcherSerializerTest method compositeConditionWithName.

@Test
public void compositeConditionWithName() {
    ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
    condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
    condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
    condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
    doTest(condition);
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) Test(org.junit.Test)

Example 15 with ArrangementCompositeMatchCondition

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

the class StandardArrangementEntryMatcherTest method compositeAndCondition.

@Test
public void compositeAndCondition() {
    ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
    condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
    condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));
    StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
    assertEquals(condition, matcher.getCondition());
    final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
    final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
    final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field");
    final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method");
    final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field");
    final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field");
    myMockery.checking(new Expectations() {

        {
            allowing(fieldEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
            allowing(publicEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
            allowing(privateFieldEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
            allowing(privateFieldEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PRIVATE)));
            allowing(publicMethodEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(METHOD)));
            allowing(publicMethodEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
            allowing(publicFieldEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
            allowing(publicFieldEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
            allowing(publicStaticFieldEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
            allowing(publicStaticFieldEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC)));
        }
    });
    assertFalse(matcher.isMatched(fieldEntry));
    assertFalse(matcher.isMatched(publicEntry));
    assertFalse(matcher.isMatched(privateFieldEntry));
    assertFalse(matcher.isMatched(publicMethodEntry));
    assertTrue(matcher.isMatched(publicFieldEntry));
    assertTrue(matcher.isMatched(publicStaticFieldEntry));
}
Also used : Expectations(org.jmock.Expectations) TypeAwareArrangementEntry(com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ModifierAwareArrangementEntry(com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) Test(org.junit.Test)

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