`
hlbng
  • 浏览: 174785 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Source Code Guide of Eclipse 3.4 (Ganymede)

    博客分类:
  • RCP
阅读更多

Abstract

Developers are frequently advised to read existing high-quality code. Having easy access to the Eclipse sources can be extremely helpful in familiarizing yourself with the coding patterns inherent in Eclipse.

This article describes how to access the Eclipse source code, how to use the Plug-in Spy to identify a plug-in which is responsible for a certain part of the user interface and how to debug Eclipse. It also give a few examples how to search for code.

The Eclipse code base is stored in a cvs version control system. It will also be described how to access the source code for this.

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.

This article assumes that you are already familiar with using the Eclipse IDE.


1. Importing the sources

1.1. Create Workspace

Create a new workspace, e.g. "EclipseSource".

 

Tip1

It is highly recommended to test this with a new workspace as the plug-ins will be copied into this workspace, hence you will "pollute" an existing workspace. If later you decided that you would like to have access to the sources in your normal workspace you can do this again and use a filter to hide them.

 

 

Tip2

The Eclipse distribution usually contains already the source code for some Eclipse projects, e.g. Eclipse Platform, JDT, PDE, etc. For other Eclipse projects you usually find a "SDK" bundle on the project update side which contains the source code.

 

1.2. Binary projects

Eclipse has the option to import binary project. This will tell Eclipse that you want to read the source code of the plug-ins but that you do not want to change / compile the source code. As the Eclipse source code is very large this setting will save memory and will allow so search the code quickly.

1.3. Import

Select File -> Import. Select "Plug-ins and Fragments".

 

 

Make the following settings. Very important is the setting "Binary projects".

 

 

From the displayed list select all plugs-ins which are of interest for you (if in doubt, select all) and press the "Add" button.

 

 

Press finish to import all into your workspace. The copying process may run a while.

Now that you have the code you should start digging around in the code. Eclipse allows several ways of doing this. The following chapter will give examples how to do this.

2. Working with Extensions

2.1. Search Extension Points

You can search for the declaration / usage of an extension point. The following will search for the declaration of an extension point "org.eclipse.ui.commands".

 

 

 

 

The result should be displayed in the search view. Double-click on the result to go to the plug-in.

2.2. Using Help

You find the Eclipse Platform extension points documented in the Help under Platform Plug-in Developer Guide -> Reference -> Extension Point Reference

3. Plug-in Spy

Eclipse Ganymede introduced a very useful tool, the Plug-in Spy. Press Alt+Shift+F1 to get information about the current running Eclipse plugin / 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.

4. Finding Source Code

4.1. Example: Create Initial Layout

Lets assume you writing a Rich Client Platform application and you are wondering how the layout in Perspective.java can be handled. In an Eclipse RCP application the method createInitialLayout in Perspective.java is responsible for setting up the layout.

Select Search -> Java

 

 

Search for method createInitialLayout

 

 

The system will show you all the occurrence of this method. Select any of the implementations to see how the Layout is defined.

 

 

4.2. Example: Finding standard menu definition

Lets assume you want to find the Eclipse creation of the menus. From your RCP application experience you know that Eclipse creates the menus in the method fillMenuBar.

Open Search -> Java and search for fillMenuBar. Browse through the hit list to see how Eclipse is handling the creation of the menu.

5. Debugging Eclipse

You can also debug the Eclipse IDE if you want to see how certain things are done. Use for example the Plug-in 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 plug-ins and run it.

 

 

 

 

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

 

 

6. Getting the Eclipse source code from cvs

The Eclipse source code is stored in cvs. To checkout the source code open the "CVS Repository" view.

 

 

Maintain the folloiwng.

 

 

Now can you browse the structure and check out code. Check out will create a local copy of the selected path into your workspace.

7. Questions and Discussion

For questions and discussion around this article please use the http://groups.google.com/group/vogella. Also if you note an error in this article please post the error and if possible the correction to the Group.

I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics