Exemple #1
0
  public static List<ICompilationUnit> collectCompilationUnits(IJavaProject project)
      throws JavaModelException {

    List<ICompilationUnit> result = new ArrayList<ICompilationUnit>();

    IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots();
    for (int i = 0; i < roots.length; ++i) {
      IPackageFragmentRoot root = roots[i];
      if (IPackageFragmentRoot.K_SOURCE == root.getKind()) {
        collectCompilationUnits(result, root);
      }
    }

    return result;
  }
 protected IBinaryType createInfoFromClassFileInJar(Openable classFile) {
   String filePath =
       (((ClassFile) classFile).getType().getFullyQualifiedName('$')).replace('.', '/')
           + SuffixConstants.SUFFIX_STRING_class;
   IPackageFragmentRoot root = classFile.getPackageFragmentRoot();
   IPath path = root.getPath();
   // take the OS path for external jars, and the forward slash path for internal jars
   String rootPath = path.getDevice() == null ? path.toString() : path.toOSString();
   String documentPath = rootPath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + filePath;
   IBinaryType binaryType = (IBinaryType) this.binariesFromIndexMatches.get(documentPath);
   if (binaryType != null) {
     this.infoToHandle.put(binaryType, classFile);
     return binaryType;
   } else {
     return super.createInfoFromClassFileInJar(classFile);
   }
 }
Exemple #3
0
 public static void collectCompilationUnits(
     List<ICompilationUnit> result, IPackageFragmentRoot root) throws JavaModelException {
   IJavaElement[] elements = root.getChildren();
   for (int j = 0; j < elements.length; ++j) {
     IPackageFragment p = (IPackageFragment) elements[j];
     result.addAll(Arrays.asList(p.getCompilationUnits()));
   }
 }
  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;
  }