use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class StdArrangementExtendableSettings method appendExpandedRules.
public void appendExpandedRules(@NotNull final StdArrangementMatchRule rule, @NotNull final List<StdArrangementMatchRule> rules, @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition);
if (sequence == null || sequence.isEmpty()) {
rules.add(rule);
return;
}
final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition());
for (StdArrangementMatchRule matchRule : sequence) {
final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone();
extendedRule.addOperand(matchRule.getMatcher().getCondition());
rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule)));
}
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition 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);
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class DefaultArrangementEntryMatcherSerializerTest method compositeMatchers.
@Test
public void compositeMatchers() {
ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
doTest(condition);
condition = new ArrangementCompositeMatchCondition();
condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));
condition.addOperand(new ArrangementAtomMatchCondition(STATIC));
condition.addOperand(new ArrangementAtomMatchCondition(FINAL));
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition 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);
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition 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();
}
Aggregations