Ejemplo n.º 1
0
 private int findEntryIndex(@NotNull String packageName) {
   Entry[] entries = mySettings.IMPORT_LAYOUT_TABLE.getEntries();
   PackageEntry bestEntry = null;
   int bestEntryIndex = -1;
   for (int i = 0; i < entries.length; i++) {
     Entry entry = entries[i];
     if (entry instanceof PackageEntry) {
       PackageEntry packageEntry = (PackageEntry) entry;
       if (packageEntry.matchesPackageName(packageName)) {
         if (bestEntry == null) {
           bestEntry = packageEntry;
           bestEntryIndex = i;
         } else {
           String package1 = bestEntry.getPackageName();
           String package2 = packageEntry.getPackageName();
           if (!bestEntry.isWithSubpackages()) continue;
           if (!packageEntry.isWithSubpackages() || package2.length() > package1.length()) {
             bestEntry = packageEntry;
             bestEntryIndex = i;
           }
         }
       }
     }
   }
   return bestEntryIndex;
 }
Ejemplo n.º 2
0
 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;
   }
   Entry[] entries = mySettings.IMPORT_LAYOUT_TABLE.getEntries();
   int maxSpace = 0;
   for (int i = index1 + 1; i < index2; i++) {
     if (entries[i] instanceof EmptyLineEntry) {
       int space = 0;
       do {
         space++;
       } while (entries[++i] instanceof EmptyLineEntry);
       maxSpace = Math.max(maxSpace, space);
     }
   }
   return maxSpace;
 }