Exemplo n.º 1
0
  /**
   * Returns whether elements of the given project or jar can see the given focus (an IJavaProject
   * or a JarPackageFragmentRot) either because the focus is part of the project or the jar, or
   * because it is accessible throught the project's classpath
   */
  public static boolean canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) {
    try {
      IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
      IJavaProject project = getJavaProject(projectOrJarPath, model);
      IJavaElement[] focuses = getFocusedElementsAndTypes(pattern, project, null);
      if (focuses.length == 0) return false;
      if (project != null) {
        return canSeeFocus(focuses, (JavaProject) project, null);
      }

      // projectOrJarPath is a jar
      // it can see the focus only if it is on the classpath of a project that can see the focus
      IJavaProject[] allProjects = model.getJavaProjects();
      for (int i = 0, length = allProjects.length; i < length; i++) {
        JavaProject otherProject = (JavaProject) allProjects[i];
        IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath);
        if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
          if (canSeeFocus(focuses, otherProject, null)) {
            return true;
          }
        }
      }
      return false;
    } catch (JavaModelException e) {
      return false;
    }
  }