Search in sources :

Example 1 with ModifierAwareArrangementEntry

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

the class ByModifierArrangementEntryMatcher method isMatched.

@Override
public boolean isMatched(@NotNull ArrangementEntry entry) {
    if (entry instanceof ModifierAwareArrangementEntry) {
        final Set<ArrangementSettingsToken> modifiers = ((ModifierAwareArrangementEntry) entry).getModifiers();
        for (ArrangementAtomMatchCondition condition : myModifiers) {
            final Object value = condition.getValue();
            boolean isInverted = value instanceof Boolean && !((Boolean) value);
            if (isInverted == modifiers.contains(condition.getType())) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ModifierAwareArrangementEntry(com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)

Example 2 with ModifierAwareArrangementEntry

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

Example 3 with ModifierAwareArrangementEntry

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

ModifierAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)3 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)3 TypeAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)1 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)1