package de.skuzzle.enforcer.restrictimports.analyze;

import de.skuzzle.enforcer.restrictimports.parser.ImportStatement;
import de.skuzzle.enforcer.restrictimports.parser.ParsedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * Collects banned import matches from a single source file.
 *
 * @author Simon Taddiken
 */
class ImportAnalyzer {

    private static final Logger LOGGER = LoggerFactory.getLogger(ImportAnalyzer.class);

    /**
     * Collects all imports that are banned within the given source file.
     *
     * @param sourceFile The parsed file to check for banned imports..
     * @param groups The groups of banned imports to check the file against. From all
     *            groups, the one with the most specific base pattern match is chosen.
     * @return a {@link MatchedFile} holds information about the found matches. Returns an
     *         empty optional if no matches were found.
     */
    public Optional<MatchedFile> matchFile(ParsedFile sourceFile, BannedImportGroups groups) {
        LOGGER.trace("Analyzing {} for banned imports", sourceFile);

        final BannedImportGroup group = groups.selectGroupFor(sourceFile.getFqcn()).orElse(null);
        if (group == null) {
            return Optional.empty();
        }

        final List<MatchedImport> matches = new ArrayList<>();
        for (ImportStatement importStmt : sourceFile.getImports()) {
            group.ifImportIsBanned(importStmt.getImportName())
                    .map(bannedImport -> new MatchedImport(importStmt.getLine(), importStmt.getImportName(), bannedImport))
                    .ifPresent(matches::add);
        }
        if (matches.isEmpty()) {
            return Optional.empty();
        }
        return Optional.of(new MatchedFile(sourceFile.getPath(), matches, group));
    }
}

@@ -1020,15 +1020,8 @@
     
-public 
 Opti
@@ -1313,42 +1313,171 @@
     
-return Optional.empty();%0A        %7D
+LOGGER.trace(%22No rule group matched %7B%7D%22, sourceFile);%0A            return Optional.empty();%0A        %7D%0A        LOGGER.trace(%22Selected %7B%7D for %7B%7D%22, group, sourceFile);
 %0A%0A  
@@ -1941,27 +1941,40 @@
     
-return Optional.of(
+final MatchedFile matchedFile = 
 new 
@@ -2022,16 +2022,126 @@
 , group)
+;%0A        LOGGER.debug(%22Found banned import matches: %7B%7D%22, matchedFile);%0A        return Optional.of(matchedFile
 );%0A    %7D

Add log statement about rule selection