RSS

Search Engine

Saturday, July 10, 2010

Eclipse JDT

1.1. Overview

The Eclipse Java Development Tools (JDT) provide APIs to access and manipulate Java source code. It allows to access the existing projects in the workspace, create new projects and modify and read existing projects. It also allows to launch Java programs.

Java JDT allows to access Java source code via two different means. The Java Model and the Abstract Syntax Tree (AST).

which is a Document Object Model similar to the XML DOM

1.2. Java Model

Each Java project is represented in Eclipse as a Java model. The Eclipse Java model is a light-weight and fault tolerant representation of the Java project. It does not contain as many information as the Abstract Syntax Tree (AST) (for example it does not contain the method body of a method) but is fast to re-created in case of changes. For example the outline view is using the Java model for it representation; this way the information in the outline view can quickly get updated.

The Java model is defined in package and plugin "org.eclipse.jdt.core".

The Java model is represented as a tree structure which can be described via the following table.

Table 1.

Project ElementJava Model elementDescription
Java projectIJavaProjectThe Java project which contains all other objects.
src folder / bin folder / or external libraryIPackageFragmentRoot Hold source or binary files, can be a folder or a library (zip / jar file )
Each packageIPackageFragment Each package is below the IPackageFragmentRoot, sub-packages are not leaves of the package, they are listed directed under IPackageFragmentRoot
Java Source FileICompilationUnitThe Source file is always below the package node
Types / Fields / MethodsIType / IField / IMethodTypes, fields and methods

1.3. Abstract Syntax Tree (AST)

The AST is a detailed tree representation of Java source code. The AST defines API to modify, create, read and delete source code.

The package for AST is org.eclipse.jdt.core.dom in the Eclipse org.eclipse.jdt.core plugin.

Each element in the Java source file is represented as a subclass of ASTNode. Each specific AST node provides specific information about the object it represents. For example you have MethodDeclaration (for methods), VariableDeclarationFragment (for variable declarations) and SimpleName (for any string which is not a Java keyword).

The AST is typically created based on a ICompilationUnit from the Java Model.

0 comments:

Post a Comment