misc changes in the internal builder
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / builder / IncrementalImageBuilder.java
index 635ac56..ffbe886 100644 (file)
@@ -137,7 +137,7 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
             / allSourceFiles.length);
         increment = increment / 2;
         compile(allSourceFiles);
-        removeSecondaryTypes();
+//        removeSecondaryTypes();
         addAffectedSourceFiles();
       }
       if (this.hasStructuralChanges && javaBuilder.javaProject.hasCycleMarker())
@@ -171,41 +171,41 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
     // if a well known name was found then we can skip over these
     if (simpleNames.length < simpleStrings.size())
       simpleNames = null;
-    Object[] keyTable = newState.references.keyTable;
-    Object[] valueTable = newState.references.valueTable;
-    next : for (int i = 0, l = valueTable.length; i < l; i++) {
-      ReferenceCollection refs = (ReferenceCollection) valueTable[i];
-      if (refs != null && refs.includes(qualifiedNames, simpleNames)) {
-        String typeLocator = (String) keyTable[i];
-        IFile file = javaBuilder.currentProject.getFile(typeLocator);
-        if (file.exists()) {
-          ClasspathMultiDirectory md = sourceLocations[0];
-          if (sourceLocations.length > 1) {
-            IPath sourceFileFullPath = file.getFullPath();
-            for (int j = 0, m = sourceLocations.length; j < m; j++) {
-              if (sourceLocations[j].sourceFolder.getFullPath().isPrefixOf(
-                  sourceFileFullPath)) {
-                md = sourceLocations[j];
-                if (md.exclusionPatterns == null
-                    || !Util.isExcluded(file, md.exclusionPatterns))
-                  break;
-              }
-            }
-          }
-          SourceFile sourceFile = new SourceFile(file, md, encoding);
-          if (sourceFiles.contains(sourceFile))
-            continue next;
-          if (compiledAllAtOnce && previousSourceFiles != null
-              && previousSourceFiles.contains(sourceFile))
-            continue next; // can skip previously compiled files since already
-          // saw hierarchy related problems
-          if (PHPBuilder.DEBUG)
-            System.out.println("  adding affected source file " + typeLocator); //$NON-NLS-1$
-          //                           // update indexfile for the project:
-          sourceFiles.add(sourceFile);
-        }
-      }
-    }
+//    Object[] keyTable = newState.references.keyTable;
+//    Object[] valueTable = newState.references.valueTable;
+//    next : for (int i = 0, l = valueTable.length; i < l; i++) {
+//      ReferenceCollection refs = (ReferenceCollection) valueTable[i];
+//      if (refs != null && refs.includes(qualifiedNames, simpleNames)) {
+//        String typeLocator = (String) keyTable[i];
+//        IFile file = javaBuilder.currentProject.getFile(typeLocator);
+//        if (file.exists()) {
+//          ClasspathMultiDirectory md = sourceLocations[0];
+//          if (sourceLocations.length > 1) {
+//            IPath sourceFileFullPath = file.getFullPath();
+//            for (int j = 0, m = sourceLocations.length; j < m; j++) {
+//              if (sourceLocations[j].sourceFolder.getFullPath().isPrefixOf(
+//                  sourceFileFullPath)) {
+//                md = sourceLocations[j];
+//                if (md.exclusionPatterns == null
+//                    || !Util.isExcluded(file, md.exclusionPatterns))
+//                  break;
+//              }
+//            }
+//          }
+//          SourceFile sourceFile = new SourceFile(file, md, encoding);
+//          if (sourceFiles.contains(sourceFile))
+//            continue next;
+//          if (compiledAllAtOnce && previousSourceFiles != null
+//              && previousSourceFiles.contains(sourceFile))
+//            continue next; // can skip previously compiled files since already
+//          // saw hierarchy related problems
+//          if (PHPBuilder.DEBUG)
+//            System.out.println("  adding affected source file " + typeLocator); //$NON-NLS-1$
+//          //                         // update indexfile for the project:
+//          sourceFiles.add(sourceFile);
+//        }
+//      }
+//    }
   }
   protected void addDependentsOf(IPath path, boolean hasStructuralChanges) {
     if (hasStructuralChanges) {
@@ -292,12 +292,12 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
             if (binaryDelta.getKind() == IResourceDelta.ADDED) {
               // see if any known source file is from the same package...
               // classpath already includes new package
-              if (!newState.isKnownPackage(packageName)) {
-                if (PHPBuilder.DEBUG)
-                  System.out.println("Found added package " + packageName); //$NON-NLS-1$
-                addDependentsOf(packagePath, false);
-                return;
-              }
+//              if (!newState.isKnownPackage(packageName)) {
+//                if (PHPBuilder.DEBUG)
+//                  System.out.println("Found added package " + packageName); //$NON-NLS-1$
+//                addDependentsOf(packagePath, false);
+//                return;
+//              }
               if (PHPBuilder.DEBUG)
                 System.out.println("Skipped dependents of added package "
                     + packageName); //$NON-NLS-1$
@@ -453,37 +453,37 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
                     + typeLocator); //$NON-NLS-1$
               sourceFiles.add(new SourceFile((IFile) resource, md, encoding));
               String typeName = typePath.toString();
-              if (!newState.isDuplicateLocator(typeName, typeLocator)) { // adding
-                // dependents
-                // results
-                // in
-                // 2
-                // duplicate
-                // errors
-                if (PHPBuilder.DEBUG)
-                  System.out.println("Found added source file " + typeName); //$NON-NLS-1$
-                addDependentsOf(typePath, true);
-              }
+//              if (!newState.isDuplicateLocator(typeName, typeLocator)) { // adding
+//                // dependents
+//                // results
+//                // in
+//                // 2
+//                // duplicate
+//                // errors
+//                if (PHPBuilder.DEBUG)
+//                  System.out.println("Found added source file " + typeName); //$NON-NLS-1$
+//                addDependentsOf(typePath, true);
+//              }
               return;
             case IResourceDelta.REMOVED :
-              char[][] definedTypeNames = newState
-                  .getDefinedTypeNamesFor(typeLocator);
-              if (definedTypeNames == null) { // defined a single type matching
-                // typePath
-                removeClassFile(typePath, md.binaryFolder);
-                if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
-                  // remove problems and tasks for a compilation unit that is
-                  // being moved (to another package or renamed)
-                  // if the target file is a compilation unit, the new cu will
-                  // be recompiled
-                  // if the target file is a non-java resource, then markers
-                  // are removed
-                  // see bug 2857
-                  IResource movedFile = javaBuilder.workspaceRoot
-                      .getFile(sourceDelta.getMovedToPath());
-                  PHPBuilder.removeProblemsAndTasksFor(movedFile);
-                }
-              } else {
+//              char[][] definedTypeNames = newState
+//                  .getDefinedTypeNamesFor(typeLocator);
+//              if (definedTypeNames == null) { // defined a single type matching
+//                // typePath
+//                removeClassFile(typePath, md.binaryFolder);
+//                if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
+//                  // remove problems and tasks for a compilation unit that is
+//                  // being moved (to another package or renamed)
+//                  // if the target file is a compilation unit, the new cu will
+//                  // be recompiled
+//                  // if the target file is a non-java resource, then markers
+//                  // are removed
+//                  // see bug 2857
+//                  IResource movedFile = javaBuilder.workspaceRoot
+//                      .getFile(sourceDelta.getMovedToPath());
+//                  PHPBuilder.removeProblemsAndTasksFor(movedFile);
+//                }
+//              } else {
                 if (PHPBuilder.DEBUG)
                   System.out.println("Found removed source file "
                       + typePath.toString()); //$NON-NLS-1$
@@ -491,16 +491,16 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
                 // source file since it may be
                 // involved in a name
                 // collision
-                if (definedTypeNames.length > 0) { // skip it if it failed to
-                  // successfully define a
-                  // type
-                  IPath packagePath = typePath.removeLastSegments(1);
-                  for (int i = 0, l = definedTypeNames.length; i < l; i++)
-                    removeClassFile(packagePath.append(new String(
-                        definedTypeNames[i])), md.binaryFolder);
-                }
-              }
-              newState.removeLocator(typeLocator);
+//                if (definedTypeNames.length > 0) { // skip it if it failed to
+//                  // successfully define a
+//                  // type
+//                  IPath packagePath = typePath.removeLastSegments(1);
+//                  for (int i = 0, l = definedTypeNames.length; i < l; i++)
+//                    removeClassFile(packagePath.append(new String(
+//                        definedTypeNames[i])), md.binaryFolder);
+//                }
+//              }
+//              newState.removeLocator(typeLocator);
               return;
             case IResourceDelta.CHANGED :
               if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0)
@@ -573,73 +573,73 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
   protected void finishedWith(String sourceLocator, CompilationResult result,
       char[] mainTypeName, ArrayList definedTypeNames,
       ArrayList duplicateTypeNames) throws CoreException {
-    char[][] previousTypeNames = newState.getDefinedTypeNamesFor(sourceLocator);
-    if (previousTypeNames == null)
-      previousTypeNames = new char[][]{mainTypeName};
-    IPath packagePath = null;
-    next : for (int i = 0, l = previousTypeNames.length; i < l; i++) {
-      char[] previous = previousTypeNames[i];
-      for (int j = 0, m = definedTypeNames.size(); j < m; j++)
-        if (CharOperation.equals(previous, (char[]) definedTypeNames.get(j)))
-          continue next;
-      SourceFile sourceFile = (SourceFile) result.getCompilationUnit();
-      if (packagePath == null) {
-        int count = sourceFile.sourceLocation.sourceFolder.getFullPath()
-            .segmentCount();
-        packagePath = sourceFile.resource.getFullPath().removeFirstSegments(
-            count).removeLastSegments(1);
-      }
-      if (secondaryTypesToRemove == null)
-        this.secondaryTypesToRemove = new SimpleLookupTable();
-      ArrayList types = (ArrayList) secondaryTypesToRemove
-          .get(sourceFile.sourceLocation.binaryFolder);
-      if (types == null)
-        types = new ArrayList(definedTypeNames.size());
-      types.add(packagePath.append(new String(previous)));
-      secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types);
-    }
+//    char[][] previousTypeNames = newState.getDefinedTypeNamesFor(sourceLocator);
+//    if (previousTypeNames == null)
+//      previousTypeNames = new char[][]{mainTypeName};
+//    IPath packagePath = null;
+//    next : for (int i = 0, l = previousTypeNames.length; i < l; i++) {
+//      char[] previous = previousTypeNames[i];
+//      for (int j = 0, m = definedTypeNames.size(); j < m; j++)
+//        if (CharOperation.equals(previous, (char[]) definedTypeNames.get(j)))
+//          continue next;
+//      SourceFile sourceFile = (SourceFile) result.getCompilationUnit();
+//      if (packagePath == null) {
+//        int count = sourceFile.sourceLocation.sourceFolder.getFullPath()
+//            .segmentCount();
+//        packagePath = sourceFile.resource.getFullPath().removeFirstSegments(
+//            count).removeLastSegments(1);
+//      }
+//      if (secondaryTypesToRemove == null)
+//        this.secondaryTypesToRemove = new SimpleLookupTable();
+//      ArrayList types = (ArrayList) secondaryTypesToRemove
+//          .get(sourceFile.sourceLocation.binaryFolder);
+//      if (types == null)
+//        types = new ArrayList(definedTypeNames.size());
+//      types.add(packagePath.append(new String(previous)));
+//      secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types);
+//    }
     // super.finishedWith(sourceLocator, result, mainTypeName,
     // definedTypeNames, duplicateTypeNames);
   }
-  protected void removeClassFile(IPath typePath, IContainer outputFolder)
-      throws CoreException {
-    if (typePath.lastSegment().indexOf('$') == -1) { // is not a nested type
-      newState.removeQualifiedTypeName(typePath.toString());
-      // add dependents even when the type thinks it does not exist to be on
-      // the safe side
-      if (PHPBuilder.DEBUG)
-        System.out.println("Found removed type " + typePath); //$NON-NLS-1$
-      addDependentsOf(typePath, true); // when member types are removed, their
-      // enclosing type is structurally
-      // changed
-    }
-    IFile classFile = outputFolder.getFile(typePath
-        .addFileExtension(PHPBuilder.CLASS_EXTENSION));
-    if (classFile.exists()) {
-      if (PHPBuilder.DEBUG)
-        System.out.println("Deleting class file of removed type " + typePath); //$NON-NLS-1$
-      classFile.delete(IResource.FORCE, null);
-    }
-  }
-  protected void removeSecondaryTypes() throws CoreException {
-    if (secondaryTypesToRemove != null) { // delayed deleting secondary types
-      // until the end of the compile loop
-      Object[] keyTable = secondaryTypesToRemove.keyTable;
-      Object[] valueTable = secondaryTypesToRemove.valueTable;
-      for (int i = 0, l = keyTable.length; i < l; i++) {
-        IContainer outputFolder = (IContainer) keyTable[i];
-        if (outputFolder != null) {
-          ArrayList paths = (ArrayList) valueTable[i];
-          for (int j = 0, m = paths.size(); j < m; j++)
-            removeClassFile((IPath) paths.get(j), outputFolder);
-        }
-      }
-      this.secondaryTypesToRemove = null;
-      if (previousSourceFiles != null && previousSourceFiles.size() > 1)
-        this.previousSourceFiles = null; // cannot optimize recompile case when
-      // a secondary type is deleted
-    }
-  }
+//  protected void removeClassFile(IPath typePath, IContainer outputFolder)
+//      throws CoreException {
+//    if (typePath.lastSegment().indexOf('$') == -1) { // is not a nested type
+//      newState.removeQualifiedTypeName(typePath.toString());
+//      // add dependents even when the type thinks it does not exist to be on
+//      // the safe side
+//      if (PHPBuilder.DEBUG)
+//        System.out.println("Found removed type " + typePath); //$NON-NLS-1$
+//      addDependentsOf(typePath, true); // when member types are removed, their
+//      // enclosing type is structurally
+//      // changed
+//    }
+//    IFile classFile = outputFolder.getFile(typePath
+//        .addFileExtension(PHPBuilder.CLASS_EXTENSION));
+//    if (classFile.exists()) {
+//      if (PHPBuilder.DEBUG)
+//        System.out.println("Deleting class file of removed type " + typePath); //$NON-NLS-1$
+//      classFile.delete(IResource.FORCE, null);
+//    }
+//  }
+//  protected void removeSecondaryTypes() throws CoreException {
+//    if (secondaryTypesToRemove != null) { // delayed deleting secondary types
+//      // until the end of the compile loop
+//      Object[] keyTable = secondaryTypesToRemove.keyTable;
+//      Object[] valueTable = secondaryTypesToRemove.valueTable;
+//      for (int i = 0, l = keyTable.length; i < l; i++) {
+//        IContainer outputFolder = (IContainer) keyTable[i];
+//        if (outputFolder != null) {
+//          ArrayList paths = (ArrayList) valueTable[i];
+//          for (int j = 0, m = paths.size(); j < m; j++)
+//            removeClassFile((IPath) paths.get(j), outputFolder);
+//        }
+//      }
+//      this.secondaryTypesToRemove = null;
+//      if (previousSourceFiles != null && previousSourceFiles.size() > 1)
+//        this.previousSourceFiles = null; // cannot optimize recompile case when
+//      // a secondary type is deleted
+//    }
+//  }
   protected void resetCollections() {
     previousSourceFiles = sourceFiles.isEmpty()
         ? null