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

项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@Nullable
private JavaElementArrangementEntry createNewEntry(@NotNull PsiElement element,
                                                   @NotNull TextRange range,
                                                   @NotNull ArrangementSettingsToken type,
                                                   @Nullable String name,
                                                   boolean canArrange)
{
  if (!isWithinBounds(range)) {
    return null;
  }
  DefaultArrangementEntry current = getCurrent();
  JavaElementArrangementEntry entry;
  if (canArrange) {
    TextRange expandedRange = myDocument == null ? null : ArrangementUtil.expandToLineIfPossible(range, myDocument);
    TextRange rangeToUse = expandedRange == null ? range : expandedRange;
    entry = new JavaElementArrangementEntry(current, rangeToUse, type, name, true);
  }
  else {
    entry = new JavaElementArrangementEntry(current, range, type, name, false);
  }
  registerEntry(element, entry);
  return entry;
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@SuppressWarnings("MagicConstant")
private static void parseModifiers(@Nullable PsiModifierList modifierList, @NotNull JavaElementArrangementEntry entry) {
  if (modifierList == null) {
    return;
  }
  for (String modifier : PsiModifier.MODIFIERS) {
    if (modifierList.hasModifierProperty(modifier)) {
      ArrangementSettingsToken arrangementModifier = MODIFIERS.get(modifier);
      if (arrangementModifier != null) {
        entry.addModifier(arrangementModifier);
      }
    }
  }
  if (modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
    entry.addModifier(PACKAGE_PRIVATE);
  }
}
项目:intellij-ce-playground    文件:StdArrangementMatchRule.java   
@Override
public int compareTo(@NotNull StdArrangementMatchRule o) {
  final Map<ArrangementSettingsToken, Object> tokenValues = ArrangementUtil.extractTokens(getMatcher().getCondition());
  final Map<ArrangementSettingsToken, Object> tokenValues1 = ArrangementUtil.extractTokens(o.getMatcher().getCondition());
  final Set<ArrangementSettingsToken> tokens = tokenValues.keySet();
  final Set<ArrangementSettingsToken> tokens1 = tokenValues1.keySet();
  if (tokens1.containsAll(tokens)) {
    return tokens.containsAll(tokens1) ? 0 : 1;
  }
  else {
    if (tokens.containsAll(tokens1)) {
      return -1;
    }

    final String entryType = getEntryType(tokenValues);
    final String entryType1 = getEntryType(tokenValues1);
    final int compare = StringUtil.compare(entryType1, entryType, false);
    if (compare != 0 || tokens.size() == tokens1.size()) {
      return compare;
    }
    return tokens.size() < tokens1.size() ? 1 : -1;
  }
}
项目:intellij-ce-playground    文件:ArrangementGroupingRulesControl.java   
@NotNull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:XmlArrangementVisitor.java   
@Nullable
private XmlElementArrangementEntry createNewEntry(@NotNull TextRange range,
                                                  @NotNull ArrangementSettingsToken type,
                                                  @Nullable String name,
                                                  @Nullable String namespace,
                                                  boolean canBeMatched) {
  if (range.getStartOffset() == 0 && range.getEndOffset() == 0 || !isWithinBounds(range)) {
    return null;
  }
  final DefaultArrangementEntry current = getCurrent();
  final XmlElementArrangementEntry entry = new XmlElementArrangementEntry(
    current, range, type, name, namespace, canBeMatched);

  if (current == null) {
    myInfo.addEntry(entry);
  }
  else {
    current.addChild(entry);
  }
  return entry;
}
项目:tools-idea    文件:JavaArrangementVisitor.java   
@Override
public void visitMethod(PsiMethod method) {
  ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD;
  JavaElementArrangementEntry entry = createNewEntry(method, method.getTextRange(), type, method.getName(), true);
  if (entry == null) {
    return;
  }

  processEntry(entry, method, method.getBody());
  parseProperties(method, entry);
  myInfo.onMethodEntryCreated(method, entry);
  MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst();
  if (overridden != null) {
    myInfo.onOverriddenMethod(overridden.getMethod(), method);
  }
  boolean reset = myMethodBodyProcessor.setBaseMethod(method);
  try {
    method.accept(myMethodBodyProcessor);
  }
  finally {
    if (reset) {
      myMethodBodyProcessor.setBaseMethod(null);
    }
  }
}
项目:tools-idea    文件:JavaArrangementVisitor.java   
@SuppressWarnings("MagicConstant")
private static void parseModifiers(@Nullable PsiModifierList modifierList, @NotNull JavaElementArrangementEntry entry) {
  if (modifierList == null) {
    return;
  }
  for (String modifier : PsiModifier.MODIFIERS) {
    if (modifierList.hasModifierProperty(modifier)) {
      ArrangementSettingsToken arrangementModifier = MODIFIERS.get(modifier);
      if (arrangementModifier != null) {
        entry.addModifier(arrangementModifier);
      }
    }
  }
  if (modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
    entry.addModifier(PACKAGE_PRIVATE);
  }
}
项目:tools-idea    文件:ArrangementStandardSettingsManager.java   
@Override
public int compare(ArrangementSettingsToken t1, ArrangementSettingsToken t2) {
  if (myWeights.containsKey(t1)) {
    if (myWeights.containsKey(t2)) {
      return myWeights.get(t1) - myWeights.get(t2);
    }
    else {
      return -1;
    }
  }
  else if (myWeights.containsKey(t2)) {
    return 1;
  }
  else {
    return t1.compareTo(t2);
  }
}
项目: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);
    }
  }
}
项目:tools-idea    文件:ArrangementGroupingRulesControl.java   
@NotNull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:tools-idea    文件:XmlArrangementVisitor.java   
@Nullable
private XmlElementArrangementEntry createNewEntry(@NotNull TextRange range,
                                                  @NotNull ArrangementSettingsToken type,
                                                  @Nullable String name,
                                                  @Nullable String namespace,
                                                  boolean canBeMatched) {
  if (!isWithinBounds(range)) {
    return null;
  }
  final DefaultArrangementEntry current = getCurrent();
  final XmlElementArrangementEntry entry = new XmlElementArrangementEntry(
    current, range, type, name, namespace, canBeMatched);

  if (current == null) {
    myInfo.addEntry(entry);
  }
  else {
    current.addChild(entry);
  }
  return entry;
}
项目:consulo    文件:StdArrangementMatchRule.java   
@Override
public int compareTo(@Nonnull StdArrangementMatchRule o) {
  final Set<ArrangementSettingsToken> tokens = ArrangementUtil.extractTokens(getMatcher().getCondition()).keySet();
  final Set<ArrangementSettingsToken> tokens1 = ArrangementUtil.extractTokens(o.getMatcher().getCondition()).keySet();
  if (tokens1.containsAll(tokens)) {
    return tokens.containsAll(tokens1) ? 0 : 1;
  }
  else {
    if (tokens.containsAll(tokens1)) {
      return -1;
    }

    final String entryType = getEntryType(tokens);
    final String entryType1 = getEntryType(tokens1);
    final int compare = StringUtil.compare(entryType, entryType1, false);
    if (compare != 0 || tokens.size() == tokens1.size()) {
      return compare;
    }
    return tokens.size() < tokens1.size() ? 1 : -1;
  }
}
项目:consulo    文件:ArrangementGroupingRulesControl.java   
@Nonnull
public List<ArrangementGroupingRule> getRules() {
  List<ArrangementGroupingRule> result = new ArrayList<ArrangementGroupingRule>();
  DefaultTableModel model = getModel();
  for (int i = 0, max = model.getRowCount(); i < max; i++) {
    ArrangementGroupingComponent component = (ArrangementGroupingComponent)model.getValueAt(i, 0);
    if (!component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken orderType = component.getOrderType();
    if (orderType == null) {
      result.add(new ArrangementGroupingRule(component.getGroupingType()));
    }
    else {
      result.add(new ArrangementGroupingRule(component.getGroupingType(), orderType));
    }
  }
  return result;
}
项目:consulo-xml    文件:XmlArrangementVisitor.java   
@Nullable
private XmlElementArrangementEntry createNewEntry(@NotNull TextRange range,
                                                  @NotNull ArrangementSettingsToken type,
                                                  @Nullable String name,
                                                  boolean canBeMatched) {
  if (!isWithinBounds(range)) {
    return null;
  }
  final DefaultArrangementEntry current = getCurrent();
  final XmlElementArrangementEntry entry = new XmlElementArrangementEntry(
    current, range, type, name, canBeMatched);

  if (current == null) {
    myInfo.addEntry(entry);
  }
  else {
    current.addChild(entry);
  }
  return entry;
}
项目:consulo-java    文件:JavaRearranger.java   
private static void setupUtilityMethods(@NotNull JavaArrangementParseInfo info, @NotNull ArrangementSettingsToken orderType)
{
    if(DEPTH_FIRST.equals(orderType))
    {
        for(ArrangementEntryDependencyInfo rootInfo : info.getMethodDependencyRoots())
        {
            setupDepthFirstDependency(rootInfo);
        }
    }
    else if(BREADTH_FIRST.equals(orderType))
    {
        for(ArrangementEntryDependencyInfo rootInfo : info.getMethodDependencyRoots())
        {
            setupBreadthFirstDependency(rootInfo);
        }
    }
    else
    {
        assert false : orderType;
    }
}
项目: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);
}
项目:consulo-java    文件:JavaRearranger.java   
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],
                conditions[0]))));
        return;
    }

    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for(ArrangementSettingsToken condition : conditions)
    {
        composite.addOperand(new ArrangementAtomMatchCondition(condition, condition));
    }
    matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
项目:consulo-java    文件:JavaRearranger.java   
@Nullable
@Override
public TextAttributes getTextAttributes(@NotNull EditorColorsScheme scheme, @NotNull ArrangementSettingsToken token, boolean selected)
{
    if(selected)
    {
        TextAttributes attributes = new TextAttributes();
        attributes.setForegroundColor(scheme.getColor(EditorColors.SELECTION_FOREGROUND_COLOR));
        attributes.setBackgroundColor(scheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR));
        return attributes;
    }
    else if(SUPPORTED_TYPES.contains(token))
    {
        return getAttributes(scheme, JavaHighlightingColors.KEYWORD);
    }
    else if(SUPPORTED_MODIFIERS.contains(token))
    {
        getAttributes(scheme, JavaHighlightingColors.KEYWORD);
    }
    return null;
}
项目:consulo-java    文件:JavaArrangementVisitor.java   
@Override
public void visitClass(PsiClass aClass)
{
    boolean isSectionCommentsDetected = registerSectionComments(aClass);
    TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(aClass) : aClass.getTextRange();

    ArrangementSettingsToken type = CLASS;
    if(aClass.isEnum())
    {
        type = ENUM;
    }
    else if(aClass.isInterface())
    {
        type = INTERFACE;
    }
    JavaElementArrangementEntry entry = createNewEntry(aClass, range, type, aClass.getName(), true);
    processEntry(entry, aClass, aClass);
}
项目:consulo-java    文件:JavaArrangementVisitor.java   
@Nullable
private JavaElementArrangementEntry createNewEntry(
        @NotNull PsiElement element, @NotNull TextRange range, @NotNull ArrangementSettingsToken type, @Nullable String name, boolean canArrange)
{
    if(!isWithinBounds(range))
    {
        return null;
    }
    DefaultArrangementEntry current = getCurrent();
    JavaElementArrangementEntry entry;
    if(canArrange)
    {
        TextRange expandedRange = myDocument == null ? null : ArrangementUtil.expandToLineIfPossible(range, myDocument);
        TextRange rangeToUse = expandedRange == null ? range : expandedRange;
        entry = new JavaElementArrangementEntry(current, rangeToUse, type, name, true);
    }
    else
    {
        entry = new JavaElementArrangementEntry(current, range, type, name, false);
    }
    registerEntry(element, entry);
    return entry;
}
项目:consulo-java    文件:JavaArrangementVisitor.java   
@SuppressWarnings("MagicConstant")
private static void parseModifiers(@Nullable PsiModifierList modifierList, @NotNull JavaElementArrangementEntry entry)
{
    if(modifierList == null)
    {
        return;
    }
    for(String modifier : PsiModifier.MODIFIERS)
    {
        if(modifierList.hasModifierProperty(modifier))
        {
            ArrangementSettingsToken arrangementModifier = MODIFIERS.get(modifier);
            if(arrangementModifier != null)
            {
                entry.addModifier(arrangementModifier);
            }
        }
    }
    if(modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL))
    {
        entry.addModifier(PACKAGE_PRIVATE);
    }
}
项目:intellij-ce-playground    文件:JavaSectionArrangementEntry.java   
public JavaSectionArrangementEntry(@Nullable ArrangementEntry parent,
                                   @NotNull ArrangementSettingsToken type,
                                   @NotNull TextRange range,
                                   @NotNull String text,
                                   boolean canBeMatched)
{
  super(parent, range.getStartOffset(), range.getEndOffset(), type, "SECTION", canBeMatched);
  myText = text;
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@NotNull
private static Set<ArrangementSettingsToken> getGroupingRules(@NotNull ArrangementSettings settings) {
  Set<ArrangementSettingsToken> groupingRules = ContainerUtilRt.newHashSet();
  for (ArrangementGroupingRule rule : settings.getGroupings()) {
    groupingRules.add(rule.getGroupingType());
  }
  return groupingRules;
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@Override
public void visitClass(PsiClass aClass) {
  boolean isSectionCommentsDetected = registerSectionComments(aClass);
  TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(aClass) : aClass.getTextRange();

  ArrangementSettingsToken type = CLASS;
  if (aClass.isEnum()) {
    type = ENUM;
  }
  else if (aClass.isInterface()) {
    type = INTERFACE;
  }
  JavaElementArrangementEntry entry = createNewEntry(aClass, range, type, aClass.getName(), true);
  processEntry(entry, aClass, aClass);
}
项目:intellij-ce-playground    文件:JavaArrangementVisitor.java   
@Override
public void visitMethod(PsiMethod method) {
  boolean isSectionCommentsDetected = registerSectionComments(method);
  final TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(method)
                                                    : method.getTextRange();

  ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD;
  JavaElementArrangementEntry entry = createNewEntry(method, range, type, method.getName(), true);
  if (entry == null) {
    return;
  }

  processEntry(entry, method, method.getBody());
  parseProperties(method, entry);
  myInfo.onMethodEntryCreated(method, entry);
  MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst();
  if (overridden != null) {
    entry.addModifier(OVERRIDDEN);
    myInfo.onOverriddenMethod(overridden.getMethod(), method);
  }
  boolean reset = myMethodBodyProcessor.setBaseMethod(method);
  try {
    method.accept(myMethodBodyProcessor);
  }
  finally {
    if (reset) {
      myMethodBodyProcessor.setBaseMethod(null);
    }
  }
}
项目:intellij-ce-playground    文件:JavaElementArrangementEntry.java   
public JavaElementArrangementEntry(@Nullable ArrangementEntry parent,
                                   @NotNull TextRange range,
                                   @NotNull ArrangementSettingsToken type,
                                   @Nullable String name,
                                   boolean canBeMatched)
{
  this(parent, range.getStartOffset(), range.getEndOffset(), type, name, canBeMatched);
}
项目:intellij-ce-playground    文件:JavaElementArrangementEntry.java   
public JavaElementArrangementEntry(@Nullable ArrangementEntry parent,
                                   int startOffset,
                                   int endOffset,
                                   @NotNull ArrangementSettingsToken type,
                                   @Nullable String name,
                                   boolean canBeArranged)
{
  super(parent, startOffset, endOffset, canBeArranged);
  myType = type;
  myTypes.add(type);
  myName = name;
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
private static StdArrangementMatchRule rule(boolean byName, @NotNull ArrangementSettingsToken... tokens) {
  final List<ArrangementAtomMatchCondition> conditions = new ArrayList<ArrangementAtomMatchCondition>();
  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);
}
项目:intellij-ce-playground    文件:ByModifierArrangementEntryMatcher.java   
@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;
}
项目:intellij-ce-playground    文件:StdArrangementMatchRule.java   
@Nullable
private static String getEntryType(@NotNull Map<ArrangementSettingsToken, Object> tokens) {
  for (Map.Entry<ArrangementSettingsToken, Object> token : tokens.entrySet()) {
    if (StdArrangementTokenType.ENTRY_TYPE.is(token.getKey())) {
      final Object value = token.getValue();
      if (!(value instanceof Boolean) || (Boolean)value) {
        return token.getKey().getId();
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializer.java   
@Override
public void visit(@NotNull ArrangementAtomMatchCondition condition) {
  ArrangementSettingsToken type = condition.getType();
  final Element element = new Element(type.getId());
  if (StdArrangementTokenType.REG_EXP.is(type)) {
    element.setText(StringUtil.escapeStringCharacters(condition.getValue().toString()));
  }
  else if (condition.getValue() instanceof Boolean) {
    element.setText(condition.getValue().toString());
  }
  register(element);
}
项目:intellij-ce-playground    文件:ByTypeArrangementEntryMatcher.java   
@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;
}
项目:intellij-ce-playground    文件:ArrangementSectionDetector.java   
public ArrangementSectionEntryTemplate(@NotNull PsiElement element,
                                       @NotNull ArrangementSettingsToken token,
                                       @NotNull TextRange range,
                                       @NotNull String text) {
  myElement = element;
  myToken = token;
  myTextRange = range;
  myText = text;
}
项目:intellij-ce-playground    文件:ArrangementColorsProviderImpl.java   
@NotNull
@Override
public TextAttributes getTextAttributes(@NotNull ArrangementSettingsToken token, boolean selected) {
  final TextAttributes cached;
  if (selected) {
    cached = mySelectedAttributesCache.get(token);
  }
  else {
    cached = myNormalAttributesCache.get(token);
  }
  if (cached != null) {
    return cached;
  }

  TextAttributes result = null;
  if (myColorsAware != null) {
    result = myColorsAware.getTextAttributes(EditorColorsManager.getInstance().getGlobalScheme(), token, selected);
  }
  if (result == null) {
    result = selected ? myDefaultSelectedAttributes : myDefaultNormalAttributes;
  }
  if (selected) {
    mySelectedAttributesCache.put(token, result);
  }
  else {
    myNormalAttributesCache.put(token, result);
  }

  return result;
}
项目:intellij-ce-playground    文件:ArrangementCheckBoxUiComponent.java   
@Override
public void chooseToken(@NotNull ArrangementSettingsToken data) throws UnsupportedOperationException {
  if (!getToken().equals(data)) {
    throw new UnsupportedOperationException(String.format(
      "Can't choose '%s' data at the check box token with data '%s'", data, getToken()
    ));
  }
}
项目:intellij-ce-playground    文件:ArrangementComboBoxUiComponent.java   
@SuppressWarnings("unchecked")
public ArrangementComboBoxUiComponent(@NotNull List<ArrangementSettingsToken> tokens) {
  super(tokens);
  ArrangementSettingsToken[] tokensArray = tokens.toArray(new ArrangementSettingsToken[tokens.size()]);
  Arrays.sort(tokensArray, new Comparator<ArrangementSettingsToken>() {
    @Override
    public int compare(ArrangementSettingsToken t1, ArrangementSettingsToken t2) {
      return t1.getRepresentationValue().compareTo(t2.getRepresentationValue());
    }
  });
  myComboBox = new JComboBox(tokensArray);
  myComboBox.setRenderer(new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      setText(((ArrangementSettingsToken)value).getRepresentationValue());
    }
  });
  myComboBox.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        fireStateChanged();
      }
    }
  });
  int minWidth = 0;
  ListCellRenderer renderer = myComboBox.getRenderer();
  JBList dummyList = new JBList();
  for (int i = 0, max = myComboBox.getItemCount(); i < max; i++) {
    Component rendererComponent = renderer.getListCellRendererComponent(dummyList, myComboBox.getItemAt(i), i, false, true);
    minWidth = Math.max(minWidth, rendererComponent.getPreferredSize().width);
  }
  myComboBox.setPreferredSize(new Dimension(minWidth * 5 / 3, myComboBox.getPreferredSize().height));
}
项目:intellij-ce-playground    文件:DefaultArrangementUiComponentFactory.java   
@Nullable
@Override
public ArrangementUiComponent build(@NotNull StdArrangementTokenUiRole role,
                                    @NotNull List<ArrangementSettingsToken> tokens,
                                    @NotNull ArrangementColorsProvider colorsProvider,
                                    @NotNull ArrangementStandardSettingsManager settingsManager)
{
  switch (role) {
    case CHECKBOX:
      if (tokens.size() != 1) {
        throw new IllegalArgumentException("Can't build a checkbox token for elements " + tokens);
      }
      else {
        return new ArrangementCheckBoxUiComponent(tokens.get(0));
      }
    case COMBO_BOX:
      if (tokens.isEmpty()) {
        throw new IllegalArgumentException("Can't build a combo box token with empty content");
      }
      return new ArrangementComboBoxUiComponent(tokens);
    case LABEL:
      if (tokens.size() != 1) {
        throw new IllegalArgumentException("Can't build a label token for elements " + tokens);
      }
      return new ArrangementLabelUiComponent(tokens.get(0));
    case TEXT_FIELD:
      if (tokens.size() != 1) {
        throw new IllegalArgumentException("Can't build a text field token for elements " + tokens);
      }
      return new ArrangementTextFieldUiComponent(tokens.get(0));
    case BULB:
      if (tokens.size() != 1) {
        throw new IllegalArgumentException("Can't build a bulb token for elements " + tokens);
      }
      return new ArrangementAtomMatchConditionComponent(
        settingsManager, colorsProvider, new ArrangementAtomMatchCondition(tokens.get(0)), null
      );
  }
  return null;
}
项目:intellij-ce-playground    文件:ArrangementEngine.java   
public static boolean isSectionEntry(@NotNull ArrangementEntry entry, @NotNull String sectionText) {
  if (entry instanceof TypeAwareArrangementEntry && entry instanceof TextAwareArrangementEntry) {
    final Set<ArrangementSettingsToken> types = ((TypeAwareArrangementEntry)entry).getTypes();
    if (types.size() == 1) {
      final ArrangementSettingsToken type = types.iterator().next();
      if (type.equals(START_SECTION) || type.equals(END_SECTION)) {
        return StringUtil.equals(((TextAwareArrangementEntry)entry).getText(), sectionText);
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:ArrangementEngine.java   
private boolean isTypeOf(@Nullable E element, @NotNull ArrangementSettingsToken token) {
  if (element instanceof TypeAwareArrangementEntry) {
    Set<ArrangementSettingsToken> types = ((TypeAwareArrangementEntry)element).getTypes();
    return types.size() == 1 && token.equals(types.iterator().next());
  }
  return false;
}
项目:intellij-ce-playground    文件:XmlElementArrangementEntry.java   
public XmlElementArrangementEntry(@Nullable ArrangementEntry parent,
                                  @NotNull TextRange range,
                                  @NotNull ArrangementSettingsToken type,
                                  @Nullable String name,
                                  @Nullable String namespace,
                                  boolean canBeMatched)
{
  super(parent, range.getStartOffset(), range.getEndOffset(), canBeMatched);
  myName = name;
  myNamespace = namespace;
  myType = type;
}