### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java,v retrieving revision 1.295 diff -u -r1.295 NegativeTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 24 Nov 2006 17:07:29 -0000 1.295 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 7 Dec 2006 20:55:44 -0000 @@ -15482,6 +15482,11 @@ " bar().missing();\n" + " ^^^^^^^^^^^^^^^\n" + "The type plugin3.SecretClass cannot be resolved. It is indirectly referenced from required .class files\n" + + "----------\n" + + "2. ERROR in plugin1\\Main.java (at line 5)\n" + + " bar().missing();\n" + + " ^^^^^^^\n" + + "The method missing() is undefined for the type Dumbo\n" + "----------\n", null, false); #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java,v retrieving revision 1.124 diff -u -r1.124 JavaBuilder.java --- model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 7 Dec 2006 07:28:06 -0000 1.124 +++ model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 7 Dec 2006 21:06:29 -0000 @@ -212,15 +212,6 @@ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); - } catch (MissingClassFileException e) { - // do not log this exception since its thrown to handle aborted compiles because of missing class files - if (DEBUG) - System.out.println(Messages.bind(Messages.build_incompleteClassPath, e.missingClassFile)); - IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); - marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_incompleteClassPath, e.missingClassFile)); - marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); - marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); - marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } catch (MissingSourceFileException e) { // do not log this exception since its thrown to handle aborted compiles because of missing source files if (DEBUG) @@ -291,7 +282,7 @@ IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage())); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); - marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } finally { notifier.done(); cleanup(); Index: model/org/eclipse/jdt/internal/core/builder/MissingClassFileException.java =================================================================== RCS file: model/org/eclipse/jdt/internal/core/builder/MissingClassFileException.java diff -N model/org/eclipse/jdt/internal/core/builder/MissingClassFileException.java --- model/org/eclipse/jdt/internal/core/builder/MissingClassFileException.java 10 May 2006 18:03:50 -0000 1.8 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.internal.core.builder; - -/** - * Exception thrown when the build should be aborted because a referenced - * class file cannot be found. - */ -public class MissingClassFileException extends RuntimeException { - - protected String missingClassFile; - private static final long serialVersionUID = 3060418973806972616L; // backward compatible - -public MissingClassFileException(String missingClassFile) { - this.missingClassFile = missingClassFile; -} -} Index: model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java,v retrieving revision 1.100 diff -u -r1.100 AbstractImageBuilder.java --- model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 7 Dec 2006 07:28:05 -0000 1.100 +++ model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 7 Dec 2006 21:06:29 -0000 @@ -50,6 +50,7 @@ private boolean inCompiler; +protected boolean keepStoringProblemMarkers; protected SimpleSet filesWithAnnotations = null; public static int MAX_AT_ONCE = 2000; // best compromise between space used and speed @@ -85,6 +86,7 @@ this.nameEnvironment = javaBuilder.nameEnvironment; this.sourceLocations = this.nameEnvironment.sourceLocations; this.notifier = javaBuilder.notifier; + this.keepStoringProblemMarkers = true; // may get disabled when missing classfiles are encountered if (buildStarting) { this.newState = newState == null ? new State(javaBuilder) : newState; @@ -550,25 +552,42 @@ */ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException { if (sourceFile == null || problems == null || problems.length == 0) return; + // once a classpath error is found, ignore all other problems for this project so the user can see the main error + // but still try to compile as many source files as possible to help the case when the base libraries are in source + if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file - String missingClassFile = null; IResource resource = sourceFile.resource; HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); for (int i = 0, l = problems.length; i < l; i++) { CategorizedProblem problem = problems[i]; int id = problem.getID(); + + // handle missing classfile situation if (id == IProblem.IsClassPathCorrect) { - JavaBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject); // make this the only problem for this project - String[] args = problem.getArguments(); - missingClassFile = args[0]; + String missingClassfileName = problem.getArguments()[0]; + if (JavaBuilder.DEBUG) + System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName)); + boolean isInvalidClasspathError = JavaCore.ERROR.equals(javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true)); + // insert extra classpath problem, and make it the only problem for this project (optional) + if (isInvalidClasspathError && JavaCore.ABORT.equals(javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) { + JavaBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject); // make this the only problem for this project + this.keepStoringProblemMarkers = false; + } + IMarker marker = this.javaBuilder.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); + marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_incompleteClassPath, missingClassfileName)); + marker.setAttribute(IMarker.SEVERITY, isInvalidClasspathError ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); + marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); + // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending + // IsClassPathCorrect problem gets recorded since it may help locate the offending reference } - + String markerType = problem.getMarkerType(); boolean managedProblem = false; if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) - || (managedProblem = managedMarkerTypes.contains(markerType))) { + || (managedProblem = managedMarkerTypes.contains(markerType))) { IMarker marker = resource.createMarker(markerType); - + // standard attributes marker.setAttributes( JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES, @@ -593,9 +612,9 @@ if (extraLength > 0) { marker.setAttributes(extraAttributeNames, problem.getExtraMarkerAttributeValues()); } + + if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file } - if (missingClassFile != null) - throw new MissingClassFileException(missingClassFile); } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.142 diff -u -r1.142 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 23 Nov 2006 17:27:18 -0000 1.142 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 7 Dec 2006 21:06:28 -0000 @@ -957,11 +957,15 @@ problemReporter().hierarchyHasProblems(sourceType); } connectMemberTypes(); + LookupEnvironment env = environment(); try { + env.missingClassFileLocation = referenceContext; checkForInheritedMemberTypes(sourceType); } catch (AbortCompilation e) { e.updateContext(referenceContext, referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } @@ -1099,19 +1103,24 @@ } private ReferenceBinding findSupertype(TypeReference typeReference) { + CompilationUnitScope unitScope = compilationUnitScope(); + LookupEnvironment env = unitScope.environment; try { + env.missingClassFileLocation = typeReference; typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes - compilationUnitScope().recordQualifiedReference(typeReference.getTypeName()); + unitScope.recordQualifiedReference(typeReference.getTypeName()); this.superTypeReference = typeReference; ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this); - this.superTypeReference = null; return superType; } catch (AbortCompilation e) { SourceTypeBinding sourceType = this.referenceContext.binding; if (sourceType.superInterfaces == null) sourceType.superInterfaces = Binding.NO_SUPERINTERFACES; // be more resilient for hierarchies (144976) e.updateContext(typeReference, referenceCompilationUnit().compilationResult); throw e; - } + } finally { + env.missingClassFileLocation = null; + this.superTypeReference = null; + } } /* Answer the problem reporter to use for raising new problems. Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.297 diff -u -r1.297 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 7 Dec 2006 16:22:24 -0000 1.297 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 7 Dec 2006 21:06:28 -0000 @@ -1355,8 +1355,10 @@ * Limitations: cannot request FIELD independently of LOCAL, or vice versa */ public Binding getBinding(char[] name, int mask, InvocationSite invocationSite, boolean needResolve) { - + CompilationUnitScope unitScope = compilationUnitScope(); + LookupEnvironment env = unitScope.environment; try { + env.missingClassFileLocation = invocationSite; Binding binding = null; FieldBinding problemField = null; if ((mask & Binding.VARIABLE) != 0) { @@ -1499,7 +1501,6 @@ if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // at this point the scope is a compilation unit scope & need to check for imported static fields - CompilationUnitScope unitScope = (CompilationUnitScope) scope; ImportBinding[] imports = unitScope.imports; if (imports != null) { // check single static imports @@ -1564,9 +1565,8 @@ return binding; // answer the problem type binding if we are only looking for a type } else if ((mask & Binding.PACKAGE) != 0) { - CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordSimpleReference(name); - if ((binding = unitScope.environment.getTopLevelPackage(name)) != null) + if ((binding = env.getTopLevelPackage(name)) != null) return binding; } if (problemField != null) return problemField; @@ -1576,12 +1576,16 @@ } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } public MethodBinding getConstructor(ReferenceBinding receiverType, TypeBinding[] argumentTypes, InvocationSite invocationSite) { + CompilationUnitScope unitScope = compilationUnitScope(); + LookupEnvironment env = unitScope.environment; try { - CompilationUnitScope unitScope = compilationUnitScope(); + env.missingClassFileLocation = invocationSite; unitScope.recordTypeReference(receiverType); unitScope.recordTypeReferences(argumentTypes); MethodBinding methodBinding = receiverType.getExactConstructor(argumentTypes); @@ -1636,6 +1640,8 @@ } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } @@ -1680,7 +1686,9 @@ } public FieldBinding getField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite) { + LookupEnvironment env = environment(); try { + env.missingClassFileLocation = invocationSite; FieldBinding field = findField(receiverType, fieldName, invocationSite, true /*resolve*/); if (field != null) return field; @@ -1691,7 +1699,9 @@ } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; - } + } finally { + env.missingClassFileLocation = null; + } } /* API @@ -1981,15 +1991,18 @@ } public MethodBinding getMethod(TypeBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { + CompilationUnitScope unitScope = compilationUnitScope(); + LookupEnvironment env = unitScope.environment; try { + env.missingClassFileLocation = invocationSite; switch (receiverType.kind()) { case Binding.BASE_TYPE : return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound); case Binding.ARRAY_TYPE : - compilationUnitScope().recordTypeReference(receiverType); + unitScope.recordTypeReference(receiverType); return findMethodForArray((ArrayBinding) receiverType, selector, argumentTypes, invocationSite); } - compilationUnitScope().recordTypeReference(receiverType); + unitScope.recordTypeReference(receiverType); ReferenceBinding currentType = (ReferenceBinding) receiverType; if (!currentType.canBeSeenBy(this)) @@ -2016,6 +2029,8 @@ } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java,v retrieving revision 1.74 diff -u -r1.74 LookupEnvironment.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 17 Nov 2006 19:43:52 -0000 1.74 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 7 Dec 2006 21:06:28 -0000 @@ -64,6 +64,7 @@ private SimpleLookupTable uniqueParameterizedGenericMethodBindings; public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units + public Object missingClassFileLocation = null; // only set when resolving certain references, to help locating problems private CompilationUnitDeclaration[] units = new CompilationUnitDeclaration[4]; private MethodVerifier verifier; @@ -172,6 +173,26 @@ return createBinaryTypeFrom(binaryType, computePackageFrom(compoundName), needFieldsAndMethods, accessRestriction); return null; // the type already exists & can be retrieved from the cache } +public BinaryTypeBinding cacheMissingBinaryType(char[][] compoundName, CompilationUnitDeclaration unit) { + // report the missing class file first + problemReporter.isClassPathCorrect( + compoundName, + unit == null ? this.unitBeingCompleted : unit, + this.missingClassFileLocation); + + PackageBinding packageBinding = computePackageFrom(compoundName); + // create a proxy for the missing BinaryType + MissingBinaryTypeBinding type = new MissingBinaryTypeBinding(packageBinding, compoundName, this); + if (type.id != TypeIds.T_JavaLangObject) { + // make Object be its superclass - it could in turn be missing as well + ReferenceBinding objectType = getType(TypeConstants.JAVA_LANG_OBJECT); + if (objectType == null) + objectType = cacheMissingBinaryType(TypeConstants.JAVA_LANG_OBJECT, unit); // create a proxy for the missing Object type + type.setMissingSuperclass(objectType); + } + packageBinding.addType(type); + return type; +} /* * 1. Connect the type hierarchy for the type bindings created for parsedUnits. * 2. Create the field bindings @@ -860,8 +881,10 @@ ReferenceBinding type = getType(compoundName); if (type != null) return type; - problemReporter.isClassPathCorrect(compoundName, scope == null ? null : scope.referenceCompilationUnit()); - return null; // will not get here since the above error aborts the compilation + // create a proxy for the missing BinaryType + return cacheMissingBinaryType( + compoundName, + scope == null ? this.unitBeingCompleted : scope.referenceCompilationUnit()); } /* Answer the top level package named name. * Ask the oracle for the package if its not in the cache. @@ -886,7 +909,7 @@ } /* Answer the type corresponding to the compoundName. * Ask the name environment for the type if its not in the cache. -* Answer null if the type cannot be found... likely a fatal error. +* Answer null if the type cannot be found. */ public ReferenceBinding getType(char[][] compoundName) { @@ -947,8 +970,6 @@ * unresolved type is returned which must be resolved before used. * * NOTE: Does NOT answer base types nor array types! -* -* NOTE: Aborts compilation if the class file cannot be found. */ ReferenceBinding getTypeFromCompoundName(char[][] compoundName, boolean isParameterized) { @@ -958,11 +979,11 @@ binding = new UnresolvedReferenceBinding(compoundName, packageBinding); packageBinding.addType(binding); } else if (binding == TheNotFoundType) { - problemReporter.isClassPathCorrect(compoundName, null); - return null; // will not get here since the above error aborts the compilation + // create a proxy for the missing BinaryType + binding = cacheMissingBinaryType(compoundName, this.unitBeingCompleted); } else if (!isParameterized) { // check raw type, only for resolved types - binding = (ReferenceBinding)convertUnresolvedBinaryToRawType(binding); + binding = (ReferenceBinding) convertUnresolvedBinaryToRawType(binding); } return binding; } @@ -971,8 +992,6 @@ * unresolved type is returned which must be resolved before used. * * NOTE: Does NOT answer base types nor array types! -* -* NOTE: Aborts compilation if the class file cannot be found. */ ReferenceBinding getTypeFromConstantPoolName(char[] signature, int start, int end, boolean isParameterized) { @@ -987,8 +1006,6 @@ * unresolved type is returned which must be resolved before used. * * NOTE: Does answer base types & array types. -* -* NOTE: Aborts compilation if the class file cannot be found. */ TypeBinding getTypeFromSignature(char[] signature, int start, int end, boolean isParameterized, TypeBinding enclosingType) { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java,v retrieving revision 1.26 diff -u -r1.26 UnresolvedReferenceBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java 10 May 2006 18:03:50 -0000 1.26 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java 7 Dec 2006 21:06:28 -0000 @@ -41,12 +41,11 @@ targetType = this.fPackage.getType0(this.compoundName[this.compoundName.length - 1]); if (targetType == this) targetType = environment.askForType(this.compoundName); - if (targetType != null && targetType != this) { // could not resolve any better, error was already reported against it - setResolvedType(targetType, environment); - } else { - environment.problemReporter.isClassPathCorrect(this.compoundName, null); - return null; // will not get here since the above error aborts the compilation + if (targetType == null || targetType == this) { // could not resolve any better, error was already reported against it + // create a proxy for the missing BinaryType + targetType = environment.cacheMissingBinaryType(this.compoundName, null); } + setResolvedType(targetType, environment); } if (convertGenericToRawType) { targetType = (ReferenceBinding) environment.convertUnresolvedBinaryToRawType(targetType); Index: compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java,v retrieving revision 1.100 diff -u -r1.100 BinaryTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java 23 Nov 2006 18:11:41 -0000 1.100 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java 7 Dec 2006 21:06:27 -0000 @@ -30,21 +30,21 @@ null is NOT a valid value for a non-public field... it just means the field is not initialized. */ -public final class BinaryTypeBinding extends ReferenceBinding { +public class BinaryTypeBinding extends ReferenceBinding { // all of these fields are ONLY guaranteed to be initialized if accessed using their public accessor method - private ReferenceBinding superclass; - private ReferenceBinding enclosingType; - private ReferenceBinding[] superInterfaces; - private FieldBinding[] fields; - private MethodBinding[] methods; - private ReferenceBinding[] memberTypes; + protected ReferenceBinding superclass; + protected ReferenceBinding enclosingType; + protected ReferenceBinding[] superInterfaces; + protected FieldBinding[] fields; + protected MethodBinding[] methods; + protected ReferenceBinding[] memberTypes; protected TypeVariableBinding[] typeVariables; // For the link with the principle structure - private LookupEnvironment environment; + protected LookupEnvironment environment; - private SimpleLookupTable storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder + protected SimpleLookupTable storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder static Object convertMemberValue(Object binaryValue, LookupEnvironment env) { if (binaryValue == null) return null; @@ -133,6 +133,19 @@ return type; } +/** + * Default empty constructor for subclasses only. + */ +protected BinaryTypeBinding() { + // only for subclasses +} + +/** + * Standard constructor for creating binary type bindings from binary models (classfiles) + * @param packageBinding + * @param binaryType + * @param environment + */ public BinaryTypeBinding(PackageBinding packageBinding, IBinaryType binaryType, LookupEnvironment environment) { this.compoundName = CharOperation.splitOn('/', binaryType.getName()); computeId(); @@ -252,7 +265,7 @@ if (superclassName != null) { // attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested) this.superclass = environment.getTypeFromConstantPoolName(superclassName, 0, -1, false); - this.tagBits |= TagBits.HasUnresolvedSuperclass; + this.tagBits |= TagBits.HasUnresolvedSuperclass; } this.superInterfaces = Binding.NO_SUPERINTERFACES; @@ -264,7 +277,7 @@ for (int i = 0; i < size; i++) // attempt to find each superinterface if it exists in the cache (otherwise - resolve it when requested) this.superInterfaces[i] = environment.getTypeFromConstantPoolName(interfaceNames[i], 0, -1, false); - this.tagBits |= TagBits.HasUnresolvedSuperinterfaces; + this.tagBits |= TagBits.HasUnresolvedSuperinterfaces; } } } else { @@ -281,7 +294,7 @@ // attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested) this.superclass = (ReferenceBinding) environment.getTypeFromTypeSignature(wrapper, Binding.NO_TYPE_VARIABLES, this); - this.tagBits |= TagBits.HasUnresolvedSuperclass; + this.tagBits |= TagBits.HasUnresolvedSuperclass; this.superInterfaces = Binding.NO_SUPERINTERFACES; if (!wrapper.atEnd()) { @@ -292,7 +305,7 @@ } while (!wrapper.atEnd()); this.superInterfaces = new ReferenceBinding[types.size()]; types.toArray(this.superInterfaces); - this.tagBits |= TagBits.HasUnresolvedSuperinterfaces; + this.tagBits |= TagBits.HasUnresolvedSuperinterfaces; } } @@ -908,6 +921,8 @@ // finish resolving the type this.superclass = resolveType(this.superclass, this.environment, true); this.tagBits &= ~TagBits.HasUnresolvedSuperclass; + if (this.superclass.problemId() == ProblemReasons.NotFound) + this.tagBits |= TagBits.HierarchyHasProblems; // propagate type inconsistency return this.superclass; } // NOTE: superInterfaces of binary types are resolved when needed @@ -915,8 +930,11 @@ if ((this.tagBits & TagBits.HasUnresolvedSuperinterfaces) == 0) return this.superInterfaces; - for (int i = this.superInterfaces.length; --i >= 0;) + for (int i = this.superInterfaces.length; --i >= 0;) { this.superInterfaces[i] = resolveType(this.superInterfaces[i], this.environment, true); + if (this.superInterfaces[i].problemId() == ProblemReasons.NotFound) + this.tagBits |= TagBits.HierarchyHasProblems; // propagate type inconsistency + } this.tagBits &= ~TagBits.HasUnresolvedSuperinterfaces; return this.superInterfaces; } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java,v retrieving revision 1.103 diff -u -r1.103 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 17 Nov 2006 19:43:52 -0000 1.103 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 7 Dec 2006 21:06:28 -0000 @@ -550,9 +550,11 @@ if (importBinding != null) importBinding = ((PackageBinding) importBinding).getTypeOrPackage(JAVA_LANG[1]); - // abort if java.lang cannot be found... - if (importBinding == null || !importBinding.isValidBinding()) - problemReporter().isClassPathCorrect(JAVA_LANG_OBJECT, referenceCompilationUnit()); + if (importBinding == null || !importBinding.isValidBinding()) { + // create a proxy for the missing BinaryType + BinaryTypeBinding missingObject = environment.cacheMissingBinaryType(JAVA_LANG_OBJECT, this.referenceContext); + importBinding = missingObject.fPackage; + } return environment.defaultImports = new ImportBinding[] {new ImportBinding(JAVA_LANG, true, importBinding, null)}; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java,v retrieving revision 1.37 diff -u -r1.37 QualifiedTypeReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java 20 Oct 2006 11:02:03 -0000 1.37 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java 7 Dec 2006 21:06:27 -0000 @@ -34,7 +34,9 @@ } protected TypeBinding findNextTypeBinding(int tokenIndex, Scope scope, PackageBinding packageBinding) { + LookupEnvironment env = scope.environment(); try { + env.missingClassFileLocation = this; if (this.resolvedType == null) { this.resolvedType = scope.getType(this.tokens[tokenIndex], packageBinding); } else { @@ -51,6 +53,8 @@ } catch (AbortCompilation e) { e.updateContext(this, scope.referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java,v retrieving revision 1.28 diff -u -r1.28 ArrayQualifiedTypeReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java 10 May 2006 18:03:43 -0000 1.28 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java 7 Dec 2006 21:06:27 -0000 @@ -54,12 +54,16 @@ if (this.dimensions > 255) { scope.problemReporter().tooManyDimensions(this); } + LookupEnvironment env = scope.environment(); try { + env.missingClassFileLocation = this; TypeBinding leafComponentType = super.getTypeBinding(scope); return this.resolvedType = scope.createArrayType(leafComponentType, dimensions); } catch (AbortCompilation e) { e.updateContext(this, scope.referenceCompilationUnit().compilationResult); throw e; + } finally { + env.missingClassFileLocation = null; } } Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.334 diff -u -r1.334 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 1 Dec 2006 21:44:44 -0000 1.334 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 7 Dec 2006 21:06:29 -0000 @@ -3443,16 +3443,27 @@ argument.type.sourceStart, argument.sourceEnd); } -public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) { +public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location) { this.referenceContext = compUnitDecl; String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)}; + int start = 0, end = 0; + if (location != null) { + if (location instanceof InvocationSite) { + InvocationSite site = (InvocationSite) location; + start = site.sourceStart(); + end = site.sourceEnd(); + } else if (location instanceof ASTNode) { + ASTNode node = (ASTNode) location; + start = node.sourceStart(); + end = node.sourceEnd(); + } + } this.handle( IProblem.IsClassPathCorrect, arguments, arguments, - ProblemSeverities.AbortCompilation | ProblemSeverities.Error | ProblemSeverities.Fatal, - 0, - 0); + start, + end); } private boolean isIdentifier(int token) { return token == TerminalTokens.TokenNameIdentifier; Index: compiler/org/eclipse/jdt/internal/compiler/Compiler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java,v retrieving revision 1.81 diff -u -r1.81 Compiler.java --- compiler/org/eclipse/jdt/internal/compiler/Compiler.java 28 Nov 2006 03:54:20 -0000 1.81 +++ compiler/org/eclipse/jdt/internal/compiler/Compiler.java 7 Dec 2006 21:06:27 -0000 @@ -584,6 +584,7 @@ * Process a compilation unit already parsed and build. */ public void process(CompilationUnitDeclaration unit, int i) { + this.lookupEnvironment.unitBeingCompleted = unit; this.parser.getMethodBodies(unit); @@ -610,6 +611,8 @@ // refresh the total number of units known at this stage unit.compilationResult.totalUnitsKnown = totalUnits; + + this.lookupEnvironment.unitBeingCompleted = null; } public void reset() { lookupEnvironment.reset(); Index: model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java,v retrieving revision 1.71 diff -u -r1.71 HierarchyResolver.java --- model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java 20 Oct 2006 11:02:03 -0000 1.71 +++ model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java 7 Dec 2006 21:06:29 -0000 @@ -166,30 +166,36 @@ if (superBinding != null) { superBinding = (ReferenceBinding) superBinding.erasure(); - if (superBinding.id == TypeIds.T_JavaLangObject && typeBinding.isHierarchyInconsistent()) { - char[] superclassName; - char separator; - if (type instanceof IBinaryType) { - superclassName = ((IBinaryType)type).getSuperclassName(); - separator = '/'; - } else if (type instanceof ISourceType) { - superclassName = ((ISourceType)type).getSuperclassName(); - separator = '.'; - } else if (type instanceof HierarchyType) { - superclassName = ((HierarchyType)type).superclassName; - separator = '.'; - } else { + if (typeBinding.isHierarchyInconsistent()) { + if (superBinding.problemId() == ProblemReasons.NotFound) { + this.hasMissingSuperClass = true; + this.builder.hierarchy.missingTypes.add(new String(superBinding.sourceName)); // note: this could be Map$Entry return null; - } - - if (superclassName != null) { // check whether subclass of Object due to broken hierarchy (as opposed to explicitly extending it) - int lastSeparator = CharOperation.lastIndexOf(separator, superclassName); - char[] simpleName = lastSeparator == -1 ? superclassName : CharOperation.subarray(superclassName, lastSeparator+1, superclassName.length); - if (!CharOperation.equals(simpleName, TypeConstants.OBJECT)) { - this.hasMissingSuperClass = true; - this.builder.hierarchy.missingTypes.add(new String(simpleName)); + } else if ((superBinding.id == TypeIds.T_JavaLangObject)) { + char[] superclassName; + char separator; + if (type instanceof IBinaryType) { + superclassName = ((IBinaryType)type).getSuperclassName(); + separator = '/'; + } else if (type instanceof ISourceType) { + superclassName = ((ISourceType)type).getSuperclassName(); + separator = '.'; + } else if (type instanceof HierarchyType) { + superclassName = ((HierarchyType)type).superclassName; + separator = '.'; + } else { return null; } + + if (superclassName != null) { // check whether subclass of Object due to broken hierarchy (as opposed to explicitly extending it) + int lastSeparator = CharOperation.lastIndexOf(separator, superclassName); + char[] simpleName = lastSeparator == -1 ? superclassName : CharOperation.subarray(superclassName, lastSeparator+1, superclassName.length); + if (!CharOperation.equals(simpleName, TypeConstants.OBJECT)) { + this.hasMissingSuperClass = true; + this.builder.hierarchy.missingTypes.add(new String(simpleName)); + return null; + } + } } } for (int t = this.typeIndex; t >= 0; t--) { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MissingBinaryTypeBinding.java =================================================================== RCS file: compiler/org/eclipse/jdt/internal/compiler/lookup/MissingBinaryTypeBinding.java diff -N compiler/org/eclipse/jdt/internal/compiler/lookup/MissingBinaryTypeBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MissingBinaryTypeBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +public class MissingBinaryTypeBinding extends BinaryTypeBinding { + +/** + * Special constructor for constructing proxies of missing binary types (114349) + * @param packageBinding + * @param compoundName + * @param environment + */ +public MissingBinaryTypeBinding(PackageBinding packageBinding, char[][] compoundName, LookupEnvironment environment) { + this.compoundName = compoundName; + computeId(); + this.tagBits |= TagBits.IsBinaryBinding | TagBits.HierarchyHasProblems; + this.environment = environment; + this.fPackage = packageBinding; + this.fileName = CharOperation.concatWith(compoundName, '/'); + this.sourceName = compoundName[compoundName.length - 1]; // [java][util][Map$Entry] + this.modifiers = ClassFileConstants.AccPublic; + this.superclass = null; // will be fixed up using #setMissingSuperclass(...) + this.superInterfaces = Binding.NO_SUPERINTERFACES; + this.typeVariables = Binding.NO_TYPE_VARIABLES; + this.memberTypes = Binding.NO_MEMBER_TYPES; + this.fields = Binding.NO_FIELDS; + this.methods = Binding.NO_METHODS; +} + +/** + * Missing binary type will answer false to #isValidBinding() + * @see org.eclipse.jdt.internal.compiler.lookup.Binding#problemId() + */ +public int problemId() { + return ProblemReasons.NotFound; +} + +/** + * Only used to fixup the superclass hierarchy of proxy binary types + * @param missingSuperclass + * @see LookupEnvironment#cacheMissingBinaryType(char[][], CompilationUnitDeclaration) + */ +void setMissingSuperclass(ReferenceBinding missingSuperclass) { + this.superclass = missingSuperclass; +} +} #P org.eclipse.jdt.core.tests.builder Index: src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java,v retrieving revision 1.47 diff -u -r1.47 MultiProjectTests.java --- src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java 7 Dec 2006 14:54:03 -0000 1.47 +++ src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java 7 Dec 2006 21:06:29 -0000 @@ -783,7 +783,7 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=114349 // this one fails; compare with testCycle7 (only one change in Object source), // which passes -public void _testCycle6() throws JavaModelException { +public void testCycle6() throws JavaModelException { Hashtable options = JavaCore.getOptions(); Hashtable newOptions = JavaCore.getOptions(); newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java,v retrieving revision 1.110 diff -u -r1.110 ASTConverterTestAST3_2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 23 Nov 2006 18:00:59 -0000 1.110 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 7 Dec 2006 21:06:31 -0000 @@ -6087,8 +6087,9 @@ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); CompilationUnit compilationUnit = (CompilationUnit) node; String expectedResult = + "The hierarchy of the type X is inconsistent\n" + "The type test0599.Zork2 cannot be resolved. It is indirectly referenced from required .class files"; - assertProblemsSize(compilationUnit, 1, expectedResult); + assertProblemsSize(compilationUnit, 2, expectedResult); compilationUnit.accept(new ASTVisitor() { public void endVisit(MethodDeclaration methodDeclaration) { Block body = methodDeclaration.getBody();