Back to top

vogella training Training Books

Eclipse Source Code - Tutorial

Lars Vogel

Version 3.3

01.08.2012

Revision History
Revision 0.1 - 0.6 23.05.2008 Lars
Vogel
Created Article
Revision 0.7 - 3.3 18.02.2009 - 01.08.2012 Lars
Vogel
bugfixes and enhancements

Eclipse Source Code Tutorial

This tutorial explains how to work with the Eclipse source code. It assumes that you are already familiar with using the Eclipse IDE and is based on Eclipse 4.2 (Eclipse Juno).


Table of Contents

1. Eclipse Source Code
2. Import Plugins
3. Plugin Spy
3.1. Plugin Spy for UI parts
3.2. Plugin Spy for menus
3.3. SWT spy
4. Include all plug-ins into the Eclipse search
5. Find plug-in for a certain class
6. Finding classes and plug-ins
6.1. Open Plugin Artifact
6.2. Plug-in Search
7. Finding commands for keybindings
8. Debugging Eclipse
9. Eclipse source code via Git
10. Feature Patch Projects
11. Thank you
12. Questions and Discussion
13. Links and Literature
13.1. Source Code
13.2. Eclipse Resources
13.3. vogella Resources

1. Eclipse Source Code

Developers are frequently advised to read high-quality code. Eclipse is a powerful, extensible IDE for building general purpose applications. Some of the key player in creating Eclipse are also well known for their software architecture skills. By reading the Eclipse source code you can learn a lot. It also helps to understand the Eclipse source code to address certain problems.

Especially if you develop Eclipse Plugins or Eclipse RCP application looking at the Eclipse Source code is useful.

2. Import Plugins

The following describes how you can import Eclipse plugins from your Eclipse installation to review the code. The Eclipse standard distribution contains the source code for the core Eclipse projects, e.g. Eclipse JDT . For other Eclipse projects you usually find a "SDK" bundle on the project update site which contains the source code.

To avoid "pollution" of your existing workspace, switch to a new workspace and select File -> Import. Select "Plug-ins and Fragments".

Make the following settings. Select "Binary projects". In Binary project you can read the source code but you cannot change it. They will also not be compiled therefore this setting will save memory and performance.

Add all plugins you would like to import and press "Finish".

You can you investigate the code of the imported plugins.

3. Plugin Spy

3.1. Plugin Spy for UI parts

The Plugin Spy gives you easily information about the running UI. Press Alt+Shift+F1 to get information about the current running Eclipse plug-in / data types / screen. This way you can get immediately access to the plug-in which is currently running.

Click on the active class or the contributing plug-in to get to the class or the source code of the class.

3.2. Plugin Spy for menus

Press "Alt + Shift + F2" and select a menu to see who is contributing this menu.

Tip

To use the Eclipse Plugin Spy in your Eclipse RCP application include the plug-in "org.eclipse.pde.runtime" into your application.

3.3. SWT spy

SWT spy for Eclipse is a tool that prints out information about the widget under the cursor. Currently, this includes style, layout and parent information. See SWT Tools for more information.

4. Include all plug-ins into the Eclipse search

By default the Eclipse Java tools only consider Java components, e.g. classes or interfaces, from the standard Java libraries and from the projects and their dependencies in the workspace as relevant for search operations.

For example the Ctrl+Shift+T (Open Type) shortcut will not find the ISources interface if it is not referred to in the current workspace.

You can add all classes from the current target platform, e.g. default is the Eclipse IDE, to be relevant for the Eclipse search via the following setting: WindowPreferencesPlug-in DevelopmentInclude all plug-ins from target into Java Search

How to add all Java classes from the Eclipse target platform to the Java search

5. Find plug-in for a certain class

Eclipse consists out of components called plug-ins.

You frequently have to find the plug-in which contains a certain class. After making the Include all plug-ins from target into Java Search setting in the Eclipse preferences you can use the Open Type dialog to find the plug-in for a class. The jar file is shown in this dialog and the prefix of the jar file is typically the plug-in which contains this class.

Open Type Dialog

Plug-in for an Java class

6. Finding classes and plug-ins

6.1. Open Plugin Artifact

Use the shortcut "Ctrl+Shift+A" to search for an extension point. Definition and usage of an extension point use different icons. For example to see which plug-in defines the org.eclipse.menu.ui extension point, enter it in the dialog and select the entry with the blue icon.

6.2. Plug-in Search

Plug-in Search allows you to perform a detailed search for extension points. Select the menu "Search" -> "Search" and the tab "Plug-in Search". The following will search for all declaration (defining an extension) to the extension point "org.eclipse.debug.core.launchConfigurationTypes".

7. Finding commands for keybindings

Eclipse allows to trace a running Eclipse and to write information to the console. This can be used to identify which command is associated with a certain keybinding. To use tracing modify your runtime configuration on the "Tracing" tab and set "Enable Tracing". For trace for example the keybindings of "org.eclipse.ui" plug-in select it and flag "debug".

Scroll down and select "trace/keybindings" and "trace/keybindings.verbose".

Make sure you have the -consoleLog flag maintained as an argument.

If you start now the Eclipse IDE and you use a shortcut the calling Eclipse will display a trace which contains the commandId.

In your calling Eclipse you can now use Search (text) to find the handler / action which implements this command.

8. Debugging Eclipse

You can also debug the Eclipse IDE if you want to see how certain things are done. Use for example the Plugin Spy to find the class / plug-in which you would like to invest. Put a breakpoint into the coding, for example in the constructor of the class or if the class shows UI elements "createPartControl". Create a Run Configuration which includes all Eclipse IDE plugins and run it.

If you now select Run -> Debug for your runtime configuration you can start debugging the interesting point.

9. Eclipse source code via Git

Eclipse projects primarily use Git.The following section describes the usage of Git.

The usage and background of Git is not described in this tutorial. Please see EGit Tutorial for details on how to use the EGit plug-in for Eclipse or see Git Tutorial to learn how to use Git from the command line.

The main Git repository be accessed to the via the Eclipse source code repository. You find links to all Eclipse Git repositories on this page.

To clone a project you check the webpage. For example if you want to clone the project Tycho you see on the webpage that the name is tycho and the repository is called org.eclipse.tycho.git. You can clone this repo via the following command.

git clone git://git.eclipse.org/gitroot/tycho/org.eclipse.tycho.git 

10. Feature Patch Projects

If you want to modify standard Eclipse plug-ins you can use Feature Patch Projects. A Feature Patch Project can contain plug-ins which replaces existing plug-ins. This would allow you to create update site for this feature and users can use your version of the modified code.

A feature project can get created via FileNewOther...Plug-in DevelopmentFeature Patch.

In this dialog select the feature which you want to patch. Add every modified plug-in to your new Feature Patch Projects and export is as p2 update site.

Every feature can only be patched once.

11. Thank you

Please help me to support this article:

Flattr this

12. Questions and Discussion

Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.com Google Group. I have created a short list how to create good questions which might also help you.

13. Links and Literature

13.1. Source Code

Source Code of Examples

13.2. Eclipse Resources

13.2.1. Eclipse Source Code

Setting up your ssh key for Eclipse.org

13.3. vogella Resources

vogella Training Android and Eclipse Training from the vogella team

Android Tutorial Introduction to Android Programming

GWT Tutorial Program in Java and compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test your application

Git Tutorial Put everything you have under distributed version control system