Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Johnson2006-06-14 14:52:13 +0000
committerKent Johnson2006-06-14 14:52:13 +0000
commite99fd132807afc95fcc77c3c34043d87d317280b (patch)
treebc1f8495d75eafed971b457fd5155e8c0f3a66f1
parentcb61b7980446fa3c463a7c07963cf30e2c9c73c6 (diff)
downloadeclipse.jdt.core-e99fd132807afc95fcc77c3c34043d87d317280b.tar.gz
eclipse.jdt.core-e99fd132807afc95fcc77c3c34043d87d317280b.tar.xz
eclipse.jdt.core-e99fd132807afc95fcc77c3c34043d87d317280b.zip
146324 in 3.2.1
-rw-r--r--org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java4
-rw-r--r--org.eclipse.jdt.core/buildnotes_jdt-core.html4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java7
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java55
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java74
5 files changed, 96 insertions, 48 deletions
diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java
index d24c365c47..1f8cb05ba4 100644
--- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java
+++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java
@@ -723,10 +723,10 @@ public class IncrementalTests extends BuilderTests {
env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
env.addClass(root, "", "AB", //$NON-NLS-1$ //$NON-NLS-2$
- "public class AB extends AZ {}"); //$NON-NLS-1$
+ "public class AB { AZ z = new AA();}"); //$NON-NLS-1$
env.addClass(root, "", "AA", //$NON-NLS-1$ //$NON-NLS-2$
- "public class AA {} \n"+ //$NON-NLS-1$
+ "public class AA extends AZ {} \n"+ //$NON-NLS-1$
"class AZ {}"); //$NON-NLS-1$
int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE;
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index 0da42e37ad..7a5adb2bbf 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -57,7 +57,9 @@ Eclipse SDK 3.2.1 - ?th September 2006
</ul>
<h3>Problem Reports Fixed</h3>
-<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=146615">146615</a>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=146324">146324</a>
+Batch builds produce "The type X is already defined" errors
+<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=146615">146615</a>
[hierarchy] TypeHierarchyTests is tests order dependent
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=142207">142207</a>
[batch][options] Source/target level names 5 and 5.0 missing from batch
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
index ab14703db1..d7dc58b230 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
@@ -108,9 +108,10 @@ void buildTypeBindings(AccessRestriction accessRestriction) {
TypeDeclaration typeDecl = types[i];
ReferenceBinding typeBinding = fPackage.getType0(typeDecl.name);
recordSimpleReference(typeDecl.name); // needed to detect collision cases
- if (typeBinding != null && !(typeBinding instanceof UnresolvedReferenceBinding)) {
- // if a type exists, it must be a valid type - cannot be a NotFound problem type
- // unless its an unresolved type which is now being defined
+ if (typeBinding != null && typeBinding.isValidBinding() && !(typeBinding instanceof UnresolvedReferenceBinding)) {
+ // if a type exists, check that its a valid type
+ // it can be a NotFound problem type if its a secondary type referenced before its primary type found in additional units
+ // and it can be an unresolved type which is now being defined
problemReporter().duplicateTypes(referenceContext, typeDecl);
continue nextType;
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
index 2dcba305eb..9f844fee13 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
@@ -14,6 +14,7 @@ import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.compiler.*;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.core.util.Messages;
import org.eclipse.jdt.internal.core.util.Util;
@@ -23,13 +24,15 @@ import java.util.*;
public class BatchImageBuilder extends AbstractImageBuilder {
IncrementalImageBuilder incrementalBuilder; // if annotations or secondary types have to be processed after the compile loop
- ArrayList missingSecondaryTypes; // qualified names for any secondary types found after the first compile loop
+ ArrayList secondaryTypes; // qualified names for all secondary types found during batch compile
+ StringSet typeLocatorsWithUndefinedTypes; // type locators for all source files with errors that may be caused by 'not found' secondary types
protected BatchImageBuilder(JavaBuilder javaBuilder, boolean buildStarting) {
super(javaBuilder, buildStarting, null);
this.nameEnvironment.isIncrementalBuild = false;
this.incrementalBuilder = null;
- this.missingSecondaryTypes = null;
+ this.secondaryTypes = null;
+ this.typeLocatorsWithUndefinedTypes = null;
}
public void build() {
@@ -55,8 +58,9 @@ public void build() {
workQueue.addAll(allSourceFiles);
compile(allSourceFiles);
- if (this.missingSecondaryTypes != null && !this.missingSecondaryTypes.isEmpty())
- rebuildTypesAffectedByMissingSecondaryTypes();
+ if (this.typeLocatorsWithUndefinedTypes != null)
+ if (this.secondaryTypes != null && !this.secondaryTypes.isEmpty())
+ rebuildTypesAffectedBySecondaryTypes();
if (this.incrementalBuilder != null)
this.incrementalBuilder.buildAfterBatchBuild();
}
@@ -71,8 +75,8 @@ public void build() {
}
protected void acceptSecondaryType(ClassFile classFile) {
- if (this.missingSecondaryTypes != null)
- this.missingSecondaryTypes.add(classFile.fileName());
+ if (this.secondaryTypes != null)
+ this.secondaryTypes.add(classFile.fileName());
}
protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
@@ -207,13 +211,14 @@ protected void cleanOutputFolders(boolean copyBack) throws CoreException {
protected void cleanUp() {
this.incrementalBuilder = null;
- this.missingSecondaryTypes = null;
+ this.secondaryTypes = null;
+ this.typeLocatorsWithUndefinedTypes = null;
super.cleanUp();
}
protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
- if (!compilingFirstGroup && this.missingSecondaryTypes == null)
- this.missingSecondaryTypes = new ArrayList(7);
+ if (additionalUnits != null && this.secondaryTypes == null)
+ this.secondaryTypes = new ArrayList(7);
super.compile(units, additionalUnits, compilingFirstGroup);
}
@@ -323,14 +328,38 @@ protected void processAnnotationResults(CompilationParticipantResult[] results)
this.incrementalBuilder.processAnnotationResults(results);
}
-protected void rebuildTypesAffectedByMissingSecondaryTypes() {
+protected void rebuildTypesAffectedBySecondaryTypes() {
// to compile types that could not find 'missing' secondary types because of multiple
// compile groups, we need to incrementally recompile all affected types as if the missing
- // secondary types have just been added
+ // secondary types have just been added, see bug 146324
if (this.incrementalBuilder == null)
this.incrementalBuilder = new IncrementalImageBuilder(this);
- for (int i = this.missingSecondaryTypes.size(); --i >=0; )
- this.incrementalBuilder.addAffectedSourceFiles((char[]) this.missingSecondaryTypes.get(i));
+
+ for (int i = this.secondaryTypes.size(); --i >=0;) {
+ char[] secondaryTypeName = (char[]) this.secondaryTypes.get(i);
+ IPath path = new Path(null, new String(secondaryTypeName));
+ this.incrementalBuilder.addDependentsOf(path, false);
+ }
+ this.incrementalBuilder.addAffectedSourceFiles(
+ this.incrementalBuilder.qualifiedStrings,
+ this.incrementalBuilder.simpleStrings,
+ this.typeLocatorsWithUndefinedTypes);
+}
+
+protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException {
+ if (sourceFile == null || problems == null || problems.length == 0) return;
+
+ for (int i = problems.length; --i >= 0;) {
+ CategorizedProblem problem = problems[i];
+ if (problem != null && problem.getID() == IProblem.UndefinedType) {
+ if (this.typeLocatorsWithUndefinedTypes == null)
+ this.typeLocatorsWithUndefinedTypes = new StringSet(3);
+ this.typeLocatorsWithUndefinedTypes.add(sourceFile.typeLocator());
+ break;
+ }
+ }
+
+ super.storeProblemsFor(sourceFile, problems);
}
public String toString() {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
index 99b5e4fa1b..4f907cf446 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
@@ -168,24 +168,10 @@ protected void buildAfterBatchBuild() {
protected void addAffectedSourceFiles() {
if (qualifiedStrings.elementSize == 0 && simpleStrings.elementSize == 0) return;
- addAffectedSourceFiles(qualifiedStrings, simpleStrings);
+ addAffectedSourceFiles(qualifiedStrings, simpleStrings, null);
}
-protected void addAffectedSourceFiles(char[] secondaryTypeName) {
- // the secondary type search can have too many false hits if we addAffectedSource files using all the qualified type names
- // of each secondary type... so look for the dependents 1 file at a time
- int index = CharOperation.lastIndexOf('/', secondaryTypeName);
- String packageName = index == -1 ? "" : new String(CharOperation.subarray(secondaryTypeName, 0, index)); //$NON-NLS-1$
- StringSet packageNames = new StringSet(1);
- packageNames.add(packageName);
- String typeName = new String(index == -1 ? secondaryTypeName : CharOperation.subarray(secondaryTypeName, index + 1, secondaryTypeName.length));
- StringSet typeNames = new StringSet(1);
- typeNames.add(typeName);
-
- addAffectedSourceFiles(packageNames, typeNames);
-}
-
-private void addAffectedSourceFiles(StringSet qualifiedSet, StringSet simpleSet) {
+protected void addAffectedSourceFiles(StringSet qualifiedSet, StringSet simpleSet, 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
@@ -199,19 +185,22 @@ private void addAffectedSourceFiles(StringSet qualifiedSet, StringSet simpleSet)
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(internedQualifiedNames, internedSimpleNames)) {
- String typeLocator = (String) keyTable[i];
- IFile file = javaBuilder.currentProject.getFile(typeLocator);
- SourceFile sourceFile = findSourceFile(file);
- if (sourceFile == null) continue next;
- 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 (JavaBuilder.DEBUG)
- System.out.println(" adding affected source file " + typeLocator); //$NON-NLS-1$
- sourceFiles.add(sourceFile);
+ 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)) {
+ IFile file = javaBuilder.currentProject.getFile(typeLocator);
+ SourceFile sourceFile = findSourceFile(file);
+ if (sourceFile == null) continue next;
+ 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 (JavaBuilder.DEBUG)
+ System.out.println(" adding affected source file " + typeLocator); //$NON-NLS-1$
+ sourceFiles.add(sourceFile);
+ }
}
}
}
@@ -276,6 +265,33 @@ protected void cleanUp() {
this.compileLoop = 0;
}
+protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
+ if (compilingFirstGroup && additionalUnits != null) {
+ // add any source file from additionalUnits to units if it defines secondary types
+ // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type
+ // can cause an infinite loop as it alternates between not found and defined, see bug 146324
+ ArrayList extras = null;
+ for (int i = 0, l = additionalUnits.length; i < l; i++) {
+ SourceFile unit = additionalUnits[i];
+ if (unit != null && newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) {
+ if (JavaBuilder.DEBUG)
+ System.out.println("About to compile file with secondary types "+ unit.typeLocator()); //$NON-NLS-1$
+ if (extras == null)
+ extras = new ArrayList(3);
+ extras.add(unit);
+ }
+ }
+ if (extras != null) {
+ int oldLength = units.length;
+ int toAdd = extras.size();
+ System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength);
+ for (int i = 0; i < toAdd; i++)
+ units[oldLength++] = (SourceFile) extras.get(i);
+ }
+ }
+ super.compile(units, additionalUnits, compilingFirstGroup);
+}
+
protected void deleteGeneratedFiles(IFile[] deletedGeneratedFiles) {
// delete generated files and recompile any affected source files
try {

Back to the top