Class JavaParser
java.lang.Object
io.micronaut.annotation.processing.test.JavaParser
- All Implemented Interfaces:
Closeable,AutoCloseable
Utility for parsing Java code.
NOTE: Forked from Google Compile Testing Project
- Since:
- 1.1
- Author:
- graemerocher
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Iterable<? extends JavaFileObject>Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.Iterable<? extends JavaFileObject>generate(JavaFileObject... sources) Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.The type element visitor processor to use.The list of processors to use.protected @NonNull BeanDefinitionInjectProcessorTheBeanDefinitionInjectProcessorto use.getFiler()getJavacTask(JavaFileObject... sources) gets the javac task.protected @NonNull TypeElementVisitorProcessorThe type element visitor processor to use.parse(JavaFileObject... sources) Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.parseLines(String className, String... lines) Parsessourcesinto compilation units.readGenerated(@NonNull String filePath, String className, String code) Reads the contents of a generated file as a reader.
-
Constructor Details
-
JavaParser
public JavaParser()Default constructor.
-
-
Method Details
-
getDiagnosticCollector
- Returns:
- The diagnostic collector
-
getCompiler
- Returns:
- The compiler used
-
getFileManager
- Returns:
- The file manager
-
getFiler
- Returns:
- The filer
-
getProcessingEnv
- Returns:
- Dummy processing environment
-
parseLines
Parsessourcesinto compilation units. This method does not compile the sources.- Parameters:
className- The class namelines- The lines to parse- Returns:
- The elements
-
parse
Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits. This method does not compile the sources.- Parameters:
sources- The sources- Returns:
- The elements
-
getLastTask
- Returns:
- The last task that was used
-
getJavacTask
gets the javac task.- Parameters:
sources- The sources- Returns:
- the task
-
generate
Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits. This method does not compile the sources.- Parameters:
className- The class namecode- the raw code- Returns:
- The generated file objects
-
readGenerated
@Nullable public @Nullable Reader readGenerated(@NonNull @NonNull String filePath, String className, String code) throws IOException Reads the contents of a generated file as a reader.- Parameters:
filePath- The file pathclassName- The class name that produces the filecode- The code of the class- Returns:
- The generated file
- Throws:
IOException- when an error occurs reading the file
-
generate
Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits. This method does not compile the sources.- Parameters:
sources- The sources- Returns:
- The java file objects
-
getAnnotationProcessors
The list of processors to use.- Returns:
- The processor list
-
getBeanDefinitionInjectProcessor
TheBeanDefinitionInjectProcessorto use.- Returns:
- The
BeanDefinitionInjectProcessor
-
getTypeElementVisitorProcessor
The type element visitor processor to use.- Returns:
- The type element visitor processor
-
getAggregatingTypeElementVisitorProcessor
@NonNull protected @NonNull AggregatingTypeElementVisitorProcessor getAggregatingTypeElementVisitorProcessor()The type element visitor processor to use.- Returns:
- The type element visitor processor
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-