Class JavaLanguageSupport
- java.lang.Object
-
- de.skuzzle.enforcer.restrictimports.parser.lang.JavaLanguageSupport
-
- All Implemented Interfaces:
LanguageSupport
public class JavaLanguageSupport extends Object implements LanguageSupport
-
-
Constructor Summary
Constructors Constructor Description JavaLanguageSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>getSupportedFileExtensions()The set of supported file extensions.ParsedFileparseCompilationUnit(Path sourceFilePath, Charset charset)Called only whenLanguageSupport.parseFullCompilationUnitSupported()returns true.booleanparseFullCompilationUnitSupported()When returning true, the framework will not use the line base import parser but will instead try to parse the whole source file usingLanguageSupport.parseCompilationUnit(Path, Charset).List<ImportStatement>parseImport(String line, 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
-
getSupportedFileExtensions
public Set<String> getSupportedFileExtensions()
Description copied from interface:LanguageSupportThe set of supported file extensions. Extensions returned here are case insensitive and may or may not start with a '.' (dot).- Specified by:
getSupportedFileExtensionsin interfaceLanguageSupport- Returns:
- The set of file extensions.
-
parseFullCompilationUnitSupported
public boolean parseFullCompilationUnitSupported()
Description copied from interface:LanguageSupportWhen returning true, the framework will not use the line base import parser but will instead try to parse the whole source file usingLanguageSupport.parseCompilationUnit(Path, Charset).- Specified by:
parseFullCompilationUnitSupportedin interfaceLanguageSupport- Returns:
- Whether this implementation supports full compilation unit parsing.
-
parseCompilationUnit
public ParsedFile parseCompilationUnit(Path sourceFilePath, Charset charset) throws IOException
Description copied from interface:LanguageSupportCalled only whenLanguageSupport.parseFullCompilationUnitSupported()returns true.Used to parse a full source file into a
ParsedFile.By default, throws an
UnsupportedOperationException.- Specified by:
parseCompilationUnitin interfaceLanguageSupport- 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.
-
parsePackage
public Optional<String> parsePackage(String line)
Description copied from interface:LanguageSupportParses the given line and returns the declared package- Specified by:
parsePackagein interfaceLanguageSupport- Parameters:
line- Line in the source file- Returns:
- The package declared
-
parseImport
public List<ImportStatement> parseImport(String line, int lineNumber)
Description copied from interface:LanguageSupportExtract 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.
- Specified by:
parseImportin interfaceLanguageSupport- Parameters:
line- Line in the source filelineNumber- The line number of the import.- Returns:
- Fully qualified package name that this import represents
-
-