// Path: src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/LanguageSupport.java
// public interface LanguageSupport {
// 
//     /**
//      * Returns the {@link LanguageSupport} implementation for the given file.
//      *
//      * @param path The path to a file.
//      * @return The {@link LanguageSupport} implementation or an empty optional if none was
//      *         found.
//      */
//     static LanguageSupport getLanguageSupport(Path path) {
//         final String extension = FileExtension.fromPath(path);
//         return SupportedLanguageHolder.getLanguageSupport(extension)
//                 .orElseThrow(() -> new IllegalArgumentException(String.format(
//                         "Could not find a LanguageSupport implementation for normalized file extension: '%s' (%s)",
//                         extension, path)));
//     }
// 
//     /**
//      * Determines whether there exists a {@link LanguageSupport} implementation for the
//      * given path.
//      *
//      * @param path The path to a file.
//      * @return Whether such implementation exists.
//      * @since 1.1.0
//      */
//     static boolean isLanguageSupported(Path path) {
//         final Path filename = path.getFileName();
//         return !Files.isDirectory(path)
//                 && SupportedLanguageHolder.isLanguageSupported(FileExtension.fromPath(filename));
//     }
// 
//     /**
//      * The set of supported file extensions. Extensions returned here are case insensitive
//      * and may or may not start with a '.' (dot).
//      *
//      * @return The set of file extensions.
//      */
//     Set<String> getSupportedFileExtensions();
// 
//     /**
//      * Parses the given line and returns the declared package
//      *
//      * @param line Line in the source file
//      * @return The package declared
//      */
//     Optional<String> parsePackage(String line);
// 
//     /**
//      * Extract the package names that this import statement represents. As some languages
//      * allow to specify multiple imports in a single line, this method returns a list.
//      * <p>
//      * e.g. import java.util.List; The above should return java.util.List in a Java source
//      * file.
//      *
//      * @param importLine Line in the source file
//      * @param lineNumber The line number of the import.
//      * @return Fully qualified package name that this import represents
//      */
//     List<ImportStatement> parseImport(String importLine, int lineNumber);
// }
// 
// Path: src/main/java/de/skuzzle/enforcer/restrictimports/util/Preconditions.java
// public final class Preconditions {
// 
//     public static void checkArgument(boolean condition) {
//         checkArgument(condition, "Unexpected argument");
//     }
// 
//     public static void checkArgument(boolean condition, String message, Object... args) {
//         if (!condition) {
//             throw new IllegalArgumentException(String.format(message, args));
//         }
//     }
// 
//     public static void checkState(boolean condition) {
//         checkState(condition, "Unexpected state");
//     }
// 
//     public static void checkState(boolean condition, String message, Object... args) {
//         if (!condition) {
//             throw new IllegalStateException(String.format(message, args));
//         }
//     }
// 
//     private Preconditions() {
//         throw new IllegalStateException("hidden");
//     }
// }


import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.skuzzle.enforcer.restrictimports.parser.lang.LanguageSupport;
import de.skuzzle.enforcer.restrictimports.util.Preconditions;
package de.skuzzle.enforcer.restrictimports.parser;




/**
 * Parses a source file into a {@link ParsedFile} representation.
 */
final class ImportStatementParserImpl implements ImportStatementParser {

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

    private final LineSupplier supplier;

    /**
     * Constructor just for testing purposes.
     *
     * @param supplier The line sources
     */
    ImportStatementParserImpl(LineSupplier supplier) {
        this.supplier = supplier;
    }

    @Override
    public ParsedFile parse(Path sourceFilePath) {
        LOGGER.trace("Analyzing {} for imports", sourceFilePath);

// Path: src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/LanguageSupport.java
// public interface LanguageSupport {
// 
//     /**
//      * Returns the {@link LanguageSupport} implementation for the given file.
//      *
//      * @param path The path to a file.
//      * @return The {@link LanguageSupport} implementation or an empty optional if none was
//      *         found.
//      */
//     static LanguageSupport getLanguageSupport(Path path) {
//         final String extension = FileExtension.fromPath(path);
//         return SupportedLanguageHolder.getLanguageSupport(extension)
//                 .orElseThrow(() -> new IllegalArgumentException(String.format(
//                         "Could not find a LanguageSupport implementation for normalized file extension: '%s' (%s)",
//                         extension, path)));
//     }
// 
//     /**
//      * Determines whether there exists a {@link LanguageSupport} implementation for the
//      * given path.
//      *
//      * @param path The path to a file.
//      * @return Whether such implementation exists.
//      * @since 1.1.0
//      */
//     static boolean isLanguageSupported(Path path) {
//         final Path filename = path.getFileName();
//         return !Files.isDirectory(path)
//                 && SupportedLanguageHolder.isLanguageSupported(FileExtension.fromPath(filename));
//     }
// 
//     /**
//      * The set of supported file extensions. Extensions returned here are case insensitive
//      * and may or may not start with a '.' (dot).
//      *
//      * @return The set of file extensions.
//      */
//     Set<String> getSupportedFileExtensions();
// 
//     /**
//      * Parses the given line and returns the declared package
//      *
//      * @param line Line in the source file
//      * @return The package declared
//      */
//     Optional<String> parsePackage(String line);
// 
//     /**
//      * Extract the package names that this import statement represents. As some languages
//      * allow to specify multiple imports in a single line, this method returns a list.
//      * <p>
//      * e.g. import java.util.List; The above should return java.util.List in a Java source
//      * file.
//      *
//      * @param importLine Line in the source file
//      * @param lineNumber The line number of the import.
//      * @return Fully qualified package name that this import represents
//      */
//     List<ImportStatement> parseImport(String importLine, int lineNumber);
// }
// 
// Path: src/main/java/de/skuzzle/enforcer/restrictimports/util/Preconditions.java
// public final class Preconditions {
// 
//     public static void checkArgument(boolean condition) {
//         checkArgument(condition, "Unexpected argument");
//     }
// 
//     public static void checkArgument(boolean condition, String message, Object... args) {
//         if (!condition) {
//             throw new IllegalArgumentException(String.format(message, args));
//         }
//     }
// 
//     public static void checkState(boolean condition) {
//         checkState(condition, "Unexpected state");
//     }
// 
//     public static void checkState(boolean condition, String message, Object... args) {
//         if (!condition) {
//             throw new IllegalStateException(String.format(message, args));
//         }
//     }
// 
//     private Preconditions() {
//         throw new IllegalStateException("hidden");
//     }
// }


// Path: src/main/java/de/skuzzle/enforcer/restrictimports/parser/ImportStatementParserImpl.java
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.skuzzle.enforcer.restrictimports.parser.lang.LanguageSupport;
import de.skuzzle.enforcer.restrictimports.util.Preconditions;

package de.skuzzle.enforcer.restrictimports.parser;




/**
 * Parses a source file into a {@link ParsedFile} representation.
 */
final class ImportStatementParserImpl implements ImportStatementParser {

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

    private final LineSupplier supplier;

    /**
     * Constructor just for testing purposes.
     *
     * @param supplier The line sources
     */
    ImportStatementParserImpl(LineSupplier supplier) {
        this.supplier = supplier;
    }

    @Override
    public ParsedFile parse(Path sourceFilePath) {
        LOGGER.trace("Analyzing {} for imports", sourceFilePath);

        final LanguageSupport languageSupport = LanguageSupport.getLanguageSupport(sourceFilePath);