use of com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken in project intellij-community by JetBrains.
the class ByModifierArrangementEntryMatcher method isMatched.
@Override
public boolean isMatched(@NotNull ArrangementEntry entry) {
if (entry instanceof ModifierAwareArrangementEntry) {
final Set<ArrangementSettingsToken> modifiers = ((ModifierAwareArrangementEntry) entry).getModifiers();
for (ArrangementAtomMatchCondition condition : myModifiers) {
final Object value = condition.getValue();
boolean isInverted = value instanceof Boolean && !((Boolean) value);
if (isInverted == modifiers.contains(condition.getType())) {
return false;
}
}
return true;
}
return false;
}
use of com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken in project intellij-community by JetBrains.
the class ByTypeArrangementEntryMatcher method isMatched.
@Override
public boolean isMatched(@NotNull ArrangementEntry entry) {
if (entry instanceof TypeAwareArrangementEntry) {
final Set<ArrangementSettingsToken> types = ((TypeAwareArrangementEntry) entry).getTypes();
for (ArrangementAtomMatchCondition condition : myTypes) {
final Object value = condition.getValue();
boolean isInverted = value instanceof Boolean && !((Boolean) value);
if (isInverted == types.contains(condition.getType())) {
return false;
}
}
return true;
}
return false;
}
use of com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken in project intellij-community by JetBrains.
the class DefaultArrangementEntryMatcherSerializer method deserializeAtomCondition.
@Nullable
private ArrangementMatchCondition deserializeAtomCondition(@NotNull Element matcherElement) {
String id = matcherElement.getName();
ArrangementSettingsToken token = StdArrangementTokens.byId(id);
boolean processInnerText = true;
if (token != null && (StdArrangementTokens.General.TYPE.equals(token) || StdArrangementTokens.General.MODIFIER.equals(token))) {
// Backward compatibility with old arrangement settings format.
id = matcherElement.getText();
if (StringUtil.isEmpty(id)) {
LOG.warn("Can't deserialize match condition at legacy format");
return null;
}
token = StdArrangementTokens.byId(id);
processInnerText = false;
}
if (token == null) {
token = myMixin.deserializeToken(id);
}
if (token == null) {
LOG.warn(String.format("Can't deserialize match condition with id '%s'", id));
return null;
}
Object value = token;
String text = matcherElement.getText();
if (text != null && processInnerText) {
text = StringUtil.unescapeStringCharacters(matcherElement.getText());
if (!StringUtil.isEmpty(text)) {
final Boolean booleanValue = parseBooleanValue(text);
if (booleanValue != null) {
value = booleanValue;
} else {
value = text;
}
}
}
return new ArrangementAtomMatchCondition(token, value);
}
use of com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken 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.std.ArrangementSettingsToken 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);
}
Aggregations