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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Iterable<? extends JavaFileObject>
Parsessources
intocom.sun.source.tree.CompilationUnitTree
units.Iterable<? extends JavaFileObject>
generate
(JavaFileObject... sources) Parsessources
intocom.sun.source.tree.CompilationUnitTree
units.The type element visitor processor to use.The list of processors to use.protected @NonNull BeanDefinitionInjectProcessor
TheBeanDefinitionInjectProcessor
to use.getFiler()
getJavacTask
(JavaFileObject... sources) gets the javac task.protected @NonNull TypeElementVisitorProcessor
The type element visitor processor to use.parse
(JavaFileObject... sources) Parsessources
intocom.sun.source.tree.CompilationUnitTree
units.parseLines
(String className, String... lines) Parsessources
into 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
-
getCompiler
- Returns:
- The compiler used
-
getFileManager
- Returns:
- The file manager
-
getFiler
- Returns:
- The filer
-
getProcessingEnv
- Returns:
- Dummy processing environment
-
parseLines
Parsessources
into compilation units. This method does not compile the sources.- Parameters:
className
- The class namelines
- The lines to parse- Returns:
- The elements
-
parse
Parsessources
intocom.sun.source.tree.CompilationUnitTree
units. 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
Parsessources
intocom.sun.source.tree.CompilationUnitTree
units. 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
Parsessources
intocom.sun.source.tree.CompilationUnitTree
units. 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
TheBeanDefinitionInjectProcessor
to 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-