Search in sources :

Example 26 with ArrangementAtomMatchCondition

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

the class DefaultArrangementEntryMatcherSerializerTest method simpleMatchers.

@Test
public void simpleMatchers() {
    doTest(new ArrangementAtomMatchCondition(CLASS));
    doTest(new ArrangementAtomMatchCondition(PRIVATE));
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Test(org.junit.Test)

Example 27 with ArrangementAtomMatchCondition

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

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

Example 29 with ArrangementAtomMatchCondition

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

the class ArrangementSectionRuleManager method getSectionRuleData.

@Nullable
public ArrangementSectionRuleData getSectionRuleData(@NotNull ArrangementMatchCondition condition) {
    final Ref<Boolean> isStart = new Ref<>();
    final Ref<String> text = new Ref<>();
    condition.invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            final ArrangementSettingsToken type = condition.getType();
            if (type.equals(START_SECTION)) {
                isStart.set(true);
            } else if (type.equals(END_SECTION)) {
                isStart.set(false);
            } else if (type.equals(TEXT)) {
                text.set(condition.getValue().toString());
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            for (ArrangementMatchCondition c : condition.getOperands()) {
                c.invite(this);
                if (!text.isNull() && !isStart.isNull()) {
                    return;
                }
            }
        }
    });
    if (isStart.isNull()) {
        return null;
    }
    return new ArrangementSectionRuleData(processSectionText(StringUtil.notNullize(text.get())), isStart.get());
}
Also used : Ref(com.intellij.openapi.util.Ref) ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) CompositeArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with ArrangementAtomMatchCondition

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

the class ArrangementSettingsSerializationTest method testDefaultGroupingFilter.

@Test
public void testDefaultGroupingFilter() {
    final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME);
    final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
    final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
    final StdArrangementSettings settings = new StdArrangementSettings();
    settings.addGrouping(groupingRule);
    settings.addRule(rule);
    final StdArrangementSettings defaultSettings = new StdArrangementSettings();
    defaultSettings.addGrouping(groupingRule);
    final Element holder = doSerializationTest(settings, defaultSettings);
    assertTrue(holder.getChildren().size() == 1);
    assertNull(holder.getChild("groups"));
    assertNotNull(holder.getChild("rules"));
}
Also used : ArrangementGroupingRule(com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Element(org.jdom.Element) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementSettings(com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) Test(org.junit.Test)

Aggregations

ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)31 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)15 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)13 Test (org.junit.Test)13 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)11 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)11 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)9 NotNull (org.jetbrains.annotations.NotNull)9 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)6 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)6 StdArrangementSettings (com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings)6 Element (org.jdom.Element)6 Nullable (org.jetbrains.annotations.Nullable)5 Ref (com.intellij.openapi.util.Ref)4 ModifierAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)3 TypeAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry)3 Expectations (org.jmock.Expectations)2 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