Difference between PsiClass.getResolveScope and PsiClass.getUseScope

The context is that I need to locate a class by fqn. I have a psiclass already so I am doing

.
Which of the getXXXScope should I use (both classes, the one I have and the one I want, do not have anything in common).

Thanks

Jacques

5 comments
Comment actions Permalink

This actually depends on what you want. There can be many classes with this
FQ name (in different modules and libraries). There should be a way to
choose one. A popular task is to find what this FQ-class name means in
particular "context" (e.g. given file). Is it something like you actually
need?

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

"Jacques Morel" <jacmorel@yahoo.com> wrote in message
news:31326260.1065019552419.JavaMail.itn@is.intellij.net...

The context is that I need to locate a class by fqn. I have a psiclass

already so I am doing


.
Which of the getXXXScope should I use (both classes, the one I have and

the one I want, do not have anything in common).
>

Thanks

>

Jacques



0
Comment actions Permalink

I need to find out if a class is a junit.framework.TestCase.

Should I use


or


and if you could tell us a little bit of the why it would be great

Jacques

0
Comment actions Permalink

Jacques Morel wrote:

I need to find out if a class is a junit.framework.TestCase.

Should I use

 psiClass.getManager().findClass("junit.framework.TestCase",
> psiClass.*getUseScope()*)
> ]]>


or

 psiClass.getManager().findClass("junit.framework.TestCase",
> psiClass.*getResolveScope()*)
> ]]>


You need a resolve scope here.


and if you could tell us a little bit of the why it would be great


The notion of resolve scope came into being with new multi-module support.
The problem is that PSI is per-project in IDEA, but different modules
require different class paths. Class path is abstracted by a
GlobalSearchScope. PsiElement.getResolveScope() gives you a "class path" in
which to search classes in the context of this PsiElement. All references
to classes that are in that PsiElement will be resolved in its resolve
scope. (for example, if your PsiElement is part of source of some module,
its resolve scope will include this module, all its libraries, and all
modules from which it depends)

Use scope is a "dual notion": it is a scope where this PsiElement can
potentially be used. This is what PsiSearchHelper.findReferences() uses.
If you PsiElement is part of a source of some module, its use scope includes
this module and all modules that depend from it.

Friendly,
Dmitry


--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

I need to find out if a class is a junit.framework.TestCase.


Why not use


?

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"



"Jacques Morel" <jacmorel@yahoo.com> wrote in message
news:24158493.1065218595926.JavaMail.itn@is.intellij.net...

I need to find out if a class is a junit.framework.TestCase.

>

Should I use

 psiClass.getManager().findClass("junit.framework.TestCase",
psiClass.*getUseScope()*)
> ]]>

>

or

>

 psiClass.getManager().findClass("junit.framework.TestCase",
psiClass.*getResolveScope()*)
> ]]>

>

and if you could tell us a little bit of the why it would be great

>

Jacques



0
Comment actions Permalink

If that could be that simple ;)

When I say I want to find out if a class is a TestCase I really mean IS-A. I need to find out if a class derives from TestCase.

Thanks for the answer though. From what Dmitry has said and my own testing I use the useScope.

Now I have another question though. I am trying to find what tests are calling a method. If I do it the stupid way by creating a project scope and search for references it takes ages on a large project (6K classes).
Outside of limiting the scope is there any way to speed up the search?

Jacques

0

Please sign in to leave a comment.