Using SearchEngine to scope by package visibility [message #242616] |
Mon, 09 April 2007 18:47  |
Eclipse User |
|
|
|
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 #242657 is a reply to message #242626] |
Tue, 10 April 2007 10:08  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.72134 seconds