protected void addDependentsOf(
      IPath path,
      boolean isStructuralChange,
      StringSet qualifiedNames,
      StringSet simpleNames,
      StringSet rootNames) {
    path = path.setDevice(null);
    if (isStructuralChange) {
      String last = path.lastSegment();
      if (last.length() == TypeConstants.PACKAGE_INFO_NAME.length)
        if (CharOperation.equals(last.toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) {
          path =
              path.removeLastSegments(
                  1); // the package-info file has changed so blame the package itself
          /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785, in the case of default package,
            there is no need to blame the package itself as there can be no annotations or documentation
            comment tags in the package-info file that can influence the rest of the package. Just bail out
            so we don't touch null objects below.
          */
          if (path.isEmpty()) return;
        }
    }

    if (isStructuralChange && !this.hasStructuralChanges) {
      this.newState.tagAsStructurallyChanged();
      this.hasStructuralChanges = true;
    }
    // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X'
    rootNames.add(path.segment(0));
    String packageName = path.removeLastSegments(1).toString();
    boolean wasNew = qualifiedNames.add(packageName);
    String typeName = path.lastSegment();
    int memberIndex = typeName.indexOf('$');
    if (memberIndex > 0) typeName = typeName.substring(0, memberIndex);
    wasNew = simpleNames.add(typeName) | wasNew;
    if (wasNew && JavaBuilder.DEBUG)
      System.out.println(
          "  will look for dependents of " //$NON-NLS-1$
              + typeName
              + " in "
              + packageName); //$NON-NLS-1$
  }
  protected void addAffectedSourceFiles(
      StringSet qualifiedSet, StringSet simpleSet, StringSet rootSet, StringSet affectedTypes) {
    // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X'
    char[][][] internedQualifiedNames = ReferenceCollection.internQualifiedNames(qualifiedSet);
    // if a well known qualified name was found then we can skip over these
    if (internedQualifiedNames.length < qualifiedSet.elementSize) internedQualifiedNames = null;
    char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(simpleSet, true);
    // if a well known name was found then we can skip over these
    if (internedSimpleNames.length < simpleSet.elementSize) internedSimpleNames = null;
    char[][] internedRootNames = ReferenceCollection.internSimpleNames(rootSet, false);

    Object[] keyTable = this.newState.references.keyTable;
    Object[] valueTable = this.newState.references.valueTable;
    next:
    for (int i = 0, l = valueTable.length; i < l; i++) {
      String typeLocator = (String) keyTable[i];
      if (typeLocator != null) {
        if (affectedTypes != null && !affectedTypes.includes(typeLocator)) continue next;
        ReferenceCollection refs = (ReferenceCollection) valueTable[i];
        if (refs.includes(internedQualifiedNames, internedSimpleNames, internedRootNames)) {
          IFile file = this.javaBuilder.currentProject.getFile(typeLocator);
          SourceFile sourceFile = findSourceFile(file, true);
          if (sourceFile == null) continue next;
          if (this.sourceFiles.contains(sourceFile)) continue next;
          if (this.compiledAllAtOnce
              && this.previousSourceFiles != null
              && this.previousSourceFiles.contains(sourceFile))
            continue next; // can skip previously compiled files since already saw hierarchy related
          // problems

          if (JavaBuilder.DEBUG)
            System.out.println("  adding affected source file " + typeLocator); // $NON-NLS-1$
          this.sourceFiles.add(sourceFile);
        }
      }
    }
  }
 protected void findAffectedSourceFiles(
     IResourceDelta binaryDelta, int segmentCount, StringSet structurallyChangedTypes) {
   // When a package becomes a type or vice versa, expect 2 deltas,
   // one on the folder & one on the class file
   IResource resource = binaryDelta.getResource();
   switch (resource.getType()) {
     case IResource.FOLDER:
       switch (binaryDelta.getKind()) {
         case IResourceDelta.ADDED:
         case IResourceDelta.REMOVED:
           IPath packagePath = resource.getFullPath().removeFirstSegments(segmentCount);
           String packageName = packagePath.toString();
           if (binaryDelta.getKind() == IResourceDelta.ADDED) {
             // see if any known source file is from the same package... classpath already includes
             // new package
             if (!this.newState.isKnownPackage(packageName)) {
               if (JavaBuilder.DEBUG)
                 System.out.println("Found added package " + packageName); // $NON-NLS-1$
               addDependentsOf(packagePath, false);
               return;
             }
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "Skipped dependents of added package " + packageName); // $NON-NLS-1$
           } else {
             // see if the package still exists on the classpath
             if (!this.nameEnvironment.isPackage(packageName)) {
               if (JavaBuilder.DEBUG)
                 System.out.println("Found removed package " + packageName); // $NON-NLS-1$
               addDependentsOf(packagePath, false);
               return;
             }
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "Skipped dependents of removed package " + packageName); // $NON-NLS-1$
           }
           // $FALL-THROUGH$ traverse the sub-packages and .class files
         case IResourceDelta.CHANGED:
           IResourceDelta[] children = binaryDelta.getAffectedChildren();
           for (int i = 0, l = children.length; i < l; i++)
             findAffectedSourceFiles(children[i], segmentCount, structurallyChangedTypes);
       }
       return;
     case IResource.FILE:
       if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) {
         IPath typePath =
             resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
         switch (binaryDelta.getKind()) {
           case IResourceDelta.ADDED:
           case IResourceDelta.REMOVED:
             if (JavaBuilder.DEBUG)
               System.out.println("Found added/removed class file " + typePath); // $NON-NLS-1$
             addDependentsOf(typePath, false);
             return;
           case IResourceDelta.CHANGED:
             if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0)
               return; // skip it since it really isn't changed
             if (structurallyChangedTypes != null
                 && !structurallyChangedTypes.includes(typePath.toString()))
               return; // skip since it wasn't a structural change
             if (JavaBuilder.DEBUG)
               System.out.println("Found changed class file " + typePath); // $NON-NLS-1$
             addDependentsOf(typePath, false);
         }
         return;
       }
   }
 }