Using Eclipse

This document does not intend to replace Eclipse's official documentation. This document is purposed to provide new Haystack developers with enough background on Eclipse to become sufficiently productive in exploring and contributing to the Haystack codebase.

Introduction

Eclipse is a development platform onto which many tools can be installed. One set of tools useful for our purpose is the Java Development Toolkit (JDT). JDT comes with Eclipse by default and is the set of tools that you will find useful for dealing with Haystack's codebase. This document focuses mainly on JDT.

Downloading and Installing

Eclipse comes as a zip file. When you get Eclipse for the first time, download it from here. Once you have downloaded the zip file, extract its contents to a folder. Eclipse can then be run by invoking the executable named eclipse.exe in the eclipse directory.

Subsequent updates should be done using Eclipse itself through the menu Help -> Software Updates.

Workspaces

You will find under the eclipse directory a subdirectory named workspace. This is where information about the default workspace is stored. You will find under workspace a subdirectory called .metadata, which stores the workspace's metadata, and zero or more subdirectories storing projects.

A workspace is just a directory in which there is a subdirectory named .metadata whose contents are understood and managed by Eclipse. You can create a new workspace by pointing Eclipse to a different directory using the command line argument -data:

F:\eclipse\eclipse.exe -data F:\dev\myWorkspaces

There is no UI exposed inside Eclipse itself for creating, opening, or saving workspace. Each running instance of Eclipse is bound to only one workspace.

Projects

Each workspace can contain zero or more projects. Each project can be closed or opened. In the following figure, the Navigator view shows two opened projects: Haystack and web

Use the context menu on a project icon to open or close the project. Opened projects take memory but expose to you all of its resources (e.g. files, Java classes).

Perspectives

One of the fundamental UI concepts in Eclipse is perspective. Whether this is a good concept or not is debatable. However, I have noticed that newcomers to Eclipse can be easily confused by perspectives. You can think of a perspective as a configuration of the main Eclipse window with regards to how various tools are arranged. For instance, while you are writing Java code, you might want a tool that permanently displays Javadoc next to your code editor; and while you are debugging, you probably want a tool for inspecting values of variables.

Different perspectives allow you to inspect the same workspace in different ways, each suitable for some particular scenarios. Each perspective includes, among many things, the information about the UI is laid out and which tools are available in the menu and toolbar. If you are in the wrong perspective, you might not find the tools you want.

Opened perspectives are shown in the left hand side of the Eclipse window. The following figure shows 2 opened perspectives: Java and Resource. The Resource perspective is currently selected.

Perspectives are predefined. You can only open and close them; you cannot create a new perspectives. However, you can customize an existing perspective by rearranging the UI.

To open a perspective, go to Window -> Open Perspective or use the first icon on the Perspective bar on the left hand side. Use the context menu on a perspective icon on the Perspective bar to close the perspective. Note that Eclipse might automatically open and switch to a different perspective. If you can't find a tool you need, check the Perspective bar to see if you are in the right perspective.

The Java perspective is probably the one you use most often when dealing with the Haystack codebase.

Full documentation for Eclipse's UI can be found here. Select the main topic called Workbench User Guide. "Workbench" refers to Eclipse's UI platform.

The Java Perspective

When you create a Java project in Eclipse, Eclipse automatically opens the Java perspective for you. This perspective offers several useful views, which are discussed below.

Views in Eclipse are like dockable tool windows elsewhere--they can be docked and stacked like tabs. Each view can be put into any perspective. However, each perspective comes with a predefined set of views.

Package Explorer

The Package Explorer view (below) shows Java files according to their packages. It also shows file folders in the project (e.g. documents in the figure below), as well as Java project specific details such as referenced JAR files (e.g. JRE System Library [jdk]).

Java classes and packages have their icons decorated with error and warning indications in the Package Explorer view. These decorations give you an overview of the compile-ability of the codebase.

You might find it useful to customize the Package Explorer view. For example, you can tell it to flatten Java packages (see below) by invoking the view's dropdown menu and select Layout -> Flat. You can also tell the Package Explorer view to filter out certain items (such as JAR files or CVS directories) by invoking the same dropdown menu and choose Filters.... The Link With Editor toggle command tells the view to sync its selection with the editor in focus.

Outline

The Outline view (below) shows the outline structure of whichever file being edited. The icons in this view also indicates errors and warnings.

Java Code Editor

The Java code editor (below) supports syntax highlighting and content completion. It also highlights errors and warnings as you type, and suggests ways for you to fix them. Only problems displayed with lightbulbs are fixable. To fix a problem, click on the lightbulb icon or alternatively, position your cursor on the same line as the problem and invoke the Quick Fix command (in the Edit menu).

Note that the problems are indicated both on the left margin and the right margin of the editor. Indicators on the right margin illustrate the locations of the problems with respect to the area of the file scrolled into view.

Things I Find Useful

  1. Command completion: available whenever you type "." or by invoking the Content Assist command in the Edit menu (shortcut key: Ctrl-Space).
  2. Parameter hints: available whenever you type "(" or by invoking the Parameter Hints command in the Edit menu (shortcut key: Ctrl-Shift-Space).
  3. Quick Fix: discussed above (shortcut key: Ctrl-1).
  4. Browse to a Java class: quickly go to a Java class by typing just enough of its class name (rather than its full package path); available by invoking the Open Type... command in the Navigate menu (shortcut key: Ctrl-Shift-T). You can also do wildcard search.
  5. Browse to a file: quickly go to a file by typing just enough of its file name (rather than its full file path); available by invoking the Open Type... command in the Navigate menu (shortcut key: Ctrl-Shift-T). You can also do wildcard search.
  6. Go to the declaration of a Java item: position your cursor on a variable name, a class name, or a method name inside a Java editor and invoke the Open Declaration command in the Navigate menu (shortcut key: F3).
  7. Typing down on the Outline: invoke the Show Outline command in the Navigate menu (shortcut key: Ctrl-O).
  8. Navigation history: You can browse backward and forward in Eclipse just like in a browser. Use the toolbar command buttons that look like the left and right arrows
  9. Refactor: A extremely useful feature of JDT is refactoring. Use the Refactor menu or just right click on the class, method, or variable that you want to rename or move in the Package Explorer view or the Outline view (below). You can also use drag and drop for moving Java classes between packages.

  10. Filling in unimplemented methods: Eclipse can automatically generate stubs for unimplemented methods when you derive a class from an abstract class or an interface. In the following code example:

    Reader r = new Reader()

    put the cursor in between the parenthesis and invoke the Content Assist command in the Edit menu (shortcut key: Ctrl-Space).
  11. Catching exceptions: Similarly, Eclipse can automatically wrap your code in try catch blocks.

Miscellaneous

Several plugins for Eclipse can be found here.