Search in sources :

Example 1 with ArrangementAtomMatchCondition

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

the class ArrangementSectionRule method createSectionRule.

@NotNull
private static StdArrangementMatchRule createSectionRule(@NotNull String comment, @NotNull ArrangementSettingsToken token) {
    final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.TEXT, comment);
    final ArrangementMatchCondition condition = ArrangementUtil.combine(new ArrangementAtomMatchCondition(token), text);
    return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition));
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ArrangementAtomMatchCondition

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

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

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

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

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