use of com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition 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();
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition 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;
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition 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();
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method all.
@Test
public void all() {
final StdArrangementSettings settings = new StdArrangementSettings();
settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME));
final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME));
doSerializationTest(settings, new StdArrangementSettings());
}
use of com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition in project intellij-community by JetBrains.
the class ArrangementSettingsSerializationTest method testDefaultRulesFilter.
@Test
public void testDefaultRulesFilter() {
final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME);
final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);
final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME);
final StdArrangementSettings settings = new StdArrangementSettings();
settings.addGrouping(groupingRule);
settings.addRule(rule);
final StdArrangementSettings defaultSettings = new StdArrangementSettings();
defaultSettings.addRule(rule);
final Element holder = doSerializationTest(settings, defaultSettings);
assertTrue(holder.getChildren().size() == 1);
assertNotNull(holder.getChild("groups"));
assertNull(holder.getChild("rules"));
}
Aggregations