This link has been bookmarked by 33 people . It was first bookmarked on 21 Jul 2007, by cwalltx.
-
19 Apr 16
-
IPackageFragmentRoot: can be a source or a class folder of a project, a.zipor a.jarfile.IPackageFragmentRootcan hold source or binary files.
-
-
29 Oct 14
-
03 Sep 14
-
ICompilationUnitis a pointer to a Java file
-
-
04 Feb 14
-
As mentioned, the Abstract Syntax Tree is the way that Eclipse looks at your source code
-
-
13 Jun 12
-
16 Apr 12
-
13 Jan 12
-
The Abstract Syntax Tree is the base framework for many powerful tools of the Eclipse IDE, including refactoring, Quick Fix and Quick Assist
-
The Abstract Syntax Tree maps plain Java source code in a tree form. This tree is more convenient and reliable to analyse and modify programmatically than text-based source. This article shows how you can use the Abstract Syntax Tree for your own applications.
-
Are you wondering how Eclipse is doing all the magic like jumping conveniently to a declaration, when you press "F3" on a reference to a field or method? Or how "Replace in file" solidly detects the declaration and all the references to the local variable and modifies them synchronously?
-
Well, these—and a big portion of the other source code modification and generation tools—are based upon the Abstract Syntax Tree (AST). The AST is comparable to the DOM tree model of an XML file. Just like with DOM, the AST allows you to modify the tree model and reflects these modifications in the Java source code.
-
This article refers to an example application which covers most of the interesting AST-related topics. Let us have a look at the application that was built to illustrate this article:
-
Removal of unnecessary declaration. If a variable is declared and initialized, only to be overridden by another assignment later on, the first declaration of the variable is an unnecessary declaration.
Move of declaration. If a variable is declared, and not immediately referenced within the following statement, this variable declaration has to be moved. The correct place for the declaration is the line before it is first referenced.
Move of declaration of a variable that is referred to from within different blocks. This is a subcase of case 2. Imagine that a variable is used in both a try- and a catch clause. Here the declaration cannot be moved right before the first reference in the try-clause, since then it would not be declared in the catch-clause. Our application has to deal with that and has to move the declaration to the best possible place, which would be here one line above the try-clause.
According to Java Practices [4], you should not declare local variables before using them. The goal of our application will be to detect contradicting variable declarations and to move them to their correct place. There are three cases our application has to deal with:
-
In Appendix A, Code Fragments for Example Application Cases code snippets to each of these cases are provided.
You can import the example application into your workspace [1] or install the plug-in using the Eclipse Update Manager [2].
-
Java source: To start off, you provide some source code to parse. This source code can be supplied as a Java file in your project or directly as a
char[]that contains Java source -
Parse: The source code described at 1 is parsed. All you need for this step is provided by the class
org.eclipse.jdt.core.dom.ASTParser. See the section called “Parsing source code”. -
-
-
05 Jan 12
-
15 Apr 11
Rodrigo Costaording to Java Practices [4], you should not declare local variables before using them. The goal of our application will be to detect contradicting variable declarations and to move them to their correct place. There are three cases our application has to
-
09 Mar 11
-
21 Dec 10
-
22 Apr 10
-
16 Mar 10
Sven Duzont"The Abstract Syntax Tree is the base framework for many powerful tools of the Eclipse IDE, including refactoring, Quick Fix and Quick Assist. The Abstract Syntax Tree maps plain Java source code in a tree form. This tree is more convenient and reliable to analyse and modify programmatically than text-based source. This article shows how you can use the Abstract Syntax Tree for your own applications."
-
05 Jun 09
-
05 Aug 08
-
02 Aug 08
-
21 Mar 08
-
23 Sep 07
Kim Bo KasteknivThe Abstract Syntax Tree is the base framework for many powerful tools of the Eclipse IDE, including refactoring, Quick Fix and Quick Assist.
-
21 Jul 07
-
25 Jun 07
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.