Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Sample JDT code -
Sample JDT code - [message #242782] Thu, 12 April 2007 15:15 Go to next message
jess singh is currently offline jess singhFriend
Messages: 1
Registered: July 2009
Junior Member
Hi All,

I want to be able to programmatically generate equals and hash code methods
for all classes in our domain object model preferably without having to
create a plug in.

Can someone show me an example of getting the workspace root ? The
following snippet fails with "workspace is closed" exception.

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

IProject project = root.getProject("axTest");

IJavaProject javaProject = JavaCore.create(project);


IFolder folder = project.getFolder("src");


//folder.create(true, true, null);

IPackageFragmentRoot srcFolder = javaProject

..getPackageFragmentRoot(folder);

//Assert.assertTrue(srcFolder.exists()); // resource exists and is on

// build

IPackageFragment fragment = srcFolder.createPackageFragment("x.y",

true, null);

String str = "package x.y;" + "\n" + "public class E {" + "\n"

+ "String first;" + "\n" + "}";

ICompilationUnit cu = fragment.createCompilationUnit("E.java", str,

false, null);

IType type = cu.getType("E");

type.createField("String name;", null, true, null);
Re: Sample JDT code - [message #242828 is a reply to message #242782] Fri, 13 April 2007 00:49 Go to previous message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Jess Singh a écrit :
> I want to be able to programmatically generate equals and hash code methods
> for all classes in our domain object model preferably without having to
> create a plug in.
> Can someone show me an example of getting the workspace root ? The
> following snippet fails with "workspace is closed" exception.
Are you running in a headless Eclipse?
--
Olivier
Previous Topic:Batch Compiler Fail On Warnings
Next Topic:Debugging java code invoked from a C++ application
Goto Forum:
  


Current Time: Sun Jun 30 13:43:02 GMT 2024

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

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

Back to the top