コード例 #1
0
 /**
  * Checks if current group contains any import.
  *
  * @param currentGroup current group.
  * @return true, if current group contains at least one import.
  */
 private boolean hasAnyImportInCurrentGroup(String currentGroup) {
   for (ImportDetails currentImport : importToGroupList) {
     if (currentGroup.equals(currentImport.getImportGroup())) {
       return true;
     }
   }
   return false;
 }
コード例 #2
0
  @Override
  public void finishTree(DetailAST rootAST) {

    if (importToGroupList.isEmpty()) {
      return;
    }

    final ImportDetails firstImport = importToGroupList.get(0);
    String currentGroup =
        getImportGroup(firstImport.isStaticImport(), firstImport.getImportFullPath());
    int groupNumber = customImportOrderRules.indexOf(currentGroup);
    String previousImport = null;

    for (ImportDetails importObject : importToGroupList) {
      final String importGroup = importObject.getImportGroup();
      final String fullImportIdent = importObject.importFullPath;

      if (!importGroup.equals(currentGroup)) {
        if (customImportOrderRules.size() > groupNumber + 1) {
          final String nextGroup = getNextImportGroup(groupNumber + 1);
          if (importGroup.equals(nextGroup)) {
            if (separateLineBetweenGroups && !hasEmptyLineBefore(importObject.getLineNumber())) {
              log(importObject.getLineNumber(), MSG_LINE_SEPARATOR, fullImportIdent);
            }
            currentGroup = nextGroup;
            groupNumber = customImportOrderRules.indexOf(nextGroup);
          } else {
            logWrongImportGroupOrder(importObject.getLineNumber(), importGroup);
          }
        } else {
          logWrongImportGroupOrder(importObject.getLineNumber(), importGroup);
        }
      } else if (sortImportsInGroupAlphabetically
          && previousImport != null
          && matchesImportGroup(importObject.isStaticImport(), fullImportIdent, currentGroup)
          && compareImports(fullImportIdent, previousImport) < 0) {
        log(importObject.getLineNumber(), MSG_LEX, fullImportIdent);
      }
      previousImport = fullImportIdent;
    }
  }