Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
University College London Gower Street London WC1E 6BT 
Tel: +44 (0)20 7679 4413 (Direct Dial)  Fax: +44 (0)20 7387 1397 
www.cs.ucl.ac.uk/staff/W.Emmerich 
w.emmerich@cs.ucl.ac.uk 
UCL DEPARTMENT OF COMPUTER SCIENCE 
 
 
Wolfgang Emmerich, Dr rer-nat, CEng, MIEE 
Professor of Distributed Computing 
Director of Research 
 
 
 
 
  GS04: Tools and Environments 
 
Lab Session 2: Manipulating Java ASTs using Eclipse JDT 
 
The aim of this lab session is to explore how abstract syntax trees are used in modern interactive 
development environments and to apply the principles we have discussed about abstract syntax trees in 
practice using the Eclipse platform. 
 
To gain experience with the Eclipse API contained in JDT for manipulating Java ASTs we will write an 
Eclipse plug-in that calculates the following metrics: 
 
• Number of classes in the package 
• Average number of methods per class 
• Average number of fields per class 
• Average ratio of private and public methods per class 
• Maximum depth of the inheritance tree. 
 
Getting started 
 
Download the Eclipse plug-in source for a very rudimentary metrics plug-in from the course web page at 
http://www.cs.ucl.ac.uk/staff/w.emmerich/lectures/GS04-0708. Use this source to create a new Eclipse plug-
in project. The plug-in as you have downloaded it already calculates the number of classes in a package. 
You now need to extend it to calculate the remaining five metrics.  
 
Creating the User Interface 
 
Create new menu entries in the “Metrics” Menu. You can do this by extending the plugin.xml file that 
describes the plugin. Create new a new command handler class for each of your new commands. Test your 
user interface before you move on to the next task. 
 
Extending the Metrics Engine 
 
Now consider the API in package eclipse.org.jdt.core that you can use for accessing ASTs. It’s Java API 
documentation is available from http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jdt.doc.isv 
 
Now extend the class MetricsCalculator to create the remaining metrics. Write one method per metric 
required above. Then call the metrics calculations from your command handlers.  
 
Testing 
 
For this lab session, we will need a number of abstract syntax trees as test data. To obtain them, create an 
Eclipse project called gz04CW using the test data that is available on the course web page at 
http://www.cs.ucl.ac.uk/staff/w.emmerich/lectures/GS04-0708