Search in sources :

Example 1 with ArrangementSettingsToken

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

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

the class ByTypeArrangementEntryMatcher method isMatched.

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

Example 3 with ArrangementSettingsToken

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

the class DefaultArrangementEntryMatcherSerializer method deserializeAtomCondition.

@Nullable
private ArrangementMatchCondition deserializeAtomCondition(@NotNull Element matcherElement) {
    String id = matcherElement.getName();
    ArrangementSettingsToken token = StdArrangementTokens.byId(id);
    boolean processInnerText = true;
    if (token != null && (StdArrangementTokens.General.TYPE.equals(token) || StdArrangementTokens.General.MODIFIER.equals(token))) {
        // Backward compatibility with old arrangement settings format.
        id = matcherElement.getText();
        if (StringUtil.isEmpty(id)) {
            LOG.warn("Can't deserialize match condition at legacy format");
            return null;
        }
        token = StdArrangementTokens.byId(id);
        processInnerText = false;
    }
    if (token == null) {
        token = myMixin.deserializeToken(id);
    }
    if (token == null) {
        LOG.warn(String.format("Can't deserialize match condition with id '%s'", id));
        return null;
    }
    Object value = token;
    String text = matcherElement.getText();
    if (text != null && processInnerText) {
        text = StringUtil.unescapeStringCharacters(matcherElement.getText());
        if (!StringUtil.isEmpty(text)) {
            final Boolean booleanValue = parseBooleanValue(text);
            if (booleanValue != null) {
                value = booleanValue;
            } else {
                value = text;
            }
        }
    }
    return new ArrangementAtomMatchCondition(token, value);
}
Also used : ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ArrangementSettingsToken

use of com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken 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 5 with ArrangementSettingsToken

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

Aggregations

ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)13 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)6 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)3 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)3 TextRange (com.intellij.openapi.util.TextRange)2 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)2 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)2 ArrayList (java.util.ArrayList)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 Ref (com.intellij.openapi.util.Ref)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 ModifierAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)1 TypeAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry)1 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)1 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)1 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)1 MethodSignatureBackedByPsiMethod (com.intellij.psi.util.MethodSignatureBackedByPsiMethod)1