Java 类com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens 实例源码

项目:intellij-ce-playground    文件:ArrangementEngine.java   
@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;
}
项目:tools-idea    文件:StdArrangementEntryMatcher.java   
@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);
    }
  }
}
项目:consulo    文件:ArrangementEngine.java   
@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;
}
项目:consulo-java    文件:JavaRearranger.java   
@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);
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
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);
  }
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@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);
}
项目:tools-idea    文件:JavaArrangementVisitor.java   
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);
  }
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@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);
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializer.java   
@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);
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializer.java   
@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);
}
项目:consulo    文件:ArrangementSectionRule.java   
@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));
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializer.java   
@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);
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@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);
}
项目:consulo-xml    文件:XmlRearranger.java   
@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);
}
项目:consulo-xml    文件:XmlRearranger.java   
@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));
}
项目:consulo-java    文件:JavaRearranger.java   
@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));
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void nameConditionOnly() {
  ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "get*");
  doTest(condition);
}
项目:intellij-ce-playground    文件:ArrangementSectionRule.java   
@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));
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializer.java   
@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);
}
项目:intellij-ce-playground    文件:ArrangementGroupingRule.java   
public ArrangementGroupingRule(@NotNull ArrangementSettingsToken groupingType) {
  this(groupingType, StdArrangementTokens.Order.KEEP);
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void nameConditionOnly() {
  ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "get*");
  doTest(condition);
}
项目:tools-idea    文件:ArrangementGroupingRule.java   
public ArrangementGroupingRule(@NotNull ArrangementSettingsToken groupingType) {
  this(groupingType, StdArrangementTokens.Order.KEEP);
}
项目:consulo    文件:ArrangementGroupingRule.java   
public ArrangementGroupingRule(@Nonnull ArrangementSettingsToken groupingType) {
  this(groupingType, StdArrangementTokens.Order.KEEP);
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void nameConditionOnly() {
  ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "get*");
  doTest(condition);
}
项目:consulo-xml    文件:XmlRearranger.java   
@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);
}
项目:consulo-java    文件:JavaArrangementVisitor.java   
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);
    }
}