Exemplo n.º 1
0
  /**
   * Returns the first package root for the given java project
   *
   * @param javaProject the project to search in
   * @return the first package root, or null
   */
  @Nullable
  public static IPackageFragmentRoot getSourcePackageRoot(IJavaProject javaProject) {
    IPackageFragmentRoot packageRoot = null;
    List<IPath> sources = BaseProjectHelper.getSourceClasspaths(javaProject);

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    for (IPath path : sources) {
      IResource firstSource = workspace.getRoot().findMember(path);
      if (firstSource != null) {
        packageRoot = javaProject.getPackageFragmentRoot(firstSource);
        if (packageRoot != null) {
          break;
        }
      }
    }
    return packageRoot;
  }