コード例 #1
0
  private void addProjectSourceContainers(IProject project, ArrayList result) throws CoreException {
    if (project == null || !project.hasNature(JavaCore.NATURE_ID)) return;

    IJavaProject jProject = JavaCore.create(project);
    result.add(JavaRuntime.newProjectRuntimeClasspathEntry(jProject));

    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
      IClasspathEntry entry = entries[i];
      if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IRuntimeClasspathEntry rte = convertClasspathEntry(entry);
        if (rte != null) result.add(rte);
      }
    }
  }
コード例 #2
0
  private ISourceContainer getArchiveSourceContainer(String location) throws JavaModelException {
    IWorkspaceRoot root = PDELaunchingPlugin.getWorkspace().getRoot();
    IFile[] containers = root.findFilesForLocationURI(URIUtil.toURI(location));
    for (int i = 0; i < containers.length; i++) {
      IJavaElement element = JavaCore.create(containers[i]);
      if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot archive = (IPackageFragmentRoot) element;
        IPath path = archive.getSourceAttachmentPath();
        if (path == null || path.segmentCount() == 0) continue;

        IPath rootPath = archive.getSourceAttachmentRootPath();
        boolean detectRootPath = rootPath != null && rootPath.segmentCount() > 0;

        IFile archiveFile = root.getFile(path);
        if (archiveFile.exists()) return new ArchiveSourceContainer(archiveFile, detectRootPath);

        File file = path.toFile();
        if (file.exists())
          return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath);
      }
    }
    return null;
  }