Time for action – modifying the platform

Once the location of interest has been found, it is necessary to modify the code to attempt a fix. For example, if the developer wanted to ensure that the window's title was all in upper case, it would be necessary to inject a title.toUpperCase() call. However, since the .class file is read-only, it is necessary to import the plug-in's source into the workspace to change the implementation.

  1. Using the Window | Show View | Other… menu or the Quick Access box, open the Plug-ins view from the Plug-in Development category. This will show a list of all plug-ins installed into the system.
  2. Type org.eclipse.swt to scroll down the list, and select both the org.eclipse.swt bundle and the org.eclipse.swt.* fragment that corresponds to the platform. For example, on macOS this will start with org.eclipse.swt.cocoa, while on Windows it will start with org.eclipse.swt.win32; and on Linux, org.eclipse.swt.gtk:
    Time for action – modifying the platform
  3. Right-click on the selected items and choose Import As | Source Project to load the source code projects into the workspace. After a brief period of compilation, the projects should be ready to use.
  4. Close the existing files and then use Open Type to re-open the Shell from the org.eclipse.swt.widgets package. Instead of showing Shell.class in the editor title, it should now say Shell.java and should be mutable.
  5. Go to the setText method and add a re-assignment of the string to convert it to upper case:
    public void setText(String string) {
      checkWidget();
      if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
      if (window == null) return;
      string = string.toUpperCase();
      super.setText(string);
  6. Run the launch configuration again and the window titles should be displayed in capital letters.

What just happened?

Debugging and introspecting variables can be done without source code, but in order to make changes, it is necessary to import the source code. Eclipse provides an easy way to import source code associated with the plug-in using the Plug-ins view and using Import As | Source Project.

When importing as a source project, a project is set up and the source code imported in and compiled. This will give the ability for the compiler to pick up any problems with code changes for the projects that are in the workspace.

Note

It is not possible to use this import technique for plug-ins that have no associated source plug-in.

If the only changes required are to modify the plugin.xml (for example, adding another extension), then the project can be imported as a Binary Project or Binary Project with Linked Content. Both of these options are faster, since the previously compiled code is used instead of recompiling with source. The only difference is whether the Jar file is copied into the project or a project link (like a symlink) is used to refer to the Jar from the platform's plugins directory. In neither case can the existing source files be modified.

Once the source code is available, it can be changed and debugged just like any other plug-in project. In addition, the version of the source code is guaranteed to be the same as the version of the installed plug-in.

Checking out from Git

Although local changes can be made for testing purposes, in order to get a change uploaded, it is necessary to check out the project from Eclipse's servers at the canonical git.eclipse.org repository. This requires a Git plug-in (using EGit) and optionally a command-line Git tool as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.228.88