Class BaseSourceCodeProvider

java.lang.Object
io.github.mmm.code.base.loader.BaseSourceCodeProvider
All Implemented Interfaces:
SourceCodeProvider, AutoCloseable
Direct Known Subclasses:
BaseSourceCodeProviderArchive, BaseSourceCodeProviderDirectory

public abstract class BaseSourceCodeProvider extends Object implements SourceCodeProvider
Abstract base implementation of SourceCodeProvider.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Constructor Details

    • BaseSourceCodeProvider

      public BaseSourceCodeProvider()
      The constructor.
    • BaseSourceCodeProvider

      public BaseSourceCodeProvider(String typeExtension)
      The constructor.
      Parameters:
      typeExtension - the type extension.
  • Method Details

    • getTypeExtension

      public String getTypeExtension()
      Returns:
      the extension of a file containing the source-code of a CodeType. Examples are ".java", ".ts", ".kt", ".cs", etc.
    • openType

      public Reader openType(String qualifiedName) throws IOException
      Specified by:
      openType in interface SourceCodeProvider
      Parameters:
      qualifiedName - the qualified name of the CodeType to open.
      Returns:
      a new Reader to read the source-code from or null if the requested type was not found.
      Throws:
      IOException - on I/O error.
      See Also:
    • openPackage

      public Reader openPackage(String qualifiedName) throws IOException
      Specified by:
      openPackage in interface SourceCodeProvider
      Parameters:
      qualifiedName - the qualified name of the CodePackage to open.
      Returns:
      a new Reader to read the source-code from or null if the requested package was not found.
      Throws:
      IOException - on I/O error.
    • scanPackage

      public List<String> scanPackage(String qualifiedName)
      Specified by:
      scanPackage in interface SourceCodeProvider
      Parameters:
      qualifiedName - the qualified name of the CodePackage to scan.
      Returns:
      a List with the simple names of the CodeTypes in the specified package or null if scan is not supported.
    • getPath

      protected abstract Path getPath(String path)
      Parameters:
      path - the Path as String.
      Returns:
      the actual Path.
    • isClosed

      protected abstract boolean isClosed()
      Returns:
      true if close was called, false otherwise.
    • requireNotClosed

      protected void requireNotClosed()
      Verifies that this provider has not yet been SourceCodeProvider.close()d.
    • openReader

      protected Reader openReader(InputStream in) throws IOException
      Parameters:
      in - the InputStream to read.
      Returns:
      the Reader for the given InputStream.
      Throws:
      IOException - on I/O error.
    • qualifiedName2TypePath

      protected String qualifiedName2TypePath(String qualifiedName)
      Parameters:
      qualifiedName - the qualified name.
      Returns:
      the filesystem path of the CodeType for the given qualifiedName.
    • filename2TypeSimpleName

      protected String filename2TypeSimpleName(String filename)
      Parameters:
      filename - the filename to convert.
      Returns:
      the simple name of the corresponding CodeType or null if not a CodeType.
    • qualifiedName2PackagePath

      protected String qualifiedName2PackagePath(String qualifiedName)
      Parameters:
      qualifiedName - the qualified name.
      Returns:
      the filesystem path of the CodeType for the given qualifiedName.
    • qualifiedName2Path

      protected String qualifiedName2Path(String qualifiedName)
      Parameters:
      qualifiedName - the qualified name.
      Returns:
      the filesystem path for the given qualifiedName.
    • of

      public static BaseSourceCodeProvider of(File sourceCodeLocation)
      Parameters:
      sourceCodeLocation - the File pointing to the location of the source code. See CodeSource.getSourceCodeLocation().
      Returns:
      the BaseSourceCodeProvider or null if the give File is null or does not exist.
    • of

      public static BaseSourceCodeProvider of(File sourceCodeLocation, String typeExtension)
      Parameters:
      sourceCodeLocation - the File pointing to the location of the source code. See CodeSource.getSourceCodeLocation().
      typeExtension - the type extension.
      Returns:
      the BaseSourceCodeProvider or null if the give File is null or does not exist.