Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » how to programmatically search scope=java.lang.*?
how to programmatically search scope=java.lang.*? [message #52157] Sat, 07 June 2003 03:02 Go to next message
Tom Roche is currently offline Tom RocheFriend
Messages: 160
Registered: July 2009
Senior Member
How can one get a search scope limited to classes within java.lang.*?
Why I ask:

I've got a wizard that at one point allows users to insert <name,
typename> pairs. When written, the typenames must be fully qualified,
even if the class is in java.lang: i.e.

java.lang.String is ok
String is not ok

(Also primitives must be promoted to wrappers, and other stuff.)
It is believed that, most the time, users will be entering classes in
java.lang, so, for usability, I wanna have the ability to allow the user
to enter unqualified typenames, and then resolve them.

I do this now by resolving primitives, then resolving "the usual
suspects" (i.e. what I expect users will wanna enter, e.g. String),
then searching with scope=workspace; at each step, if the unqualified
name resolves, it is returned. But what I'd like to do is resolve the
primitives, then search with scope=java.lang.*, then search with
scope=workspace.

How to do that? I know I can create a search scope with

SearchEngine.createJavaSearchScope(IJavaElement[], boolean)

So what I suspect I need to do is get an IPackageFragment that
"contains" java.lang.*: is this correct?

If so: I suspect the way to do that is to get (presumably from the
current project, to which I have a reference) the IPackageFragmentRoot
that corresponds to the user's JRE, e.g. rt.jar. Is this correct?

If so: how should I do that?

After that, I'm presuming that I can get the desired IPackageFragment
with a simple

thingy.getPackageFragment("java.lang");

or is this also mistaken?

Your assistance would be appreciated, esp if you could CC me when
posting to the list, just for notification purposes. (I will report
the results of any advice to the list, for the benefit of later
searchers.)
Re: how to programmatically search scope=java.lang.*? [message #53784 is a reply to message #52157] Tue, 10 June 2003 12:55 Go to previous message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
Tom,

To get an existing IPackageFragment for 'java.lang', you could use the
following code snippet:

IJavaProject project = ....;
IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
for (int i=0; i < roots.length; i++) {
IPackageFragmentRoot root = roots[i];
IPackageFragment pkg = root.getPackageFragment("java.lang");
if (pkg.exists()) {
return pkg;
}
}

Jerome

"Tom Roche" <tlroche@us.ibm.com> wrote in message
news:bbrkku$6h1$1@rogue.oti.com...
> How can one get a search scope limited to classes within java.lang.*?
> Why I ask:
>
> I've got a wizard that at one point allows users to insert <name,
> typename> pairs. When written, the typenames must be fully qualified,
> even if the class is in java.lang: i.e.
>
> java.lang.String is ok
> String is not ok
>
> (Also primitives must be promoted to wrappers, and other stuff.)
> It is believed that, most the time, users will be entering classes in
> java.lang, so, for usability, I wanna have the ability to allow the user
> to enter unqualified typenames, and then resolve them.
>
> I do this now by resolving primitives, then resolving "the usual
> suspects" (i.e. what I expect users will wanna enter, e.g. String),
> then searching with scope=workspace; at each step, if the unqualified
> name resolves, it is returned. But what I'd like to do is resolve the
> primitives, then search with scope=java.lang.*, then search with
> scope=workspace.
>
> How to do that? I know I can create a search scope with
>
> SearchEngine.createJavaSearchScope(IJavaElement[], boolean)
>
> So what I suspect I need to do is get an IPackageFragment that
> "contains" java.lang.*: is this correct?
>
> If so: I suspect the way to do that is to get (presumably from the
> current project, to which I have a reference) the IPackageFragmentRoot
> that corresponds to the user's JRE, e.g. rt.jar. Is this correct?
>
> If so: how should I do that?
>
> After that, I'm presuming that I can get the desired IPackageFragment
> with a simple
>
> thingy.getPackageFragment("java.lang");
>
> or is this also mistaken?
>
> Your assistance would be appreciated, esp if you could CC me when
> posting to the list, just for notification purposes. (I will report
> the results of any advice to the list, for the benefit of later
> searchers.)
>
Previous Topic:examples-zip incomplete?
Next Topic:cannot start eclipse on RH 8 platform
Goto Forum:
  


Current Time: Sat Aug 17 22:29:29 GMT 2024

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

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

Back to the top