Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] How to open existing java package (source code) programatically?

Hi Stephan,

Thanks for your reply. I think your guesses are correct. I finally managed to get it working by creating a new ICompilationUnit and populating it with the original source file's content. Not an elegant solution, but it worked! Now having gone though the API docs several times, I saw that IClasspathEntry CPE_SOURCE is for "Source code in the current project". My src package was not in the current project so that may have caused the problem.

Having said that, is there a way to import the sources (a set of java packages) into the current project? I'm currently creating ICompilationUnits for each source file I want to analyze. Or better yet, will I be able to create IClasspathEntries for it by using a reletive path that goes "out" of the workspace dir (eg: "../../../srcdir/")


Thanks,
Tharaka

PS: Sorry for posting to the wrong list. I thought all development questions go to this list and eclipse.tools.jdt is only for user level questions. I'll post my next quetions in eclipse.tools.jdt list.




----------------------------------------------------------------------

Message: 1
Date: Sat, 11 Apr 2009 15:46:31 +0200
From: Stephan Herrmann <stephan@xxxxxxxxxxxxxxx>
Subject: Re: [jdt-core-dev] How to open existing java package (source
       code)   programatically?
To: "Eclipse JDT Core developers list." <jdt-core-dev@xxxxxxxxxxx>
Message-ID: <200904111546.31467.stephan@xxxxxxxxxxxxxxx>
Content-Type: text/plain;  charset="utf-8"

Hi Tharaka,

I suppose this is the kind of question that should rather be asked
in the news group (eclipse.tools.jdt), quoting Daniel Megert from
a recent post:
 "Please use the newsgroup for such questions. This list is reserved for the
 developers of JDT Core itself."

That said, from a brief look at your code you seem to be happily mixing
paths in the file system and paths in the workspace. If cmdArgs[0] is
the absolute filesystem path to the project, these lines look bogus:

 Path dir = new Path(cmdArgs[0]);
 ..
 IClasspathEntry cp = JavaCore.newSourceEntry(dir);

newSourceEntry expects a "workspace-relative path". Similarly this line:

 IPackageFragmentRoot srcRoot = javaProj.getPackageFragmentRoot(cmdArgs[0]);

should probably better use a relative path, too.
Anyway, that's what the workspace is for in the first place:
abstracting from the physical file system!

But these are just a few quick guesses.

Stephan




Back to the top