Ejemplo n.º 1
0
  /**
   * Returns the reason for why the Javadoc of the Java element could not be retrieved.
   *
   * @param element whose Javadoc could not be retrieved
   * @param root the root of the Java element
   * @return the String message for why the Javadoc could not be retrieved for the Java element or
   *     <code>null</code> if the Java element is from a source container
   * @since 3.9
   */
  public static String getExplanationForMissingJavadoc(
      IJavaElement element, IPackageFragmentRoot root) {
    String message = null;
    try {
      boolean isBinary = (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY);
      if (isBinary) {
        boolean hasAttachedJavadoc = JavaDocLocations.getJavadocBaseLocation(element) != null;
        boolean hasAttachedSource = root.getSourceAttachmentPath() != null;
        IOpenable openable = element.getOpenable();
        boolean hasSource = openable.getBuffer() != null;

        // Provide hint why there's no Java doc
        if (!hasAttachedSource && !hasAttachedJavadoc)
          message = CorextMessages.JavaDocLocations_noAttachments;
        else if (!hasAttachedJavadoc && !hasSource)
          message = CorextMessages.JavaDocLocations_noAttachedJavadoc;
        else if (!hasAttachedSource) message = CorextMessages.JavaDocLocations_noAttachedSource;
        else if (!hasSource) message = CorextMessages.JavaDocLocations_noInformation;
      }
    } catch (JavaModelException e) {
      message = CorextMessages.JavaDocLocations_error_gettingJavadoc;
      JavaPlugin.log(e);
    }
    return message;
  }
Ejemplo n.º 2
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;
  }