Search in sources :

Example 6 with ArrangementCompositeMatchCondition

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

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

Example 8 with ArrangementCompositeMatchCondition

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

the class ArrangementMatchNodeComponentFactory method getComponent.

/**
   * Allows to build UI component for the given model.
   *
   * @param rendererTarget      target model element for which UI component should be built
   * @param rule                rule which contains given 'renderer target' condition and serves as
   *                            a data entry for the target list model
   * @param allowModification   flag which indicates whether given model can be changed at future
   * @return renderer for the given model
   */
@NotNull
public ArrangementUiComponent getComponent(@NotNull final ArrangementMatchCondition rendererTarget, @NotNull final StdArrangementMatchRule rule, final boolean allowModification) {
    final Ref<ArrangementUiComponent> ref = new Ref<>();
    rendererTarget.invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            RemoveAtomConditionCallback callback = allowModification ? new RemoveAtomConditionCallback(rule) : null;
            ArrangementUiComponent component = new ArrangementAtomMatchConditionComponent(mySettingsManager, myColorsProvider, condition, callback);
            ref.set(component);
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            ref.set(new ArrangementAndMatchConditionComponent(rule, condition, ArrangementMatchNodeComponentFactory.this, mySettingsManager, allowModification));
        }
    });
    return ref.get();
}
Also used : ArrangementUiComponent(com.intellij.psi.codeStyle.arrangement.std.ArrangementUiComponent) Ref(com.intellij.openapi.util.Ref) ArrangementMatchConditionVisitor(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor) ArrangementAtomMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition) ArrangementAtomMatchConditionComponent(com.intellij.application.options.codeStyle.arrangement.component.ArrangementAtomMatchConditionComponent) ArrangementCompositeMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition) ArrangementAndMatchConditionComponent(com.intellij.application.options.codeStyle.arrangement.component.ArrangementAndMatchConditionComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ArrangementCompositeMatchCondition

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

the class ArrangementUtil method combine.

//endregion
@NotNull
public static ArrangementMatchCondition combine(@NotNull ArrangementMatchCondition... nodes) {
    final ArrangementCompositeMatchCondition result = new ArrangementCompositeMatchCondition();
    final ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition node) {
            result.addOperand(node);
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition node) {
            for (ArrangementMatchCondition operand : node.getOperands()) {
                operand.invite(this);
            }
        }
    };
    for (ArrangementMatchCondition node : nodes) {
        node.invite(visitor);
    }
    return result.getOperands().size() == 1 ? result.getOperands().iterator().next() : 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) NotNull(org.jetbrains.annotations.NotNull) ArrangementMatchCondition(com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ArrangementCompositeMatchCondition

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

the class StdArrangementExtendableSettings method removeAliasRuleToken.

@NotNull
private static ArrangementCompositeMatchCondition removeAliasRuleToken(final ArrangementMatchCondition original) {
    final ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    original.invite(new ArrangementMatchConditionVisitor() {

        @Override
        public void visit(@NotNull ArrangementAtomMatchCondition condition) {
            if (!ArrangementUtil.isAliasedCondition(condition)) {
                composite.addOperand(condition);
            }
        }

        @Override
        public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
            for (ArrangementMatchCondition c : condition.getOperands()) {
                c.invite(this);
            }
        }
    });
    return composite;
}
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)

Aggregations

ArrangementCompositeMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition)16 ArrangementAtomMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition)15 ArrangementMatchConditionVisitor (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor)9 ArrangementMatchCondition (com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition)8 NotNull (org.jetbrains.annotations.NotNull)6 StdArrangementMatchRule (com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)5 Ref (com.intellij.openapi.util.Ref)4 Nullable (org.jetbrains.annotations.Nullable)4 Test (org.junit.Test)4 StdArrangementEntryMatcher (com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher)3 ArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken)3 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 ModifierAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.ModifierAwareArrangementEntry)1 TypeAwareArrangementEntry (com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry)1 ArrangementSectionRule (com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule)1 ArrangementUiComponent (com.intellij.psi.codeStyle.arrangement.std.ArrangementUiComponent)1 CompositeArrangementSettingsToken (com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken)1 THashSet (gnu.trove.THashSet)1