Java 类com.intellij.psi.codeStyle.PackageEntry 实例源码

项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
private void removeEntryFromImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 0) {
    return;
  }
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  myImportLayoutList.removeEntryAt(selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsDeleted(selected, selected);
  if (selected >= myImportLayoutList.getEntryCount()) {
    selected--;
  }
  if (selected >= 0) {
    myImportLayoutTable.setRowSelectionInterval(selected, selected);
  }
}
项目:intellij-ce-playground    文件:ImportHelper.java   
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final CodeStyleSettings settings) {
  int[] entryForName = ArrayUtil.newIntArray(names.size());
  PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
  for(int i = 0; i < names.size(); i++){
    Pair<String, Boolean> pair = names.get(i);
    String packageName = pair.getFirst();
    Boolean isStatic = pair.getSecond();
    entryForName[i] = findEntryIndex(packageName, isStatic, entries);
  }

  List<Pair<String, Boolean>> resultList = new ArrayList<Pair<String, Boolean>>(names.size());
  for(int i = 0; i < entries.length; i++){
    for(int j = 0; j < names.size(); j++){
      if (entryForName[j] == i){
        resultList.add(names.get(j));
        names.set(j, null);
      }
    }
  }
  for (Pair<String, Boolean> name : names) {
    if (name != null) resultList.add(name);
  }
  return resultList;
}
项目:intellij-ce-playground    文件:ImportHelper.java   
public int getEmptyLinesBetween(@NotNull PsiImportStatementBase statement1, @NotNull PsiImportStatementBase statement2){
  int index1 = findEntryIndex(statement1);
  int index2 = findEntryIndex(statement2);
  if (index1 == index2) return 0;
  if (index1 > index2) {
    int t = index1;
    index1 = index2;
    index2 = t;
  }
  PackageEntry[] entries = mySettings.IMPORT_LAYOUT_TABLE.getEntries();
  int maxSpace = 0;
  for(int i = index1 + 1; i < index2; i++){
    if (entries[i] == PackageEntry.BLANK_LINE_ENTRY){
      int space = 0;
      do{
        space++;
      } while(entries[++i] == PackageEntry.BLANK_LINE_ENTRY);
      maxSpace = Math.max(maxSpace, space);
    }
  }
  return maxSpace;
}
项目:intellij-ce-playground    文件:ImportHelper.java   
private static int findEntryIndex(@NotNull String packageName, boolean isStatic, @NotNull PackageEntry[] entries) {
  PackageEntry bestEntry = null;
  int bestEntryIndex = -1;
  int allOtherStaticIndex = -1;
  int allOtherIndex = -1;
  for(int i = 0; i < entries.length; i++){
    PackageEntry entry = entries[i];
    if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
      allOtherStaticIndex = i;
    }
    if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
      allOtherIndex = i;
    }
    if (entry.isBetterMatchForPackageThan(bestEntry, packageName, isStatic)) {
      bestEntry = entry;
      bestEntryIndex = i;
    }
  }
  if (bestEntryIndex == -1 && isStatic && allOtherStaticIndex == -1 && allOtherIndex != -1) {
    // if no layout for static imports specified, put them among all others
    bestEntryIndex = allOtherIndex;
  }
  return bestEntryIndex;
}
项目:intellij-ce-playground    文件:GroovyCodeStyleManagerImpl.java   
protected void addLineFeedAfter(@NotNull PsiElement psiFile, GrImportStatement result) {
  final GroovyCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(psiFile.getProject()).getCurrentSettings().getCustomSettings(GroovyCodeStyleSettings.class);
  final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
  final PackageEntry[] entries = layoutTable.getEntries();

  PsiElement next = result.getNextSibling();
  if (PsiImplUtil.isWhiteSpaceOrNls(next)) next = next.getNextSibling();
  if (PsiImplUtil.hasElementType(next, GroovyTokenTypes.mSEMI)) next = next.getNextSibling();
  while (PsiImplUtil.isWhiteSpaceOrNls(next)) {
    next = next.getNextSibling();
  }
  if (next instanceof GrImportStatement) {
    final int idx_after = getPackageEntryIdx(entries, (GrImportStatement)next);
    final int idx = getPackageEntryIdx(entries, result);
    final int spaceCount = getMaxSpaceCount(entries, idx, idx_after);


    ASTNode node = psiFile.getNode();
    while (PsiImplUtil.isWhiteSpaceOrNls(next.getPrevSibling())) {
      node.removeChild(next.getPrevSibling().getNode());
    }
    node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), next.getNode());
  }
}
项目:tools-idea    文件:ImportLayoutPanel.java   
private void removeEntryFromImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 0) {
    return;
  }
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  myImportLayoutList.removeEntryAt(selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsDeleted(selected, selected);
  if (selected >= myImportLayoutList.getEntryCount()) {
    selected--;
  }
  if (selected >= 0) {
    myImportLayoutTable.setRowSelectionInterval(selected, selected);
  }
}
项目:tools-idea    文件:ImportHelper.java   
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final CodeStyleSettings settings) {
  int[] entryForName = ArrayUtil.newIntArray(names.size());
  PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
  for(int i = 0; i < names.size(); i++){
    Pair<String, Boolean> pair = names.get(i);
    String packageName = pair.getFirst();
    Boolean isStatic = pair.getSecond();
    entryForName[i] = findEntryIndex(packageName, isStatic, entries);
  }

  List<Pair<String, Boolean>> resultList = new ArrayList<Pair<String, Boolean>>(names.size());
  for(int i = 0; i < entries.length; i++){
    for(int j = 0; j < names.size(); j++){
      if (entryForName[j] == i){
        resultList.add(names.get(j));
        names.set(j, null);
      }
    }
  }
  for (Pair<String, Boolean> name : names) {
    if (name != null) resultList.add(name);
  }
  return resultList;
}
项目:tools-idea    文件:ImportHelper.java   
public int getEmptyLinesBetween(@NotNull PsiImportStatementBase statement1, @NotNull PsiImportStatementBase statement2){
  int index1 = findEntryIndex(statement1);
  int index2 = findEntryIndex(statement2);
  if (index1 == index2) return 0;
  if (index1 > index2) {
    int t = index1;
    index1 = index2;
    index2 = t;
  }
  PackageEntry[] entries = mySettings.IMPORT_LAYOUT_TABLE.getEntries();
  int maxSpace = 0;
  for(int i = index1 + 1; i < index2; i++){
    if (entries[i] == PackageEntry.BLANK_LINE_ENTRY){
      int space = 0;
      do{
        space++;
      } while(entries[++i] == PackageEntry.BLANK_LINE_ENTRY);
      maxSpace = Math.max(maxSpace, space);
    }
  }
  return maxSpace;
}
项目:tools-idea    文件:ImportHelper.java   
private static int findEntryIndex(@NotNull String packageName, boolean isStatic, @NotNull PackageEntry[] entries) {
  PackageEntry bestEntry = null;
  int bestEntryIndex = -1;
  int allOtherStaticIndex = -1;
  int allOtherIndex = -1;
  for(int i = 0; i < entries.length; i++){
    PackageEntry entry = entries[i];
    if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
      allOtherStaticIndex = i;
    }
    if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
      allOtherIndex = i;
    }
    if (entry.isBetterMatchForPackageThan(bestEntry, packageName, isStatic)) {
      bestEntry = entry;
      bestEntryIndex = i;
    }
  }
  if (bestEntryIndex == -1 && isStatic && allOtherStaticIndex == -1 && allOtherIndex != -1) {
    // if no layout for static imports specified, put them among all others
    bestEntryIndex = allOtherIndex;
  }
  return bestEntryIndex;
}
项目:tools-idea    文件:GroovyFileBaseImpl.java   
protected void addLineFeedAfter(GrImportStatement result) {
  final GroovyCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(GroovyCodeStyleSettings.class);
  final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
  final PackageEntry[] entries = layoutTable.getEntries();

  PsiElement next = result.getNextSibling();
  if (isWhiteSpace(next)) next = next.getNextSibling();
  if (hasElementType(next, GroovyTokenTypes.mSEMI)) next = next.getNextSibling();
  while (isWhiteSpace(next)) {
    next = next.getNextSibling();
  }
  if (next instanceof GrImportStatement) {
    final int idx_after = getPackageEntryIdx(entries, (GrImportStatement)next);
    final int idx = getPackageEntryIdx(entries, result);
    final int spaceCount = getMaxSpaceCount(entries, idx, idx_after);


    final FileASTNode node = getNode();
    while (isWhiteSpace(next.getPrevSibling())) {
      node.removeChild(next.getPrevSibling().getNode());
    }
    node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), next.getNode());
  }
}
项目:consulo-java    文件:ImportLayoutPanel.java   
private void removeEntryFromImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 0) {
    return;
  }
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  myImportLayoutList.removeEntryAt(selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsDeleted(selected, selected);
  if (selected >= myImportLayoutList.getEntryCount()) {
    selected--;
  }
  if (selected >= 0) {
    myImportLayoutTable.setRowSelectionInterval(selected, selected);
  }
}
项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
private void addPackageToImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  myImportLayoutList.insertEntryAt(entry, selected);
  refreshTableModel(selected, myImportLayoutTable);
}
项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
private void addBlankLine() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  myImportLayoutList.insertEntryAt(PackageEntry.BLANK_LINE_ENTRY, selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsInserted(selected, selected);
  myImportLayoutTable.setRowSelectionInterval(selected, selected);
}
项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
private void moveRowUp() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry previousEntry = myImportLayoutList.getEntryAt(selected - 1);
  myImportLayoutList.setEntryAt(previousEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected - 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected - 1, selected);
  myImportLayoutTable.setRowSelectionInterval(selected - 1, selected - 1);
}
项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
private void moveRowDown() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected >= myImportLayoutList.getEntryCount() - 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry nextEntry = myImportLayoutList.getEntryAt(selected + 1);
  myImportLayoutList.setEntryAt(nextEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected + 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected, selected + 1);
  myImportLayoutTable.setRowSelectionInterval(selected + 1, selected + 1);
}
项目:intellij-ce-playground    文件:ImportLayoutPanel.java   
public static void resizeColumns(final PackageEntryTable packageTable, JBTable result, boolean areStaticImportsEnabled) {
  ColoredTableCellRenderer packageRenderer = new ColoredTableCellRenderer() {
    @Override
    protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
      PackageEntry entry = packageTable.getEntryAt(row);

      if (entry == PackageEntry.BLANK_LINE_ENTRY) {
        append("<blank line>", SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
      else {
        TextAttributes attributes = JavaHighlightingColors.KEYWORD.getDefaultAttributes();
        append("import", SimpleTextAttributes.fromTextAttributes(attributes));
        if (entry.isStatic()) {
          append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          append("static", SimpleTextAttributes.fromTextAttributes(attributes));
        }
        append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);

        if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
          append("all other imports", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
        else {
          append(entry.getPackageName() + ".*", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
      }
    }
  };
  if (areStaticImportsEnabled) {
    fixColumnWidthToHeader(result, 0);
    fixColumnWidthToHeader(result, 2);
    result.getColumnModel().getColumn(1).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(0).setCellRenderer(new BooleanTableCellRenderer());
    result.getColumnModel().getColumn(2).setCellRenderer(new BooleanTableCellRenderer());
  }
  else {
    fixColumnWidthToHeader(result, 1);
    result.getColumnModel().getColumn(0).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(1).setCellRenderer(new BooleanTableCellRenderer());
  }
}
项目:intellij-ce-playground    文件:PackagePanel.java   
private static void addPackageToPackages(JBTable table, PackageEntryTable list) {
  int selected = table.getSelectedRow() + 1;
  if (selected < 0) {
    selected = list.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  list.insertEntryAt(entry, selected);
  ImportLayoutPanel.refreshTableModel(selected, table);
}
项目:intellij-ce-playground    文件:CodeStyleImportsPanel.java   
private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
  if (list.getEntryCount() != table.getEntryCount()) {
    return true;
  }

  for (int i = 0; i < list.getEntryCount(); i++) {
    PackageEntry entry1 = list.getEntryAt(i);
    PackageEntry entry2 = table.getEntryAt(i);
    if (!entry1.equals(entry2)) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:AndroidCodeStyleSettingsModifier.java   
private static PackageEntryTable getAndroidImportOrder() {
  PackageEntryTable table = new PackageEntryTable();
  // From http://s.android.com/source/code-style.html, the order should be:
  //  1. Android imports
  //  2. Imports from 3rd parties (com, junit, net, org)
  //  3. java and javax
  table.addEntry(new PackageEntry(false, "android", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "com", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "junit", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "net", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "org", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "java", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  table.addEntry(new PackageEntry(false, "javax", true));
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  // handle any other conditions
  table.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  // location of static imports is not defined, we put it last
  table.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
  table.addEntry(PackageEntry.BLANK_LINE_ENTRY);

  return table;
}
项目:intellij-ce-playground    文件:GroovyCodeStyleManagerImpl.java   
protected static int getPackageEntryIdx(@NotNull PackageEntry[] entries, @NotNull GrImportStatement statement) {
  final GrCodeReferenceElement reference = statement.getImportReference();
  if (reference == null) return -1;
  final String packageName = StringUtil.getPackageName(reference.getCanonicalText());
  final boolean isStatic = statement.isStatic();

  int best = -1;
  int allOtherStatic = -1;
  int allOther = -1;
  PackageEntry bestEntry = null;
  for (int i = 0, length = entries.length; i < length; i++) {
    PackageEntry entry = entries[i];
    if (entry.isBetterMatchForPackageThan(bestEntry, packageName, isStatic)) {
      best = i;
      bestEntry = entry;
    }
    else if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
      allOtherStatic = i;
    }
    else if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
      allOther = i;
    }
  }
  if (best >= 0) return best;

  if (isStatic && allOtherStatic != -1) return allOtherStatic;
  return allOther;
}
项目:intellij-ce-playground    文件:GroovyCodeStyleManagerImpl.java   
protected void addLineFeedBefore(@NotNull PsiElement psiFile, @NotNull GrImportStatement result) {
  final GroovyCodeStyleSettings settings =
    CodeStyleSettingsManager.getInstance(psiFile.getProject()).getCurrentSettings().getCustomSettings(GroovyCodeStyleSettings.class);
  final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
  final PackageEntry[] entries = layoutTable.getEntries();

  PsiElement prev = result.getPrevSibling();
  while (PsiImplUtil.isWhiteSpaceOrNls(prev)) {
    prev = prev.getPrevSibling();
  }
  if (PsiImplUtil.hasElementType(prev, GroovyTokenTypes.mSEMI)) prev = prev.getPrevSibling();
  if (PsiImplUtil.isWhiteSpaceOrNls(prev)) prev = prev.getPrevSibling();

  if (prev instanceof GrImportStatement) {
    final int idx_before = getPackageEntryIdx(entries, (GrImportStatement)prev);
    final int idx = getPackageEntryIdx(entries, result);
    final int spaceCount = getMaxSpaceCount(entries, idx_before, idx);

    //skip space and semicolon after import
    if (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling()) && PsiImplUtil
      .hasElementType(prev.getNextSibling().getNextSibling(), GroovyTokenTypes.mSEMI)) prev = prev.getNextSibling().getNextSibling();
    ASTNode node = psiFile.getNode();
    while (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling())) {
      node.removeChild(prev.getNextSibling().getNode());
    }
    node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), result.getNode());
  }
}
项目:intellij-ce-playground    文件:GrCodeStyleImportsPanel.java   
private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
  if (list.getEntryCount() != table.getEntryCount()) {
    return true;
  }

  for (int i = 0; i < list.getEntryCount(); i++) {
    PackageEntry entry1 = list.getEntryAt(i);
    PackageEntry entry2 = table.getEntryAt(i);
    if (!entry1.equals(entry2)) {
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:ImportLayoutPanel.java   
private void addPackageToImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  myImportLayoutList.insertEntryAt(entry, selected);
  refreshTableModel(selected, myImportLayoutTable);
}
项目:tools-idea    文件:ImportLayoutPanel.java   
private void addBlankLine() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  myImportLayoutList.insertEntryAt(PackageEntry.BLANK_LINE_ENTRY, selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsInserted(selected, selected);
  myImportLayoutTable.setRowSelectionInterval(selected, selected);
}
项目:tools-idea    文件:ImportLayoutPanel.java   
private void moveRowUp() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry previousEntry = myImportLayoutList.getEntryAt(selected - 1);
  myImportLayoutList.setEntryAt(previousEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected - 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected - 1, selected);
  myImportLayoutTable.setRowSelectionInterval(selected - 1, selected - 1);
}
项目:tools-idea    文件:ImportLayoutPanel.java   
private void moveRowDown() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected >= myImportLayoutList.getEntryCount() - 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry nextEntry = myImportLayoutList.getEntryAt(selected + 1);
  myImportLayoutList.setEntryAt(nextEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected + 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected, selected + 1);
  myImportLayoutTable.setRowSelectionInterval(selected + 1, selected + 1);
}
项目:tools-idea    文件:ImportLayoutPanel.java   
public static void resizeColumns(final PackageEntryTable packageTable, JBTable result, boolean areStaticImportsEnabled) {
  ColoredTableCellRenderer packageRenderer = new ColoredTableCellRenderer() {
    @Override
    protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
      PackageEntry entry = packageTable.getEntryAt(row);

      if (entry == PackageEntry.BLANK_LINE_ENTRY) {
        append("                                               <blank line>", SimpleTextAttributes.LINK_ATTRIBUTES);
      }
      else {
        TextAttributes attributes = JavaHighlightingColors.KEYWORD.getDefaultAttributes();
        append("import", SimpleTextAttributes.fromTextAttributes(attributes));
        if (entry.isStatic()) {
          append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          append("static", SimpleTextAttributes.fromTextAttributes(attributes));
        }
        append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);

        if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
          append("all other imports", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
        else {
          append(entry.getPackageName() + ".*", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
      }
    }
  };
  if (areStaticImportsEnabled) {
    fixColumnWidthToHeader(result, 0);
    fixColumnWidthToHeader(result, 2);
    result.getColumnModel().getColumn(1).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(0).setCellRenderer(new BooleanTableCellRenderer());
    result.getColumnModel().getColumn(2).setCellRenderer(new BooleanTableCellRenderer());
  }
  else {
    fixColumnWidthToHeader(result, 1);
    result.getColumnModel().getColumn(0).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(1).setCellRenderer(new BooleanTableCellRenderer());
  }
}
项目:tools-idea    文件:PackagePanel.java   
private static void addPackageToPackages(JBTable table, PackageEntryTable list) {
  int selected = table.getSelectedRow() + 1;
  if (selected < 0) {
    selected = list.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  list.insertEntryAt(entry, selected);
  ImportLayoutPanel.refreshTableModel(selected, table);
}
项目:tools-idea    文件:CodeStyleImportsPanel.java   
private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
  if (list.getEntryCount() != table.getEntryCount()) {
    return true;
  }

  for (int i = 0; i < list.getEntryCount(); i++) {
    PackageEntry entry1 = list.getEntryAt(i);
    PackageEntry entry2 = table.getEntryAt(i);
    if (!entry1.equals(entry2)) {
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:GroovyFileBaseImpl.java   
protected void addLineFeedBefore(GrImportStatement result) {
  final GroovyCodeStyleSettings settings =
    CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(GroovyCodeStyleSettings.class);
  final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
  final PackageEntry[] entries = layoutTable.getEntries();

  PsiElement prev = result.getPrevSibling();
  while (isWhiteSpace(prev)) {
    prev = prev.getPrevSibling();
  }
  if (hasElementType(prev, GroovyTokenTypes.mSEMI)) prev = prev.getPrevSibling();
  if (isWhiteSpace(prev)) prev = prev.getPrevSibling();

  if (prev instanceof GrImportStatement) {
    final int idx_before = getPackageEntryIdx(entries, (GrImportStatement)prev);
    final int idx = getPackageEntryIdx(entries, result);
    final int spaceCount = getMaxSpaceCount(entries, idx_before, idx);

    //skip space and semicolon after import
    if (isWhiteSpace(prev.getNextSibling()) && hasElementType(prev.getNextSibling().getNextSibling(), GroovyTokenTypes.mSEMI)) prev = prev.getNextSibling().getNextSibling();
    final FileASTNode node = getNode();
    while (isWhiteSpace(prev.getNextSibling())) {
      node.removeChild(prev.getNextSibling().getNode());
    }
    node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), result.getNode());
  }
}
项目:tools-idea    文件:GroovyFileBaseImpl.java   
protected static int getPackageEntryIdx(PackageEntry[] entries, GrImportStatement statement) {
  final GrCodeReferenceElement reference = statement.getImportReference();
  if (reference == null) return -1;
  final String packageName = StringUtil.getPackageName(reference.getCanonicalText());
  final boolean isStatic = statement.isStatic();

  int best = -1;
  int allOtherStatic = -1;
  int allOther = -1;
  PackageEntry bestEntry = null;
  for (int i = 0, length = entries.length; i < length; i++) {
    PackageEntry entry = entries[i];
    if (entry.isBetterMatchForPackageThan(bestEntry, packageName, isStatic)) {
      best = i;
      bestEntry = entry;
    }
    else if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
      allOtherStatic = i;
    }
    else if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY) {
      allOther = i;
    }
  }
  if (best >= 0) return best;

  if (isStatic && allOtherStatic != -1) return allOtherStatic;
  return allOther;
}
项目:tools-idea    文件:GrCodeStyleImportsPanel.java   
private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
  if (list.getEntryCount() != table.getEntryCount()) {
    return true;
  }

  for (int i = 0; i < list.getEntryCount(); i++) {
    PackageEntry entry1 = list.getEntryAt(i);
    PackageEntry entry2 = table.getEntryAt(i);
    if (!entry1.equals(entry2)) {
      return true;
    }
  }

  return false;
}
项目:consulo-java    文件:ImportLayoutPanel.java   
private void addPackageToImportLayouts() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  myImportLayoutList.insertEntryAt(entry, selected);
  refreshTableModel(selected, myImportLayoutTable);
}
项目:consulo-java    文件:ImportLayoutPanel.java   
private void addBlankLine() {
  int selected = myImportLayoutTable.getSelectedRow() + 1;
  if (selected < 0) {
    selected = myImportLayoutList.getEntryCount();
  }
  myImportLayoutList.insertEntryAt(PackageEntry.BLANK_LINE_ENTRY, selected);
  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsInserted(selected, selected);
  myImportLayoutTable.setRowSelectionInterval(selected, selected);
}
项目:consulo-java    文件:ImportLayoutPanel.java   
private void moveRowUp() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected < 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry previousEntry = myImportLayoutList.getEntryAt(selected - 1);
  myImportLayoutList.setEntryAt(previousEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected - 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected - 1, selected);
  myImportLayoutTable.setRowSelectionInterval(selected - 1, selected - 1);
}
项目:consulo-java    文件:ImportLayoutPanel.java   
private void moveRowDown() {
  int selected = myImportLayoutTable.getSelectedRow();
  if (selected >= myImportLayoutList.getEntryCount() - 1) {
    return;
  }
  TableUtil.stopEditing(myImportLayoutTable);
  PackageEntry entry = myImportLayoutList.getEntryAt(selected);
  PackageEntry nextEntry = myImportLayoutList.getEntryAt(selected + 1);
  myImportLayoutList.setEntryAt(nextEntry, selected);
  myImportLayoutList.setEntryAt(entry, selected + 1);

  AbstractTableModel model = (AbstractTableModel)myImportLayoutTable.getModel();
  model.fireTableRowsUpdated(selected, selected + 1);
  myImportLayoutTable.setRowSelectionInterval(selected + 1, selected + 1);
}
项目:consulo-java    文件:ImportLayoutPanel.java   
public static void resizeColumns(final PackageEntryTable packageTable, JBTable result, boolean areStaticImportsEnabled) {
  ColoredTableCellRenderer packageRenderer = new ColoredTableCellRenderer() {
    @Override
    protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
      PackageEntry entry = packageTable.getEntryAt(row);

      if (entry == PackageEntry.BLANK_LINE_ENTRY) {
        append("                                               <blank line>", SimpleTextAttributes.LINK_ATTRIBUTES);
      }
      else {
        TextAttributes attributes = JavaHighlightingColors.KEYWORD.getDefaultAttributes();
        append("import", SimpleTextAttributes.fromTextAttributes(attributes));
        if (entry.isStatic()) {
          append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          append("static", SimpleTextAttributes.fromTextAttributes(attributes));
        }
        append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);

        if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
          append("all other imports", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
        else {
          append(entry.getPackageName() + ".*", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
      }
    }
  };
  if (areStaticImportsEnabled) {
    fixColumnWidthToHeader(result, 0);
    fixColumnWidthToHeader(result, 2);
    result.getColumnModel().getColumn(1).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(0).setCellRenderer(new BooleanTableCellRenderer());
    result.getColumnModel().getColumn(2).setCellRenderer(new BooleanTableCellRenderer());
  }
  else {
    fixColumnWidthToHeader(result, 1);
    result.getColumnModel().getColumn(0).setCellRenderer(packageRenderer);
    result.getColumnModel().getColumn(1).setCellRenderer(new BooleanTableCellRenderer());
  }
}
项目:consulo-java    文件:PackagePanel.java   
private static void addPackageToPackages(JBTable table, PackageEntryTable list) {
  int selected = table.getSelectedRow() + 1;
  if (selected < 0) {
    selected = list.getEntryCount();
  }
  PackageEntry entry = new PackageEntry(false, "", true);
  list.insertEntryAt(entry, selected);
  ImportLayoutPanel.refreshTableModel(selected, table);
}
项目:consulo-java    文件:CodeStyleImportsPanel.java   
private static boolean isModified(PackageEntryTable list, PackageEntryTable table) {
  if (list.getEntryCount() != table.getEntryCount()) {
    return true;
  }

  for (int i = 0; i < list.getEntryCount(); i++) {
    PackageEntry entry1 = list.getEntryAt(i);
    PackageEntry entry2 = table.getEntryAt(i);
    if (!entry1.equals(entry2)) {
      return true;
    }
  }

  return false;
}
项目:consulo-java    文件:ImportHelper.java   
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final CodeStyleSettings settings)
{
    int[] entryForName = ArrayUtil.newIntArray(names.size());
    PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
    for(int i = 0; i < names.size(); i++)
    {
        Pair<String, Boolean> pair = names.get(i);
        String packageName = pair.getFirst();
        Boolean isStatic = pair.getSecond();
        entryForName[i] = findEntryIndex(packageName, isStatic, entries);
    }

    List<Pair<String, Boolean>> resultList = new ArrayList<Pair<String, Boolean>>(names.size());
    for(int i = 0; i < entries.length; i++)
    {
        for(int j = 0; j < names.size(); j++)
        {
            if(entryForName[j] == i)
            {
                resultList.add(names.get(j));
                names.set(j, null);
            }
        }
    }
    for(Pair<String, Boolean> name : names)
    {
        if(name != null)
        {
            resultList.add(name);
        }
    }
    return resultList;
}