Package io.github.mkoncek.classpathless
Class JavaSourceReader
- java.lang.Object
-
- io.github.mkoncek.classpathless.JavaSourceReader
-
public class JavaSourceReader extends java.lang.ObjectDummy simple class to extract information from anInputStreamrepresenting 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 classJavaSourceReader.ReadLineResult
-
Field Summary
Fields Modifier and Type Field Description private java.io.BufferedReaderbrprivate static java.util.regex.PatternimportPatternstatic java.util.regex.PatternpackagePattern
-
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.StringreadSourcePackage()Read the package name.static java.lang.StringreadSourcePackage(java.lang.String source)Read the package name.
-
-
-
Method Detail
-
readSourcePackage
public java.lang.String readSourcePackage() throws java.io.IOExceptionRead 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.IOExceptionRead 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
-
-