Eclipse Source Code Analysis

Source: Internet
Author: User

Eclipse Source Code Analysis

I. Overview
Walk into Eclipse's kernel and see how it works?

1. Eclipse Source Code
: Http://download.eclipse.org/eclipse/downloads

2. Source code reading tool sources Insight V3.5
It is actually a code-editing software, because there are powerful code analysis tools that can easily track the relevance of the code, so often used as a tool to read the code.
: http://sourceinsight.com/down35.html

To facilitate the analysis of the code, we only extract the following plug-in code:
Org.eclipse.platform Org.eclipse.platform_3.1.1.jar
Org.eclipse.core.commands Org.eclipse.core.commands_3.1.0.jar
Org.eclipse.core.expressions Org.eclipse.core.expressions_3.1.0.jar
Org.eclipse.core.runtime Org.eclipse.core.runtime_3.1.1.jar
Org.eclipse.help Org.eclipse.help_3.1.0.jar
Org.eclipse.jface Org.eclipse.jface_3.1.1.jar
Org.eclipse.osgi Org.eclipse.osgi_3.1.1.jar
Org.eclipse.swt.win32.win32.x86 Org.eclipse.swt.win32.win32.x86_3.1.1.jar
ORG.ECLIPSE.SWT Org.eclipse.swt_3.1.0.jar
Org.eclipse.ui.workbench Org.eclipse.ui.workbench_3.1.1.jar
Org.eclipse.ui Org.eclipse.ui_3.1.1.jar
Org.eclipse.update.configurator Org.eclipse.update.configurator_3.1.0.jar

Unzip the code into an empty directory and import it into project in source insight.

Second, the Eclipse startup process
First we start with an analysis of the Eclipse startup process.

1, Eclipse.exe
It is the startup file for Eclipse and is the platform-related executable file. Its function is relatively simple, mainly loading Startup.jar files, code in the Eclipse source code in the/features/org.eclipse.platform.launchers/library directory, corresponding to multiple platforms. For the Win32 platform, you can directly run the BUILD.bat file in the Win32 directory to compile it (you need to install the C compiler).

2, Startup.jar
This is the real launch file for Eclipse, you can run the Java-jar startup.jar command at the command line to start Eclipse. Its entrance is Org.eclipse.core.launcher.Main, which corresponds to the source code in the subdirectory of the ORG.ECLIPSE.PLATFORM/SRC directory Main.java. We trace back from the main function and find Basicrun, which is the main part of the startup.

protected void Basicrun (string[] args) throws Exception {
......
Setupvmproperties (); Setting VM Properties
ProcessConfiguration (); Read the Configuration/config.ini configuration file
......
Need to ensure, getinstalllocation is called at least onCe to initialize the value.
The processing the configuration to the set
The install location.
Getinstalllocation ();

Locate boot plugin (may return-dev mode variations)
url[] Bootpath = Getbootpath (bootlocation);

Setsecuritypolicy (Bootpath); Set execution permissions

Splash handling is do here, because the default case needs to know
The location of the boot plugin we is going to use
Handlesplash (Bootpath);

Invokeframework (Passthruargs, Bootpath); Start the Eclipse kernel
}

The first part of this function is to set some properties, the most critical of which is the last Invokeframework function, which is the core of launching eclipse. Let's look at the specific contents of the Invokeframework function.

private void Invokeframework (string[] Passthruargs, url[] bootpath)
Throws ClassNotFoundException, Nosuchmethodexception, Illegalaccessexception, Error, Exception, invocationtargetexception {
......
URLClassLoader loader = new Startupclassloader (Bootpath, parent);

Class clazz = Loader.loadclass (STARTER); Load
String STARTER = "Org.eclipse.core.runtime.adaptor.EclipseStarter";
method = Clazz.getdeclaredmethod ("Run", new class[] {string[].class, runnable.class}); Get the Run method
......
Method.invoke (Clazz, new object[] {Passthruargs, endsplashhandler}); Call the Run method
......
}

First create the loader loader, which is a urlclassloader type. It then loads the class "Org.eclipse.core.runtime.adaptor.EclipseStarter", obtains its run method, and then calls this method.

3. OSGi Startup
The source code for the "Org.eclipse.core.runtime.adaptor.EclipseStarter" class is located in/plugins/org.eclipse.osgi/eclipseadaptor/src/org/ Eclipse/core/runtime/adaptor. It is visible in the OSGi package, which is the starting class for OSGi.

public static void Startup (string[] args, Runnable endsplashhandler) throws Exception {
......
Adaptor = Createadaptor (); Establishing an Adapter
......
OSGi OSGi = new OSGi (adaptor); Build OSGi objects, that's what we're looking for.
......
Osgi.launch (); Start OSGi
......
context = Osgi.getbundlecontext (); Get the execution context of the loaded bundle
......
bundle[] Startbundles = Loadbasicbundles (); Load Bundles
Setstartlevel (Getstartlevel ()); Setting the startup level
......
}

4. Implementation classes for Eclipse fixed menus (such as project, help, etc.)
The protected void Fillmenubar (Imenumanager MenuBar) method in the Workbenchactionbuilder.java class under the Org.eclipse.ui.internal.ide package, The specific implementation is as follows:

protected void Fillmenubar (Imenumanager menuBar) {
Menubar.add (Createfilemenu ()); Add a File menu to the menu bar
Menubar.add (Createeditmenu ());
Menubar.add (Createnavigatemenu ());
Menubar.add (Createprojectmenu ());
Menubar.add (New Groupmarker (iworkbenchactionconstants.mb_additions));
Menubar.add (Createwindowmenu ());
Menubar.add (Createhelpmenu ());
}

If you want to remove the move item under the File menu, you can note the following statement in the private Menumanager Createfilemenu () method:
Menu.add (moveaction);

Eclipse Source Code Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.