Search in sources :

Example 11 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class ImportLayoutPanel method addPackageToImportLayouts.

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);
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry)

Example 12 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class ImportLayoutPanel method moveRowDown.

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);
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry) AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 13 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project intellij-community by JetBrains.

the class GroovyCodeStyleManagerImpl method addLineFeedAfter.

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());
    }
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry) PackageEntryTable(com.intellij.psi.codeStyle.PackageEntryTable) ASTNode(com.intellij.lang.ASTNode) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) PsiElement(com.intellij.psi.PsiElement)

Example 14 with PackageEntry

use of com.intellij.psi.codeStyle.PackageEntry in project android by JetBrains.

the class AndroidCodeStyleSettingsModifier method getAndroidImportOrder.

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;
}
Also used : PackageEntry(com.intellij.psi.codeStyle.PackageEntry) PackageEntryTable(com.intellij.psi.codeStyle.PackageEntryTable)

Aggregations

PackageEntry (com.intellij.psi.codeStyle.PackageEntry)14 PackageEntryTable (com.intellij.psi.codeStyle.PackageEntryTable)4 AbstractTableModel (javax.swing.table.AbstractTableModel)4 PsiElement (com.intellij.psi.PsiElement)3 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)3 ASTNode (com.intellij.lang.ASTNode)2 GrPackageDefinition (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 JBTable (com.intellij.ui.table.JBTable)1 CellEditorListener (javax.swing.event.CellEditorListener)1 ChangeEvent (javax.swing.event.ChangeEvent)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableModel (javax.swing.table.TableModel)1 Nullable (org.jetbrains.annotations.Nullable)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1