Search in sources :

Example 6 with ArrangementAtomMatchCondition

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

the class ArrangementSettingsSerializationTest method testEmptyGroupings.

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

Example 7 with ArrangementAtomMatchCondition

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

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

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

the class DefaultArrangementEntryMatcherSerializerTest method nameConditionOnly.

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

Example 10 with ArrangementAtomMatchCondition

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

the class StandardArrangementEntryMatcherTest method atomCondition.

@Test
public void atomCondition() {
    ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
    StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
    assertEquals(condition, matcher.getCondition());
    final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
    final TypeAwareArrangementEntry classEntry = myMockery.mock(TypeAwareArrangementEntry.class, "class");
    final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
    myMockery.checking(new Expectations() {

        {
            allowing(fieldEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
            allowing(classEntry).getTypes();
            will(returnValue(ContainerUtilRt.newHashSet(CLASS)));
            allowing(publicEntry).getModifiers();
            will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
        }
    });
    assertTrue(matcher.isMatched(fieldEntry));
    assertFalse(matcher.isMatched(classEntry));
    assertFalse(matcher.isMatched(publicEntry));
}
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) 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