@Nullable private static <E extends ArrangementEntry> Collection<E> arrangeByRule(@NotNull List<E> arranged, @NotNull MultiMap<ArrangementMatchRule, E> elementsByRule, @NotNull ArrangementMatchRule rule) { if (elementsByRule.containsKey(rule)) { final Collection<E> arrangedEntries = elementsByRule.remove(rule); // Sort by name if necessary. if (StdArrangementTokens.Order.BY_NAME.equals(rule.getOrderType())) { sortByName((List<E>)arrangedEntries); } arranged.addAll(arrangedEntries); return arrangedEntries; } return null; }
@Override public void visit(@NotNull ArrangementAtomMatchCondition condition) { if (StdArrangementTokens.Regexp.NAME.equals(condition.getType())) { myNamePattern = condition.getValue().toString(); return; } else if (StdArrangementTokens.Regexp.XML_NAMESPACE.equals(condition.getType())) { myNamespacePattern = condition.getValue().toString(); } Object v = condition.getValue(); if (v instanceof ArrangementSettingsToken) { ArrangementSettingsToken token = (ArrangementSettingsToken)v; if (StdArrangementTokens.EntryType.is(token)) { myTypes.add(token); } else if (StdArrangementTokens.Modifier.is(token)) { myModifiers.add(token); } } }
@Nullable private static <E extends ArrangementEntry> Collection<E> arrangeByRule(@Nonnull List<E> arranged, @Nonnull MultiMap<ArrangementMatchRule, E> elementsByRule, @Nonnull ArrangementMatchRule rule) { if (elementsByRule.containsKey(rule)) { final Collection<E> arrangedEntries = elementsByRule.remove(rule); // Sort by name if necessary. if (StdArrangementTokens.Order.BY_NAME.equals(rule.getOrderType())) { sortByName((List<E>)arrangedEntries); } arranged.addAll(arrangedEntries); return arrangedEntries; } return null; }
@Override public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) { if(SUPPORTED_TYPES.contains(token) || SUPPORTED_ORDERS.contains(token) || StdArrangementTokens.Regexp.NAME.equals(token)) { return true; } ArrangementSettingsToken type = null; if(current != null) { type = ArrangementUtil.parseType(current); } if(type == null) { type = NO_TYPE; } Set<ArrangementSettingsToken> modifiers = MODIFIERS_BY_TYPE.get(type); return modifiers != null && modifiers.contains(token); }
private void parseProperties(PsiMethod method, JavaElementArrangementEntry entry) { String propertyName = null; boolean getter = true; if (PropertyUtil.isSimplePropertyGetter(method)) { entry.addModifier(GETTER); propertyName = PropertyUtil.getPropertyNameByGetter(method); } else if (PropertyUtil.isSimplePropertySetter(method)) { entry.addModifier(SETTER); propertyName = PropertyUtil.getPropertyNameBySetter(method); getter = false; } if (!myGroupingRules.contains(StdArrangementTokens.Grouping.GETTERS_AND_SETTERS) || propertyName == null) { return; } PsiClass containingClass = method.getContainingClass(); String className = null; if (containingClass != null) { className = containingClass.getQualifiedName(); } if (className == null) { className = NULL_CONTENT; } if (getter) { myInfo.registerGetter(propertyName, className, entry); } else { myInfo.registerSetter(propertyName, className, entry); } }
@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); }
private void parseProperties(PsiMethod method, JavaElementArrangementEntry entry) { if (!myGroupingRules.contains(StdArrangementTokens.Grouping.GETTERS_AND_SETTERS)) { return; } String propertyName = null; boolean getter = true; if (PropertyUtil.isSimplePropertyGetter(method)) { propertyName = PropertyUtil.getPropertyNameByGetter(method); } else if (PropertyUtil.isSimplePropertySetter(method)) { propertyName = PropertyUtil.getPropertyNameBySetter(method); getter = false; } if (propertyName == null) { return; } PsiClass containingClass = method.getContainingClass(); String className = null; if (containingClass != null) { className = containingClass.getQualifiedName(); } if (className == null) { className = NULL_CONTENT; } if (getter) { myInfo.registerGetter(propertyName, className, entry); } else { myInfo.registerSetter(propertyName, className, entry); } }
@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)) { value = text; } } return new ArrangementAtomMatchCondition(token, value); }
@Override public void visit(@NotNull ArrangementAtomMatchCondition condition) { ArrangementSettingsToken type = condition.getType(); final Element element = new Element(type.getId()); if (StdArrangementTokens.Regexp.is(type)) { element.setText(StringUtil.escapeStringCharacters(condition.getValue().toString())); } register(element); }
@Nullable private static StdArrangementMatchRule createSectionRule(@Nullable String comment, @Nonnull ArrangementSettingsToken token) { if (StringUtil.isEmpty(comment)) { return null; } final ArrangementAtomMatchCondition type = new ArrangementAtomMatchCondition(token); final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.TEXT, comment); final ArrangementMatchCondition condition = ArrangementUtil.combine(type, text); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition)); }
@Nullable private ArrangementMatchCondition deserializeAtomCondition(@Nonnull 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)) { value = text; } } return new ArrangementAtomMatchCondition(token, value); }
@NotNull public static StdArrangementMatchRule attrArrangementRule( @NotNull String nameFilter, @NotNull String namespaceFilter, @NotNull ArrangementSettingsToken orderType) { return new StdArrangementMatchRule(new StdArrangementEntryMatcher(ArrangementUtil.combine(new ArrangementAtomMatchCondition (StdArrangementTokens.Regexp.NAME, nameFilter), new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, namespaceFilter))), orderType); }
@Nullable @Override public List<CompositeArrangementSettingsToken> getSupportedMatchingTokens() { return ContainerUtilRt.newArrayList(new CompositeArrangementSettingsToken(TYPE, SUPPORTED_TYPES), new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.NAME), new CompositeArrangementSettingsToken(StdArrangementTokens .Regexp.XML_NAMESPACE), new CompositeArrangementSettingsToken(ORDER, KEEP, BY_NAME)); }
@Nullable @Override public List<CompositeArrangementSettingsToken> getSupportedMatchingTokens() { return ContainerUtilRt.newArrayList(new CompositeArrangementSettingsToken(TYPE, SUPPORTED_TYPES), new CompositeArrangementSettingsToken(MODIFIER, SUPPORTED_MODIFIERS), new CompositeArrangementSettingsToken(StdArrangementTokens .Regexp.NAME), new CompositeArrangementSettingsToken(ORDER, KEEP, BY_NAME)); }
@Test public void nameConditionOnly() { ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "get*"); doTest(condition); }
@NotNull private static StdArrangementMatchRule createSectionRule(@NotNull String comment, @NotNull ArrangementSettingsToken token) { final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.TEXT, comment); final ArrangementMatchCondition condition = ArrangementUtil.combine(new ArrangementAtomMatchCondition(token), text); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition)); }
@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); }
public ArrangementGroupingRule(@NotNull ArrangementSettingsToken groupingType) { this(groupingType, StdArrangementTokens.Order.KEEP); }
public ArrangementGroupingRule(@Nonnull ArrangementSettingsToken groupingType) { this(groupingType, StdArrangementTokens.Order.KEEP); }
@Override public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) { return SUPPORTED_TYPES.contains(token) || StdArrangementTokens.Regexp.NAME.equals(token) || StdArrangementTokens.Regexp.XML_NAMESPACE.equals (token) || KEEP.equals(token) || BY_NAME.equals(token) || SUPPORTED_TYPES.contains(token); }
private void parseProperties(PsiMethod method, JavaElementArrangementEntry entry) { if(!myGroupingRules.contains(StdArrangementTokens.Grouping.GETTERS_AND_SETTERS)) { return; } String propertyName = null; boolean getter = true; if(PropertyUtil.isSimplePropertyGetter(method)) { propertyName = PropertyUtil.getPropertyNameByGetter(method); } else if(PropertyUtil.isSimplePropertySetter(method)) { propertyName = PropertyUtil.getPropertyNameBySetter(method); getter = false; } if(propertyName == null) { return; } PsiClass containingClass = method.getContainingClass(); String className = null; if(containingClass != null) { className = containingClass.getQualifiedName(); } if(className == null) { className = NULL_CONTENT; } if(getter) { myInfo.registerGetter(propertyName, className, entry); } else { myInfo.registerSetter(propertyName, className, entry); } }