예제 #1
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 String getValue(Object[] objects) {
   StringBuffer buffer = new StringBuffer();
   for (Object object : objects) {
     IPackageFragment fragment = (IPackageFragment) object;
     if (buffer.length() > 0)
       buffer.append("," + getLineDelimiter() + " "); // $NON-NLS-1$ //$NON-NLS-2$
     buffer.append(fragment.getElementName());
   }
   return buffer.toString();
 }
  /**
   * Returns the children of <code>source</code> which are affected by this operation. If <code>
   * source</code> is a <code>K_SOURCE</code>, these are the <code>.java</code> files, if it is a
   * <code>K_BINARY</code>, they are the <code>.class</code> files.
   */
  private IResource[] collectResourcesOfInterest(IPackageFragment source)
      throws JavaModelException {
    IJavaElement[] children = source.getChildren();
    int childOfInterest = IJavaElement.COMPILATION_UNIT;
    if (source.getKind() == IPackageFragmentRoot.K_BINARY) {
      childOfInterest = IJavaElement.CLASS_FILE;
    }
    ArrayList correctKindChildren = new ArrayList(children.length);
    for (int i = 0; i < children.length; i++) {
      IJavaElement child = children[i];
      if (child.getElementType() == childOfInterest) {
        correctKindChildren.add(((JavaElement) child).resource());
      }
    }
    // Gather non-java resources
    Object[] nonJavaResources = source.getNonJavaResources();
    int actualNonJavaResourceCount = 0;
    for (int i = 0, max = nonJavaResources.length; i < max; i++) {
      if (nonJavaResources[i] instanceof IResource) actualNonJavaResourceCount++;
    }
    IResource[] actualNonJavaResources = new IResource[actualNonJavaResourceCount];
    for (int i = 0, max = nonJavaResources.length, index = 0; i < max; i++) {
      if (nonJavaResources[i] instanceof IResource)
        actualNonJavaResources[index++] = (IResource) nonJavaResources[i];
    }

    if (actualNonJavaResourceCount != 0) {
      int correctKindChildrenSize = correctKindChildren.size();
      IResource[] result = new IResource[correctKindChildrenSize + actualNonJavaResourceCount];
      correctKindChildren.toArray(result);
      System.arraycopy(
          actualNonJavaResources, 0, result, correctKindChildrenSize, actualNonJavaResourceCount);
      return result;
    } else {
      IResource[] result = new IResource[correctKindChildren.size()];
      correctKindChildren.toArray(result);
      return result;
    }
  }