package de.skuzzle.enforcer.restrictimports.parser.lang;

import de.skuzzle.enforcer.restrictimports.parser.ImportStatement;

import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;

/**
 * SPI for plugging in import statement recognition for different languages.
 * Implementations will be looked up using java's {@link ServiceLoader}.
 *
 * @author Simon Taddiken
 */
public interface LanguageSupport {


    static Optional<LanguageSupport> getLanguageSupport(String extension) {
        return SupportedLanguageHolder.getLanguageSupport(extension);
    }

    static boolean isLanguageSupported(String extension) {
        return SupportedLanguageHolder.isLanguageSupported(extension);
    }

    /**
     * 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);
}

@@ -451,161 +451,647 @@
  %7B%0A%0A
-%0A    static Optional%3CLanguageSupport%3E getLanguageSupport(String extension) %7B%0A        return SupportedLanguageHolder.getLanguageSupport(extension);%0A    %7D%0A
+    /**%0A     * Returns the %7B@link LanguageSupport%7D implementation for the given file%0A     * extension.%0A     *%0A     * @param extension The extension.%0A     * @return The %7B@link LanguageSupport%7D implementation or an empty optional%0A     * if none was found.%0A     */%0A    static Optional%3CLanguageSupport%3E getLanguageSupport(String extension) %7B%0A        return SupportedLanguageHolder.getLanguageSupport(extension);%0A    %7D%0A%0A    /**%0A     * Determines whether there exists a %7B@link LanguageSupport%7D implementation for%0A     * the given extension.%0A     *%0A     * @param extension The extension.%0A     * @return Whether such implementation exists.%0A     */
 %0A   

Add javadoc