Class JavaSourceReader
- java.lang.Object
-
- io.github.mkoncek.classpathless.impl.JavaSourceReader
-
public class JavaSourceReader extends Object
A 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.- Author:
- Marián Konček
-
-
Field Summary
Fields Modifier and Type Field Description static PatternpackagePattern
-
Constructor Summary
Constructors Constructor Description JavaSourceReader(InputStream is)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Collection<String>readImports(String source)StringreadSourcePackage()Read the package name.static StringreadSourcePackage(String source)Read the package name.
-
-
-
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.
-
readImports
public static Collection<String> readImports(String source) throws IOException
- Throws:
IOException
-
-