Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Using SearchEngine to scope by package visibility
Using SearchEngine to scope by package visibility [message #242616] Mon, 09 April 2007 18:47 Go to next message
Eclipse UserFriend
Originally posted by: konigsberg.at.geemail.dot.com

Let's say I have a file in /Project/src/org/mycompany/foo/descriptor.xml

(src is a source path for Project)

Within descriptor.xml, there are strings that reference Java classes
that can be qualified in one of three ways:

1. Fully qualified (e.g. "org.mycompany.bar.Baz")
2. Qualified as part of the package represented by the local directory
(e.g. "Quux" is the same as "org.mycompany.foo.Quux")
3. An inner class, qualified as part of the package represented by the
local directory (e.g."Quux.InnerClass")

If I create a SearchEngine object using an IJavaSearchScope of
SearchEngine.createWorkspaceScope(), then the search engine will find
items specified as #1 and #2, above. However, it doesn't know how to
find Quux.InnerClass. Since descriptor.xml is in org/mycompany/foo, I'd
like to know if there is a) an easy way to determine that it's in the
folder represented by the "org.mycompany.foo" package. *

I mean, it almost feels like the search engine is overkill. The thing
about all three strings is that they resolve to an object relative to
org.mycompany.foo. I wonder if I should just be using a more direct type
specification. What are your thoughts?

Thanks, Robert

* Besides iterating, myself, through the IJavaProject package fragment
roots.
Re: Using SearchEngine to scope by package visibility [message #242626 is a reply to message #242616] Tue, 10 April 2007 06:50 Go to previous messageGo to next message
Eclipse UserFriend
Robert Konigsberg wrote:
> Let's say I have a file in /Project/src/org/mycompany/foo/descriptor.xml
[...]
> Since descriptor.xml is in org/mycompany/foo, I'd
> like to know if there is a) an easy way to determine that it's in the
> folder represented by the "org.mycompany.foo" package. *

Assuming you have the IFile corresponding to /Project/src/org/mycompany/foo/descriptor.xml,
you can use the following snippet:
IFile descriptorFile = ...
IJavaElement element = JavaCore.create(descriptorFile.getParent());
return element.getElementType() == IJavaElement.PACKAGE_FRAGMENT;

Jerome
Re: Using SearchEngine to scope by package visibility [message #242657 is a reply to message #242626] Tue, 10 April 2007 10:08 Go to previous message
Eclipse UserFriend
Originally posted by: konigsberg.at.geemail.dot.com

Oohhh... sweet. Thanks!

Jerome Lanneluc wrote:
> Robert Konigsberg wrote:
>
>> Let's say I have a file in /Project/src/org/mycompany/foo/descriptor.xml
>
> [...]
> > Since descriptor.xml is in org/mycompany/foo, I'd
>
>> like to know if there is a) an easy way to determine that it's in the
>> folder represented by the "org.mycompany.foo" package. *
>
>
> Assuming you have the IFile corresponding to
> /Project/src/org/mycompany/foo/descriptor.xml,
> you can use the following snippet:
> IFile descriptorFile = ...
> IJavaElement element = JavaCore.create(descriptorFile.getParent());
> return element.getElementType() == IJavaElement.PACKAGE_FRAGMENT;
>
> Jerome
Previous Topic:Outline View
Next Topic:Getting comments between firstLeadingCommentIndex and lastTrailingCommentIndex
Goto Forum:
  


Current Time: Thu Jul 17 03:49:51 EDT 2025

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

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

Back to the top