Eclipse JDT tutorial – Java Model – Concept and Design

This article belongs to Eclipse JDT Tutorial Series.

What is Java Model?

The Java model is the set of classes that model the objects associated with creating, editing, and building a Java program.

It is defined in org.eclipse.jdt.core package. Accordingly, non-API classes are defined in package org.eclipse.jdt.internal.core. You will see their relation in next section.

In the diagram below, a simple project is displayed in the Package Explore view. Each element is mapped to some IJavaElement. All those classes directly or not directly extend IJavaElement class, and there are many other classes other than what are shown in the diagram. If you want to see more, you can go to reference 2 to check out the entire hierarchy.

The Handle/Info Design

Let’s take IJavaElement for example, since it is the common protocol for all elements provided by the Java model. Other Java elements have the same design(e.g. IType, IMethod, etc). Java model elements are exposed to clients as handles to the actual underlying element.

Actually, the design pattern here is a mixture of Proxy and Bridge. Those patterns are not exactly the same as how they are defined. You can follow the links to see what is a canonical implementations of Proxy and Bridge pattern.

The advantage of this design:
1. The handle (IJavaElement) is a key for an element. They define behaviors of each element, but do not keep any state information.
2. An info object stores the element’s state. There is only one implementer (JavaElement) for a handle, so it is a simplified Bridge.

* Eclipse core resources have the similar design.

References:

1. JDT APT Specification

2. Hierarchy For Package org.eclipse.jdt.core

1 thought on “Eclipse JDT tutorial – Java Model – Concept and Design”

Leave a Comment