Search in sources :

Example 1 with ArrangementMatchCondition

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

the class AbstractRearrangerTest method nameRule.

@NotNull
protected static StdArrangementMatchRule nameRule(@NotNull String nameFilter, @NotNull ArrangementSettingsToken... tokens) {
    if (tokens.length == 0) {
        return new StdArrangementMatchRule(new StdArrangementEntryMatcher(atom(nameFilter)));
    } else {
        ArrangementAtomMatchCondition[] conditions = new ArrangementAtomMatchCondition[tokens.length + 1];
        conditions[0] = atom(nameFilter);
        for (int i = 0; i < tokens.length; i++) conditions[i + 1] = atom(tokens[i]);
        ArrangementMatchCondition compositeCondition = ArrangementUtil.combine(conditions);
        return new StdArrangementMatchRule(new StdArrangementEntryMatcher(compositeCondition));
    }
}
Also used : ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) StdArrangementEntryMatcher(com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ArrangementMatchCondition

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

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

the class ArrangementUtil method buildMatcher.

@Nullable
public static ArrangementEntryMatcher buildMatcher(@NotNull ArrangementMatchCondition condition) {
    final Ref<ArrangementEntryMatcher> result = new Ref<>();
    final Stack<CompositeArrangementEntryMatcher> composites = new Stack<>();
    ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            ArrangementEntryMatcher matcher = buildMatcher(condition);
            if (matcher == null) {
                return;
            }
            if (composites.isEmpty()) {
                result.set(matcher);
            } else {
                composites.peek().addMatcher(matcher);
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            composites.push(new CompositeArrangementEntryMatcher());
            try {
                for (ArrangementMatchCondition operand : condition.getOperands()) {
                    operand.invite(this);
                }
            } finally {
                CompositeArrangementEntryMatcher matcher = composites.pop();
                if (composites.isEmpty()) {
                    result.set(matcher);
                }
            }
        }
    };
    condition.invite(visitor);
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) NotNull(org.jetbrains.annotations.NotNull) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ArrangementMatchCondition

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

the class ArrangementUtil method extractTokens.

@NotNull
public static Map<ArrangementSettingsToken, Object> extractTokens(@NotNull ArrangementMatchCondition condition) {
    final Map<ArrangementSettingsToken, Object> result = ContainerUtilRt.newHashMap();
    condition.invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            ArrangementSettingsToken type = condition.getType();
            Object value = condition.getValue();
            result.put(condition.getType(), type.equals(value) ? null : value);
            if (type instanceof CompositeArrangementToken) {
                Set<ArrangementSettingsToken> tokens = ((CompositeArrangementToken) type).getAdditionalTokens();
                for (ArrangementSettingsToken token : tokens) {
                    result.put(token, null);
                }
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            for (ArrangementMatchCondition operand : condition.getOperands()) {
                operand.invite(this);
            }
        }
    });
    return result;
}
Also used : ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ArrangementMatchCondition

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

the class ArrangementUtil method parseType.

//endregion
@Nullable
public static ArrangementSettingsToken parseType(@NotNull ArrangementMatchCondition condition) throws IllegalArgumentException {
    final Ref<ArrangementSettingsToken> result = new Ref<>();
    condition.invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            ArrangementSettingsToken type = condition.getType();
            if (StdArrangementTokenType.ENTRY_TYPE.is(condition.getType()) || MODIFIER_AS_TYPE.contains(type)) {
                result.set(condition.getType());
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            for (ArrangementMatchCondition c : condition.getOperands()) {
                c.invite(this);
                if (result.get() != null) {
                    return;
                }
            }
        }
    });
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) 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)

Aggregations

ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)14 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)11 ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)8 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)8 NotNull (org.jetbrains.annotations.NotNull)8 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)6 Nullable (org.jetbrains.annotations.Nullable)4 Ref (com.intellij.openapi.util.Ref)3 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)3 ArrangementRuleAliasDialog (com.intellij.application.options.codeStyle.arrangement.match.tokens.ArrangementRuleAliasDialog)1 ArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementMatchRule)1 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)1 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)1 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)1 THashSet (gnu.trove.THashSet)1