Interface LanguageSupport
-
- All Known Implementing Classes:
JavaLanguageSupport,KotlinGroovyLanguageSupport
public interface LanguageSupportSPI for plugging in import statement recognition for different languages. Implementations will be looked up using java'sServiceLoader.- Author:
- Simon Taddiken
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static LanguageSupportgetLanguageSupport(Path path)Returns theLanguageSupportimplementation for the given file.Set<String>getSupportedFileExtensions()The set of supported file extensions.static booleanisLanguageSupported(Path path)Determines whether there exists aLanguageSupportimplementation for the given path.default ParsedFileparseCompilationUnit(Path sourceFilePath, Charset charset)Called only whenparseFullCompilationUnitSupported()returns true.default booleanparseFullCompilationUnitSupported()When returning true, the framework will not use the line base import parser but will instead try to parse the whole source file usingparseCompilationUnit(Path, Charset).List<ImportStatement>parseImport(String importLine, int lineNumber)Extract the package names that this import statement represents.Optional<String>parsePackage(String line)Parses the given line and returns the declared package
-
-
-
Method Detail
-
getLanguageSupport
static LanguageSupport getLanguageSupport(Path path)
Returns theLanguageSupportimplementation for the given file.- Parameters:
path- The path to a file.- Returns:
- The
LanguageSupportimplementation or an empty optional if none was found.
-
isLanguageSupported
static boolean isLanguageSupported(Path path)
Determines whether there exists aLanguageSupportimplementation for the given path.- Parameters:
path- The path to a file.- Returns:
- Whether such implementation exists.
- Since:
- 1.1.0
-
parseFullCompilationUnitSupported
default boolean parseFullCompilationUnitSupported()
When returning true, the framework will not use the line base import parser but will instead try to parse the whole source file usingparseCompilationUnit(Path, Charset).- Returns:
- Whether this implementation supports full compilation unit parsing.
- Since:
- 2.1.0
-
parseCompilationUnit
default ParsedFile parseCompilationUnit(Path sourceFilePath, Charset charset) throws IOException
Called only whenparseFullCompilationUnitSupported()returns true.Used to parse a full source file into a
ParsedFile.By default, throws an
UnsupportedOperationException.- Parameters:
sourceFilePath- Path of the source file to parse.charset- Charset to apply when parsing.- Returns:
- The parsed file.
- Throws:
IOException- If an I/O error occurred.- Since:
- 2.1.0
-
getSupportedFileExtensions
Set<String> getSupportedFileExtensions()
The set of supported file extensions. Extensions returned here are case insensitive and may or may not start with a '.' (dot).- Returns:
- The set of file extensions.
-
parsePackage
Optional<String> parsePackage(String line)
Parses the given line and returns the declared package- Parameters:
line- Line in the source file- Returns:
- The package declared
-
parseImport
List<ImportStatement> parseImport(String importLine, int lineNumber)
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.e.g. import java.util.List; The above should return java.util.List in a Java source file.
- Parameters:
importLine- Line in the source filelineNumber- The line number of the import.- Returns:
- Fully qualified package name that this import represents
-
-