Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Use JDT Api in Java Project (not plug-in project)(Is it possible to use the JDT methods to get and modify an ICompilationUnit object without the project being an eclipse plug-in project.)
Use JDT Api in Java Project (not plug-in project) [message #836852] Thu, 05 April 2012 01:04 Go to next message
Benjamin Mechling is currently offline Benjamin MechlingFriend
Messages: 1
Registered: April 2012
Junior Member
My is to be able to
* take source code,
* add instructions to instrument the code for testing purposes, and
* compile and use the instrumented code at runtime.

From what I have been reading in the JDT Programmers Guide, it appears that JDT can do much of job. The problem I am running into at this point is how to create a usable instance of ICompilationUnit. Documentation includes example lines such as the following:
ICompilationUnit unit = ..; // get some compilation unit

From what I understand of the JavaModel structure, an ICompilationUnit is an element of the workspace hierarchy, but attempts to access that hierarchy such as the following seems fail.
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

The answer I have found on the internet so far is that the project must be a plug-in project. Currently the project is not designed as a plug-in but as a standard Java Project.

So finally the question:
Is is possible to get, and/or create, an ICompilationUnit object, or other object useful for purpose, in a standard Java Project?

My level of expertise:
* General OO Programming: Solid understanding of basics
* Java Programming: Fairly inexperienced. More familiar with C#. Some experience with other other c-ish languages as well.
* Eclipse program structure, api, and plugins: Little to none.
Re: Use JDT Api in Java Project (not plug-in project) [message #837079 is a reply to message #836852] Thu, 05 April 2012 08:46 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
You cannot use ICompilationUnit in a standard Java project. It has to be an Eclipse Plugin.
Re: Use JDT Api in Java Project (not plug-in project) [message #837306 is a reply to message #836852] Thu, 05 April 2012 14:03 Go to previous message
Michael Rennie is currently offline Michael RennieFriend
Messages: 67
Registered: July 2009
Location: Canada
If you are wanting to inspect the AST of your source you could instead use org.eclipse.jdt.core.dom.CompilationUnit which you can create using an org.eclipse.jdt.core.dom.ASTParser

Satyam might have some links to better examples of doing this.
Previous Topic:Eclipse Start Up
Next Topic:link with editor package explorer background color
Goto Forum:

Current Time: Thu Apr 19 10:15:49 GMT 2018

Powered by FUDForum. Page generated in 0.01530 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software