Class JavaSourceReader

java.lang.Object
io.github.mkoncek.classpathless.JavaSourceReader

public class JavaSourceReader extends 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 Details

    • packagePattern

      public static final Pattern packagePattern
    • importPattern

      private static final Pattern importPattern
    • br

      private BufferedReader br
  • Constructor Details

    • JavaSourceReader

      public JavaSourceReader(InputStream is)
  • Method Details

    • 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.
    • readImports

      public static Collection<String> readImports(String source) throws IOException
      Throws:
      IOException