Class JavaParser
- java.lang.Object
-
- io.micronaut.annotation.processing.test.JavaParser
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class JavaParser extends java.lang.Object implements java.io.CloseableUtility for parsing Java code. NOTE: Forked from Google Compile Testing Project- Since:
- 1.1
-
-
Constructor Summary
Constructors Constructor Description JavaParser()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.lang.Iterable<? extends javax.tools.JavaFileObject>generate(java.lang.String className, java.lang.String code)Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.java.lang.Iterable<? extends javax.tools.JavaFileObject>generate(javax.tools.JavaFileObject... sources)Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.protected io.micronaut.annotation.processing.AggregatingTypeElementVisitorProcessorgetAggregatingTypeElementVisitorProcessor()The type element visitor processor to use.protected java.util.List<javax.annotation.processing.Processor>getAnnotationProcessors()The list of processors to use.protected io.micronaut.annotation.processing.BeanDefinitionInjectProcessorgetBeanDefinitionInjectProcessor()TheBeanDefinitionInjectProcessorto use.javax.tools.JavaCompilergetCompiler()javax.tools.JavaFileManagergetFileManager()javax.annotation.processing.FilergetFiler()com.sun.source.util.JavacTaskgetJavacTask(javax.tools.JavaFileObject... sources)gets the javac task.java.util.Optional<com.sun.source.util.JavacTask>getLastTask()javax.annotation.processing.ProcessingEnvironmentgetProcessingEnv()protected io.micronaut.annotation.processing.TypeElementVisitorProcessorgetTypeElementVisitorProcessor()The type element visitor processor to use.java.lang.Iterable<? extends javax.lang.model.element.Element>parse(javax.tools.JavaFileObject... sources)Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits.java.lang.Iterable<? extends javax.lang.model.element.Element>parseLines(java.lang.String className, java.lang.String... lines)Parsessourcesinto compilation units.java.io.ReaderreadGenerated(java.lang.String filePath, java.lang.String className, java.lang.String code)Reads the contents of a generated file as a reader.
-
-
-
Method Detail
-
getCompiler
public javax.tools.JavaCompiler getCompiler()
- Returns:
- The compiler used
-
getFileManager
public javax.tools.JavaFileManager getFileManager()
- Returns:
- The file manager
-
getFiler
public javax.annotation.processing.Filer getFiler()
- Returns:
- The filer
-
getProcessingEnv
public javax.annotation.processing.ProcessingEnvironment getProcessingEnv()
- Returns:
- Dummy processing environment
-
parseLines
public java.lang.Iterable<? extends javax.lang.model.element.Element> parseLines(java.lang.String className, java.lang.String... lines)Parsessourcesinto compilation units. This method does not compile the sources.- Parameters:
className- The class namelines- The lines to parse- Returns:
- The elements
-
parse
public java.lang.Iterable<? extends javax.lang.model.element.Element> parse(javax.tools.JavaFileObject... sources)
Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits. This method does not compile the sources.- Parameters:
sources- The sources- Returns:
- The elements
-
getLastTask
public java.util.Optional<com.sun.source.util.JavacTask> getLastTask()
- Returns:
- The last task that was used
-
getJavacTask
public com.sun.source.util.JavacTask getJavacTask(javax.tools.JavaFileObject... sources)
gets the javac task.- Parameters:
sources- The sources- Returns:
- the task
-
generate
public java.lang.Iterable<? extends javax.tools.JavaFileObject> generate(java.lang.String className, java.lang.String code)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 java.io.Reader readGenerated(@NonNull java.lang.String filePath, java.lang.String className, java.lang.String code) throws java.io.IOExceptionReads 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:
java.io.IOException- when an error occurs reading the file
-
generate
public java.lang.Iterable<? extends javax.tools.JavaFileObject> generate(javax.tools.JavaFileObject... sources)
Parsessourcesintocom.sun.source.tree.CompilationUnitTreeunits. This method does not compile the sources.- Parameters:
sources- The sources- Returns:
- The java file objects
-
getAnnotationProcessors
@NonNull protected java.util.List<javax.annotation.processing.Processor> getAnnotationProcessors()
The list of processors to use.- Returns:
- The processor list
-
getBeanDefinitionInjectProcessor
@NonNull protected io.micronaut.annotation.processing.BeanDefinitionInjectProcessor getBeanDefinitionInjectProcessor()
TheBeanDefinitionInjectProcessorto use.- Returns:
- The
BeanDefinitionInjectProcessor
-
getTypeElementVisitorProcessor
@NonNull protected io.micronaut.annotation.processing.TypeElementVisitorProcessor getTypeElementVisitorProcessor()
The type element visitor processor to use.- Returns:
- The type element visitor processor
-
getAggregatingTypeElementVisitorProcessor
@NonNull protected io.micronaut.annotation.processing.AggregatingTypeElementVisitorProcessor getAggregatingTypeElementVisitorProcessor()
The type element visitor processor to use.- Returns:
- The type element visitor processor
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-