Creating and registering an error source

Errors are managed by implementations of the errorlist.ErrorSource abstract class. Extending this class is a bit involved and requires writing a lot of low-level code; most plugins can use the errorlist.DefaultErrorSource class instead, which provides a very easy-to-use front-end.

The constructor for the DefaultErrorSource class accepts one parameter; a string that will identify the error source. Currently, this identifier is not used, but in the future the ErrorList plugin might show which error comes from which plugin, for example.

Typically, error sources will be registered in your plugin's start() method, but that does not have to be the case. The Console plugin, for example, maintains a separate error source for each console window, and registers an unregisters them as consoles are opened and closed.

To add an error source to the list of registered error sources, you must call the static registerErrorSource() method of the errorlist.ErrorSource class.

A corresponding unregisterErrorSource()() method also exists, for advanced uses of the API, like the Console plugin mentioned above.

Putting all this together, a simple plugin core class start() method might look as follows:

public void start()
{
    errorSource = new DefaultErrorSource("MyPlugin");
    ErrorSource.registerErrorSource(errorSource);

    // any other initialization your plugin
    // needs to perform
}

Note that the newly-created error source is assigned to an instance variable. This allows the error source instance to be called upon later, when compiler errors are actually generated.