use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class StdArrangementExtendableSettings method getRuleSequence.
@Nullable
private List<StdArrangementMatchRule> getRuleSequence(@NotNull final StdArrangementMatchRule rule, @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
final List<StdArrangementMatchRule> seqRule = ContainerUtil.newSmartList();
rule.getMatcher().getCondition().invite(new ArrangementMatchConditionVisitor() {
@Override
public void visit(@NotNull ArrangementAtomMatchCondition condition) {
final StdArrangementRuleAliasToken token = tokenIdToDefinition.get(condition.getType().getId());
if (token != null && !token.getDefinitionRules().isEmpty()) {
seqRule.addAll(token.getDefinitionRules());
}
}
@Override
public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
for (ArrangementMatchCondition operand : condition.getOperands()) {
if (!seqRule.isEmpty()) {
return;
}
operand.invite(this);
}
}
});
return seqRule;
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class JavaRearranger method and.
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) {
if (conditions.length == 1) {
matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(conditions[0]))));
return;
}
ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
for (ArrangementSettingsToken condition : conditions) {
composite.addOperand(new ArrangementAtomMatchCondition(condition));
}
matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class ArrangementSectionRulesControl method createRuleAliasEditDialog.
@NotNull
public ArrangementRuleAliasDialog createRuleAliasEditDialog() {
final Set<String> tokenIds = new THashSet<>();
final List<ArrangementSectionRule> sections = getSections();
for (ArrangementSectionRule section : sections) {
for (StdArrangementMatchRule rule : section.getMatchRules()) {
rule.getMatcher().getCondition().invite(new ArrangementMatchConditionVisitor() {
@Override
public void visit(@NotNull ArrangementAtomMatchCondition condition) {
if (ArrangementUtil.isAliasedCondition(condition)) {
tokenIds.add(condition.getType().getId());
}
}
@Override
public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
for (ArrangementMatchCondition operand : condition.getOperands()) {
operand.invite(this);
}
}
});
}
}
final Collection<StdArrangementRuleAliasToken> aliases = getRulesAliases();
assert aliases != null;
return new ArrangementRuleAliasDialog(null, mySettingsManager, myColorsProvider, aliases, tokenIds);
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class DefaultArrangementEntryMatcherSerializerTest method compositeConditionWithName.
@Test
public void compositeConditionWithName() {
ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
doTest(condition);
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition in project intellij-community by JetBrains.
the class StandardArrangementEntryMatcherTest method compositeAndCondition.
@Test
public void compositeAndCondition() {
ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));
StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
assertEquals(condition, matcher.getCondition());
final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field");
final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method");
final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field");
final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field");
myMockery.checking(new Expectations() {
{
allowing(fieldEntry).getTypes();
will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
allowing(publicEntry).getModifiers();
will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
allowing(privateFieldEntry).getTypes();
will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
allowing(privateFieldEntry).getModifiers();
will(returnValue(ContainerUtilRt.newHashSet(PRIVATE)));
allowing(publicMethodEntry).getTypes();
will(returnValue(ContainerUtilRt.newHashSet(METHOD)));
allowing(publicMethodEntry).getModifiers();
will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
allowing(publicFieldEntry).getTypes();
will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
allowing(publicFieldEntry).getModifiers();
will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
allowing(publicStaticFieldEntry).getTypes();
will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
allowing(publicStaticFieldEntry).getModifiers();
will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC)));
}
});
assertFalse(matcher.isMatched(fieldEntry));
assertFalse(matcher.isMatched(publicEntry));
assertFalse(matcher.isMatched(privateFieldEntry));
assertFalse(matcher.isMatched(publicMethodEntry));
assertTrue(matcher.isMatched(publicFieldEntry));
assertTrue(matcher.isMatched(publicStaticFieldEntry));
}
Aggregations