Apache NetBeans
Apache NetBeans
Latest release

Apache NetBeans 23

Download

Getting to the javac information = writing a java infrastructure task

After brief description of how the infrastructure works we need to look at writing a task in more detail. The interface you need to implement looks like:

public interface CancellableTask<P> {

    public void cancel();

    public void run( P parameter ) throws Exception;

}

We already mentioned what is the cancel() method good for. The more interesting and more important method obviously is the run() method. You may see that it takes a parameter of type P. P can be generally anything as the interface can be used in other context than the java infrastructure as well. However, when using it for implementation of the java related tasks the P can become: CompilationInfo, CompilationController or WorkingCopy. It depends in how you registered or started your task. Considering the ordering each of the parameter types adds some functionality you may use.

  1. CompilationInfo - Used for read only tasks invoked by the infrastructure at given phase.

    • Permits for getting information about the source (Trees, Elements, Types)

    • Provides some utility classes for working with Trees, Elements and Types.

    • Knows FileObject and optionally the Document corresponding with the JavaSource

    • Knows the the errors (Diagnostics) the javac run into

    • Knows the token hierarchy

    • Knows the phase the compiler is in

  2. CompilationController - Used for read-only tasks which should be invoked on user’s action. Permits for moving Javac into given phase.

    • Can do everything what the CompilationInfo does

    • Can move javac to given phase

  3. WorkingCopy - Used for tasks which do modifications to the source

    • Does everything what the CompilationController does

    • Permits for doing modifications to the source