How to implement your own application

This section more or less explains step by step how to implement your own application, by using the application framework.

The runInternal method

Some things to consider when implementing the runInternal method:

  • If you want to support stand-alone execution, register all Eclipse Modeling Framework (EMF) metamodels with the EMF metamodel registry. Also register any parsers, constraints, etc. For instance:

    if (!Platform.isRunning()) {
        // Register languages and parsers for stand-alone execution.
        LanguageRegistry.register...(...)
    }
  • The start of the runInternal method is a good place to add output components, as all options have been fully processed at this point. Output components can be registered by using the application’s output provider (though static methods).

  • The code in this method and all code directly or indirectly executed by this method, should regularly call the AppEnv.isTerminationRequested method, to find out whether the application should be terminated.

    In general, it is best to separate application code from library code. In the library code that needs to check for termination, require an argument of type Termination in the methods invoked from the application. Then pass () -> isTerminationRequested() to such methods for the Termination-typed arguments.

    To prevent having to return dummy values from methods in case termination was requested, which must then be checked by the caller, and so on recursively, it can be useful to use Termination.throwIfRequested. If termination is requested, the throwIfRequested method throws a TerminationException, which is automatically handled by the application framework.

  • For the return code of this method, always use value zero, to indicate successful termination. Other exit codes are automatically generated by the exception framework, if applicable. See also the exit codes section.