Class JavaSourceReader
- java.lang.Object
-
- io.github.mkoncek.classpathless.impl.JavaSourceReader
-
public class JavaSourceReader extends java.lang.Object
A simple class to extract information from anInputStream
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
JavaSourceReader.ReadLineResult
-
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.
-
-
-
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
-
-