Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] how to create IJavaSearchScope that would include all necessary projectes/libraries?

Sorry, I misunderstood Adam's question. The following code should do what
you want (I haven't tested it though :-)

      public void addReferingProjects(IProject focus, Vector list) throws
JavaModelException {
            IPath path = focus.getProject().getFullPath();
            IProject[] projects = focus.getProject().getReferencingProjects
();
            for (int i = 0, length = projects.length; i < length; i++) {
                  IProject project = projects[i];
                  IJavaProject javaProject = JavaCore.create(project);
                  IClasspathEntry[] classpath = javaProject.getRawClasspath
();
                  for (int j = 0, length2 = classpath.length; j < length2;
j++) {
                        IClasspathEntry entry = classpath[j];
                        if (entry.getEntryKind() ==
IClasspathEntry.CPE_PROJECT
                                    && path.equals(entry.getPath())) {
                              list.add(javaProject);
                              if (entry.isExported()) {
                                    addReferingProjects(javaProject, list);
                              }
                              break;
                        }
                  }
            }
      }

You would call it as follows:

            IJavaProject project = ...;
            Vector list = new Vector();
            list.add(project);
            addReferingProjects(project.getProject(), list);

Jerome


                                                                                                                                              
                      Dirk_Baeumer@xxxxxx                                                                                                     
                      m                           To:      jdt-core-dev@xxxxxxxxxxx                                                           
                      Sent by:                    cc:                                                                                         
                      jdt-core-dev-admin@         Subject: Re: [jdt-core-dev] how to create IJavaSearchScope that would include all necessary 
                      eclipse.org                 projectes/libraries?                                                                        
                                                                                                                                              
                                                                                                                                              
                      03/12/2002 05:02 PM                                                                                                     
                      Please respond to                                                                                                       
                      jdt-core-dev                                                                                                            
                                                                                                                                              
                                                                                                                                              




I don't really see the difference between adding all package fragment roots
of a project and the project itself. What is the benefit ?

To make it more precise. Will your solution work for the following case:

project P0: defines a type T
project P1:
        references project P0 (specified on build path).
        export project P0
        uses type T.
project P2:
        uses type T
        reference project P1. Note project P0 isn't referenced, but T is
visible since P1 exports it.


Building the closure would help but would add to many projects in the
following case:

project P3:
        references P0
project P4:
        references P3

In this constallation P4 can't access type T defined in P0. Therefore P4
doesn't have to be part of the search scope when searching for references
to type T.

So how to we compute the "optimal" search scope in this scenario ?

Dirk


                                                                           
   Jerome_Lanneluc@ot                                                      
   i.com                      To:        jdt-core-dev@xxxxxxxxxxx          
   Sent by:                   cc:                                          
   jdt-core-dev-admin         Subject:        Re: [jdt-core-dev] how to    
   @eclipse.org       create IJavaSearchScope that would include all       
                      necessary projectes/libraries?                       
                                                                           
   12.03.2002 15:22                                                        
   Please respond to                                                       
   jdt-core-dev                                                            
                                                                           





Instead of adding all referencing projects, you could add the package
fragment roots of each referencing project (see
IJavaProject,getPackageFragmentRoots()).

Jerome




                     "Adam Kiezun"

                     <adam.kiezun@xxxxxx         To:
<jdt-core-dev@xxxxxxxxxxx>

                     t>                          cc:

                     Sent by:                    Subject: [jdt-core-dev]
how to create IJavaSearchScope that would include all necessary
                     jdt-core-dev-admin@         projectes/libraries?

                     eclipse.org



                     03/12/2002 02:29 PM

                     Please respond to

                     jdt-core-dev






hi all,
i have an IJavaElement in hand
how do i create a IJavaSearchScope that would include _everything_ that can
possibly have references to that element (and be smaller than workspace
scope)?

i mean, i have code that adds all referencing projects - but that algorithm
is not correct since projects can export some of their classpath entries
(which wasn't true when i wrote it (basically copied Jerome's suggestions -
thanks :))).

could this be implented in jcore?
if not, can you come up with some code that does it correctly?

thx
a.

_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev




_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev







Back to the top