Class JavaSourceReader


  • public class JavaSourceReader
    extends java.lang.Object
    Dummy simple class to extract information from an InputStream representing a Java source file. Reads by lines removing comments until the first "{" symbol (start of class / interface / enum / ...) declaration. Then removes all the content until the first "@" (annotation). Then searches for the package pattern in the leftover string.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.BufferedReader br  
      private static java.util.regex.Pattern importPattern  
      static java.util.regex.Pattern packagePattern  
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaSourceReader​(java.io.InputStream is)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Collection<java.lang.String> readImports​(java.lang.String source)  
      java.lang.String readSourcePackage()
      Read the package name.
      static java.lang.String readSourcePackage​(java.lang.String source)
      Read the package name.
      • Methods inherited from class java.lang.Object

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

      • packagePattern

        public static final java.util.regex.Pattern packagePattern
      • importPattern

        private static final java.util.regex.Pattern importPattern
      • br

        private java.io.BufferedReader br
    • Constructor Detail

      • JavaSourceReader

        public JavaSourceReader​(java.io.InputStream is)
    • Method Detail

      • readSourcePackage

        public java.lang.String readSourcePackage()
                                           throws java.io.IOException
        Read the package name.
        Returns:
        Package name or null if none was found.
        Throws:
        java.io.IOException - If an IO error occurs.
      • readSourcePackage

        public static java.lang.String readSourcePackage​(java.lang.String source)
                                                  throws java.io.IOException
        Read the package name.
        Parameters:
        source - The source code
        Returns:
        Package name or null if none was found.
        Throws:
        java.io.IOException - If an IO error occurs.
      • readImports

        public static java.util.Collection<java.lang.String> readImports​(java.lang.String source)
                                                                  throws java.io.IOException
        Throws:
        java.io.IOException