Class CodeSnippetExtractor


  • public class CodeSnippetExtractor
    extends java.lang.Object
    This class allows to extract code snippets from source codes contained in a set of directory paths.

    A code snippet is a sample of source codes with a title and a short description that serves to illustrate a specific code usage. Code snippets can either provide a single snippet or contain a list of steps, each one with a title and a description.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.Map<java.lang.String,​java.lang.Integer> _idCache  
      (package private) java.util.Map<java.lang.String,​SnippetReader> _readers  
    • Constructor Summary

      Constructors 
      Constructor Description
      CodeSnippetExtractor()
      Construct a code snippet extractor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addReader​(SnippetReader reader)  
      private static void checkPath​(java.lang.String[] directoryPaths)  
      java.util.List<CodeSnippetDTO> extract​(java.lang.String... directoryPaths)
      Extract a list of code snippet by analyzing source codes contained in the directory paths given in argument.
      private java.util.stream.Stream<Snippet> extractSnippets​(java.io.File file)  
      private java.lang.String generateId​(java.lang.String baseId)  
      private java.util.List<java.io.File> getSupportedFiles​(java.lang.String[] directoryPaths)  
      private void init()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _idCache

        final java.util.Map<java.lang.String,​java.lang.Integer> _idCache
      • _readers

        final java.util.Map<java.lang.String,​SnippetReader> _readers
    • Constructor Detail

      • CodeSnippetExtractor

        public CodeSnippetExtractor()
        Construct a code snippet extractor.
    • Method Detail

      • extract

        public java.util.List<CodeSnippetDTO> extract​(java.lang.String... directoryPaths)
        Extract a list of code snippet by analyzing source codes contained in the directory paths given in argument.

        Code snippets are ordered as they appear in the directories (files are first sorted in a lexicographic order).

        Parameters:
        directoryPaths - a list of directory paths from which code snippets are looked up.
        Returns:
        an ordered list of code snippets.
      • checkPath

        private static void checkPath​(java.lang.String[] directoryPaths)
      • generateId

        private java.lang.String generateId​(java.lang.String baseId)
      • init

        private void init()
      • getSupportedFiles

        private java.util.List<java.io.File> getSupportedFiles​(java.lang.String[] directoryPaths)
      • extractSnippets

        private java.util.stream.Stream<Snippet> extractSnippets​(java.io.File file)