Class JavaParser

java.lang.Object
io.micronaut.annotation.processing.test.JavaParser
All Implemented Interfaces:
Closeable, AutoCloseable

public class JavaParser extends Object implements Closeable
Utility for parsing Java code. NOTE: Forked from Google Compile Testing Project
Since:
1.1
Author:
graemerocher
  • Constructor Details

    • JavaParser

      public JavaParser()
      Default constructor.
  • Method Details

    • getDiagnosticCollector

      public DiagnosticCollector<JavaFileObject> getDiagnosticCollector()
      Returns:
      The diagnostic collector
    • getCompiler

      public JavaCompiler getCompiler()
      Returns:
      The compiler used
    • getFileManager

      public JavaFileManager getFileManager()
      Returns:
      The file manager
    • getFiler

      public Filer getFiler()
      Returns:
      The filer
    • getProcessingEnv

      public ProcessingEnvironment getProcessingEnv()
      Returns:
      Dummy processing environment
    • parseLines

      public Iterable<? extends Element> parseLines(String className, String... lines)
      Parses sources into compilation units. This method does not compile the sources.
      Parameters:
      className - The class name
      lines - The lines to parse
      Returns:
      The elements
    • parse

      public Iterable<? extends Element> parse(JavaFileObject... sources)
      Parses sources into com.sun.source.tree.CompilationUnitTree units. This method does not compile the sources.
      Parameters:
      sources - The sources
      Returns:
      The elements
    • getLastTask

      public Optional<JavacTask> getLastTask()
      Returns:
      The last task that was used
    • getJavacTask

      public JavacTask getJavacTask(JavaFileObject... sources)
      gets the javac task.
      Parameters:
      sources - The sources
      Returns:
      the task
    • generate

      public Iterable<? extends JavaFileObject> generate(String className, String code)
      Parses sources into com.sun.source.tree.CompilationUnitTree units. This method does not compile the sources.
      Parameters:
      className - The class name
      code - 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 path
      className - The class name that produces the file
      code - The code of the class
      Returns:
      The generated file
      Throws:
      IOException - when an error occurs reading the file
    • generate

      public Iterable<? extends JavaFileObject> generate(JavaFileObject... sources)
      Parses sources into com.sun.source.tree.CompilationUnitTree units. This method does not compile the sources.
      Parameters:
      sources - The sources
      Returns:
      The java file objects
    • getAnnotationProcessors

      @NonNull protected @NonNull List<Processor> getAnnotationProcessors()
      The list of processors to use.
      Returns:
      The processor list
    • getBeanDefinitionInjectProcessor

      @NonNull protected @NonNull BeanDefinitionInjectProcessor getBeanDefinitionInjectProcessor()
      Returns:
      The BeanDefinitionInjectProcessor
    • getTypeElementVisitorProcessor

      @NonNull protected @NonNull TypeElementVisitorProcessor 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 interface AutoCloseable
      Specified by:
      close in interface Closeable