Class JavaSourceReader


  • public class JavaSourceReader
    extends Object
    A 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.
    Author:
    Marián Konček
    • Field Detail

      • packagePattern

        public static final Pattern packagePattern
    • Constructor Detail

      • JavaSourceReader

        public JavaSourceReader​(InputStream is)
    • Method Detail

      • readSourcePackage

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

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