Search in sources :

Example 6 with PackageEntryTable

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

the class ImportHelper method isToUseImportOnDemand.

private static boolean isToUseImportOnDemand(@NotNull String packageName, int classCount, boolean isStaticImportNeeded, @NotNull CodeStyleSettings settings) {
    if (!settings.USE_SINGLE_CLASS_IMPORTS)
        return true;
    int limitCount = isStaticImportNeeded ? settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND : settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND;
    if (classCount >= limitCount)
        return true;
    if (packageName.isEmpty())
        return false;
    PackageEntryTable table = settings.PACKAGES_TO_USE_IMPORT_ON_DEMAND;
    return table.contains(packageName);
}
Also used : PackageEntryTable(com.intellij.psi.codeStyle.PackageEntryTable)

Example 7 with PackageEntryTable

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

the class AndroidCodeStyleSettingsModifier method modify.

public static void modify(CodeStyleSettings settings) {
    // Use Android XML formatter by default
    AndroidXmlCodeStyleSettings.getInstance(settings).USE_CUSTOM_SETTINGS = true;
    // XML:
    // Copy Android code style
    AndroidXmlPredefinedCodeStyle xmlStyle = new AndroidXmlPredefinedCodeStyle();
    xmlStyle.apply(settings);
    // Java:
    // Set Import order
    settings.IMPORT_LAYOUT_TABLE.copyFrom(getAndroidImportOrder());
    // Don't use wildcard imports
    settings.PACKAGES_TO_USE_IMPORT_ON_DEMAND.copyFrom(new PackageEntryTable());
    // Class count to use import with "*"
    settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 99;
    // Name count to use static import with "*"
    settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 99;
    // set margin to 100 columns
    settings.setDefaultRightMargin(100);
}
Also used : PackageEntryTable(com.intellij.psi.codeStyle.PackageEntryTable) AndroidXmlPredefinedCodeStyle(org.jetbrains.android.formatter.AndroidXmlPredefinedCodeStyle)

Example 8 with PackageEntryTable

use of com.intellij.psi.codeStyle.PackageEntryTable 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 9 with PackageEntryTable

use of com.intellij.psi.codeStyle.PackageEntryTable 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

PackageEntryTable (com.intellij.psi.codeStyle.PackageEntryTable)9 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)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 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 AndroidXmlPredefinedCodeStyle (org.jetbrains.android.formatter.AndroidXmlPredefinedCodeStyle)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1