JavacTask (Compiler Tree API )
Keywords: com.sun.source.util.JavacTask class
Date: 2015-05-24

com.sun.source.util

## Class JavacTask

- java.lang.Object
- - com.sun.source.util.JavacTask

- All Implemented Interfaces:
    Callable<Boolean>, JavaCompiler.CompilationTask

      @Exported
      public abstract class JavacTask
      extends Object
      implements JavaCompiler.CompilationTask

  Provides access to functionality specific to the JDK Java Compiler, javac.
  Since:
    1.6

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JavacTask()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `addTaskListener(TaskListener taskListener)` The specified listener will receive notification of events describing the progress of this compilation task.
    `abstract Iterable<? extends Element>` | `analyze()` Complete all analysis.
    `abstract Iterable<? extends JavaFileObject>` | `generate()` Generate code.
    `abstract Elements` | `getElements()` Get a utility object for dealing with program elements.
    `abstract TypeMirror` | `getTypeMirror(Iterable<? extends Tree> path)` Get a type mirror of the tree node determined by the specified path.
    `abstract Types` | `getTypes()` Get a utility object for dealing with type mirrors.
    `static JavacTask` | `instance(ProcessingEnvironment processingEnvironment)` Get the `JavacTask` for a `ProcessingEnvironment`.
    `abstract Iterable<? extends CompilationUnitTree>` | `parse()` Parse the specified files returning a list of abstract syntax trees.
    `abstract void` | `removeTaskListener(TaskListener taskListener)` The specified listener will no longer receive notification of events describing the progress of this compilation task.
    `abstract void` | `setTaskListener(TaskListener taskListener)` The specified listener will receive notification of events describing the progress of this compilation task.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface javax.tools.JavaCompiler.CompilationTask

      `call, setLocale, setProcessors`

- - ### Constructor Detail

    - #### JavacTask

          public JavacTask()

  - ### Method Detail

    - #### instance

          public static JavacTask instance(ProcessingEnvironment processingEnvironment)

      Get the `JavacTask` for a `ProcessingEnvironment`. If the compiler is being invoked using a `CompilationTask`, then that task will be returned.
      Parameters:
        `processingEnvironment` - the processing environment
      Returns:
        the `JavacTask` for a `ProcessingEnvironment`
      Since:
        1.8

    - #### parse

          public abstract Iterable<? extends CompilationUnitTree> parse()
                                                                 throws IOException

      Parse the specified files returning a list of abstract syntax trees.
      Returns:
        a list of abstract syntax trees
      Throws:
        `IOException` - if an unhandled I/O error occurred in the compiler.
        `IllegalStateException` - if the operation cannot be performed at this time.

    - #### analyze

          public abstract Iterable<? extends Element> analyze()
                                                       throws IOException

      Complete all analysis.
      Returns:
        a list of elements that were analyzed
      Throws:
        `IOException` - if an unhandled I/O error occurred in the compiler.
        `IllegalStateException` - if the operation cannot be performed at this time.

    - #### generate

          public abstract Iterable<? extends JavaFileObject> generate()
                                                               throws IOException

      Generate code.
      Returns:
        a list of files that were generated
      Throws:
        `IOException` - if an unhandled I/O error occurred in the compiler.
        `IllegalStateException` - if the operation cannot be performed at this time.

    - #### setTaskListener

          public abstract void setTaskListener(TaskListener taskListener)

      The specified listener will receive notification of events describing the progress of this compilation task. If another listener is receiving notifications as a result of a prior call of this method, then that listener will no longer receive notifications. Informally, this method is equivalent to calling `removeTaskListener` for any listener that has been previously set, followed by `addTaskListener` for the new listener.
      Throws:
        `IllegalStateException` - if the specified listener has already been added.

    - #### addTaskListener

          public abstract void addTaskListener(TaskListener taskListener)

      The specified listener will receive notification of events describing the progress of this compilation task. This method may be called at any time before or during the compilation.
      Throws:
        `IllegalStateException` - if the specified listener has already been added.
      Since:
        1.8

    - #### removeTaskListener

          public abstract void removeTaskListener(TaskListener taskListener)

      The specified listener will no longer receive notification of events describing the progress of this compilation task. This method may be called at any time before or during the compilation.
      Since:
        1.8

    - #### getTypeMirror

          public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path)

      Get a type mirror of the tree node determined by the specified path. This method has been superceded by methods on `Trees`.
      See Also:
        `Trees.getTypeMirror(com.sun.source.util.TreePath)`

    - #### getElements

          public abstract Elements getElements()

      Get a utility object for dealing with program elements.

    - #### getTypes

          public abstract Types getTypes()

      Get a utility object for dealing with type mirrors.

Copyright © 2005, 2015, Oracle and/or its affiliates. All rights reserved.