Exemplo n.º 1
0
 public static ISourceLocation findLocation(IPackageFragmentRoot root) throws JavaModelException {
   if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
     IPath path = EclEmmaCorePlugin.getAbsolutePath(root.getPath());
     return new SourceLocation(path, new Path(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH));
   } else {
     IPath path = root.getSourceAttachmentPath();
     if (path != null) {
       path = EclEmmaCorePlugin.getAbsolutePath(path);
       return new SourceLocation(path, root.getSourceAttachmentRootPath());
     } else {
       return null;
     }
   }
 }
  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;
  }