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);
}
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);
}
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());
}
}
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;
}
Aggregations