*******************************************************************************/
package net.sourceforge.phpdt.internal.core.builder;
import java.util.ArrayList;
-import net.sourceforge.phpdt.core.compiler.CharOperation;
+
import net.sourceforge.phpdt.core.compiler.IProblem;
import net.sourceforge.phpdt.internal.compiler.CompilationResult;
-import net.sourceforge.phpdt.internal.core.Util;
import net.sourceforge.phpdt.internal.core.util.SimpleLookupTable;
+import net.sourceforge.phpdt.internal.core.util.Util;
import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
-import org.eclipse.core.resources.IContainer;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
notifier.subTask(Util.bind("build.analyzingDeltas")); //$NON-NLS-1$
IResourceDelta sourceDelta = (IResourceDelta) deltas
.get(javaBuilder.currentProject);
- if (sourceDelta != null)
+ if (sourceDelta != null) {
+ sourceDelta.accept(new ParserVisitor(javaBuilder.currentProject, notifier.monitor));
+
if (!findSourceFiles(sourceDelta))
return false;
- notifier.updateProgressDelta(0.10f);
- Object[] keyTable = deltas.keyTable;
- Object[] valueTable = deltas.valueTable;
- final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault()
- .getIndexManager(javaBuilder.currentProject);
- for (int i = 0, l = valueTable.length; i < l; i++) {
- IResourceDelta delta = (IResourceDelta) valueTable[i];
- if (delta != null) {
- IResource resource = delta.getResource();
- int resourceType = resource.getType();
- if (resourceType == IResource.FILE) {
- switch (delta.getKind()) {
- case IResourceDelta.ADDED :
- if ((resource.getFileExtension() != null)
- && PHPFileUtil.isPHPFile((IFile) resource)) {
- // update indexfile for the project:
- indexManager.addFile((IFile) resource);
- }
- break;
- case IResourceDelta.CHANGED :
- if ((resource.getFileExtension() != null)
- && PHPFileUtil.isPHPFile((IFile) resource)) {
- // update indexfile for the project:
- indexManager.changeFile((IFile) resource);
- }
- break;
- case IResourceDelta.REMOVED :
- if ((resource.getFileExtension() != null)
- && PHPFileUtil.isPHPFile((IFile) resource)) {
- // update indexfile for the project:
- indexManager.removeFile((IFile) resource);
- }
- break;
- }
- }
- // ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[])
- // javaBuilder.binaryLocationsPerProject.get(keyTable[i]);
- // if (classFoldersAndJars != null)
- // if (!findAffectedSourceFiles(delta, classFoldersAndJars)) return
- // false;
- }
}
notifier.updateProgressDelta(0.10f);
+// Object[] keyTable = deltas.keyTable;
+// Object[] valueTable = deltas.valueTable;
+//// final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault()
+//// .getIndexManager(javaBuilder.currentProject);
+// for (int i = 0, l = valueTable.length; i < l; i++) {
+// IResourceDelta delta = (IResourceDelta) valueTable[i];
+// if (delta != null) {
+// IResource resource = delta.getResource();
+// int resourceType = resource.getType();
+// if (resourceType == IResource.FILE) {
+// switch (delta.getKind()) {
+// case IResourceDelta.ADDED :
+// if ((resource.getFileExtension() != null)
+// && PHPFileUtil.isPHPFile((IFile) resource)) {
+// // update indexfile for the project:
+//// indexManager.addFile((IFile) resource);
+// }
+// break;
+// case IResourceDelta.CHANGED :
+// if ((resource.getFileExtension() != null)
+// && PHPFileUtil.isPHPFile((IFile) resource)) {
+// // update indexfile for the project:
+//// indexManager.changeFile((IFile) resource);
+// }
+// break;
+// case IResourceDelta.REMOVED :
+// if ((resource.getFileExtension() != null)
+// && PHPFileUtil.isPHPFile((IFile) resource)) {
+// // update indexfile for the project:
+//// indexManager.removeFile((IFile) resource);
+// }
+// break;
+// }
+// }
+// // ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[])
+// // javaBuilder.binaryLocationsPerProject.get(keyTable[i]);
+// // if (classFoldersAndJars != null)
+// // if (!findAffectedSourceFiles(delta, classFoldersAndJars)) return
+// // false;
+// }
+// }
+ notifier.updateProgressDelta(0.10f);
notifier.subTask(Util.bind("build.analyzingSources")); //$NON-NLS-1$
addAffectedSourceFiles();
notifier.updateProgressDelta(0.05f);
/ allSourceFiles.length);
increment = increment / 2;
compile(allSourceFiles);
- removeSecondaryTypes();
+// removeSecondaryTypes();
addAffectedSourceFiles();
}
if (this.hasStructuralChanges && javaBuilder.javaProject.hasCycleMarker())
return;
// the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are
// just 'X'
- char[][][] qualifiedNames = ReferenceCollection
- .internQualifiedNames(qualifiedStrings);
+// char[][][] qualifiedNames = ReferenceCollection
+// .internQualifiedNames(qualifiedStrings);
// if a well known qualified name was found then we can skip over these
- if (qualifiedNames.length < qualifiedStrings.size())
- qualifiedNames = null;
- char[][] simpleNames = ReferenceCollection.internSimpleNames(simpleStrings);
+// if (qualifiedNames.length < qualifiedStrings.size())
+// qualifiedNames = null;
+// char[][] simpleNames = ReferenceCollection.internSimpleNames(simpleStrings);
// 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);
- }
- }
- }
+// 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);
+// }
+// }
+// }
}
protected void addDependentsOf(IPath path, boolean hasStructuralChanges) {
if (hasStructuralChanges) {
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$
return;
case IResource.FILE :
String resourceName = resource.getName();
- if (Util.isJavaFileName(resourceName)) {
+ if (net.sourceforge.phpdt.internal.compiler.util.Util.isJavaFileName(resourceName)) {
IPath typePath = resource.getFullPath().removeFirstSegments(
segmentCount).removeFileExtension();
String typeLocator = resource.getProjectRelativePath().toString();
+ 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$
// 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)
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