### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java,v retrieving revision 1.84 diff -u -r1.84 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 7 Jan 2009 17:34:23 -0000 1.84 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 8 Jan 2009 14:03:19 -0000 @@ -493,10 +493,6 @@ syntheticTypeDeclaration.javadoc = new Javadoc(syntheticTypeDeclaration.declarationSourceStart, syntheticTypeDeclaration.declarationSourceStart); } syntheticTypeDeclaration.resolve(this.scope); - // resolve annotations if any, skip this step if we don't have a valid scope due to an earlier error. (bug 252555) - if (this.currentPackage!= null && this.currentPackage.annotations != null && syntheticTypeDeclaration.staticInitializerScope != null) { - resolveAnnotations(syntheticTypeDeclaration.staticInitializerScope, this.currentPackage.annotations, this.scope.fPackage); - } /* * resolve javadoc package if any, skip this step if we don't have a valid scope due to an earlier error (bug 252555) * we do it now as the javadoc in the fake type won't be resolved. The peculiar usage of MethodScope to resolve the Index: compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java,v retrieving revision 1.48 diff -u -r1.48 PackageBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java 14 Nov 2008 20:28:34 -0000 1.48 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java 8 Jan 2009 14:03:20 -0000 @@ -10,9 +10,28 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.Annotation; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.IAnnotationBinding; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; import org.eclipse.jdt.internal.compiler.util.HashtableOfType; +import org.eclipse.jdt.internal.core.NameLookup; +import org.eclipse.jdt.internal.core.SearchableEnvironment; public class PackageBinding extends Binding implements TypeConstants { public long tagBits = 0; // See values in the interface TagBits below @@ -205,6 +224,102 @@ return null; } +/** + * Compute the tagbits for standard annotations. For source types, these could require + * lazily resolving corresponding annotation nodes, in case of forward references. + * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() + */ +public long getAnnotationTagBits() { + + if ((this.tagBits & TagBits.AnnotationResolved) != 0) + return this.tagBits; + + this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved); + + if (this.compoundName == CharOperation.NO_CHAR_CHAR) + return this.tagBits; + + ReferenceBinding packageInfo = this.getType(TypeConstants.PACKAGE_INFO_NAME); + if (packageInfo != null) { + this.tagBits |= (packageInfo.getAnnotationTagBits() & TagBits.AllStandardAnnotationsMask); + return this.tagBits; + } + + // We didn't find package-info.java. This may be due to its absence altogether in the package + // or may merely be due to the fact that the java model hides package-info.java even when it + // exists. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=99662. We work hard to restore + // @Deprecated annotation if it existed in the first place. + + INameEnvironment nameEnvironment = this.environment.nameEnvironment; + if (!(nameEnvironment instanceof SearchableEnvironment)) + return this.tagBits; + + NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup; + if (nameLookup == null) + return this.tagBits; + + final String pkgName = new String (readableName()); + IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/); + if (pkgs == null) + return this.tagBits; + + final String javaLangDeprecated = new String(CharOperation.concatWith(TypeConstants.JAVA_LANG_DEPRECATED, '.')); + try { + for (int i = 0, len = pkgs.length; i < len; i++) { + int fragType = pkgs[i].getKind(); + if (fragType == IPackageFragmentRoot.K_SOURCE) { + String unitName = "package-info.java"; //$NON-NLS-1$ + ICompilationUnit unit = pkgs[i].getCompilationUnit(unitName); + if (unit == null || !unit.exists()) + continue; + + ASTParser p = ASTParser.newParser(AST.JLS3); + p.setSource(unit); + p.setResolveBindings(true); + p.setUnitName(unitName); + p.setFocalPosition(0); + p.setKind(ASTParser.K_COMPILATION_UNIT); + CompilationUnit domUnit = (CompilationUnit) p.createAST(null); + PackageDeclaration pkgDecl = domUnit.getPackage(); + if (pkgDecl == null) + return this.tagBits; + + List annos = pkgDecl.annotations(); + if (annos == null || annos.isEmpty()) + return this.tagBits; + + for (Iterator it = annos.iterator(); it.hasNext();) { + IAnnotationBinding result; + result = ((Annotation) it.next()).resolveAnnotationBinding(); + ITypeBinding type = result.getAnnotationType(); + if (type != null) { + String name = type.getQualifiedName(); + if (name.equals(javaLangDeprecated)) { + this.tagBits |= TagBits.AnnotationDeprecated; + return this.tagBits; + } + } + } + return this.tagBits; + } + if (fragType == IPackageFragmentRoot.K_BINARY) { + NameEnvironmentAnswer answer = + nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.compoundName); + if (answer != null) { + if (answer.isBinaryType()) { + IBinaryType type = answer.getBinaryType(); + this.tagBits |= (type.getTagBits() & TagBits.AllStandardAnnotationsMask); + } + return this.tagBits; + } + } + } + } catch(JavaModelException e) { + return this.tagBits; + } + return this.tagBits; +} + /* API * Answer the receiver's binding type from Binding.BindingID. */ Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java,v retrieving revision 1.128 diff -u -r1.128 ReferenceBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 5 Dec 2008 16:49:14 -0000 1.128 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 8 Jan 2009 14:03:21 -0000 @@ -1175,7 +1175,7 @@ */ public final boolean isViewedAsDeprecated() { return (this.modifiers & (ClassFileConstants.AccDeprecated | ExtraCompilerModifiers.AccDeprecatedImplicitly)) != 0 - || (getPackage().tagBits & TagBits.AnnotationDeprecated) != 0; + || (getPackage().getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0; } public ReferenceBinding[] memberTypes() { 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.124 diff -u -r1.124 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 7 Jan 2009 17:34:23 -0000 1.124 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 8 Jan 2009 14:03:20 -0000 @@ -98,6 +98,7 @@ this.referenceContext.types[0] = declaration; declaration.name = TypeConstants.PACKAGE_INFO_NAME; declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface; + declaration.javadoc = this.referenceContext.javadoc; firstIsSynthetic = true; } // ensure the package annotations are copied over before resolution @@ -105,6 +106,9 @@ this.referenceContext.types[0].annotations = this.referenceContext.currentPackage.annotations; } recordQualifiedReference(this.currentPackageName); // always dependent on your own package + // Record a reference arc against "package-info", so a delta against package-info.java causes + // the current unit to be compiled afresh. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=214948 + recordQualifiedReference(CharOperation.arrayConcat(this.currentPackageName, TypeConstants.PACKAGE_INFO_NAME)); } // Skip typeDeclarations which know of previously reported errors 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.346 diff -u -r1.346 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 5 Dec 2008 12:41:29 -0000 1.346 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 8 Jan 2009 14:03:23 -0000 @@ -2809,16 +2809,15 @@ MethodBinding context = ((AbstractMethodDeclaration)methodScope.referenceContext).binding; if (context != null && context.isViewedAsDeprecated()) return true; - } else { - SourceTypeBinding type = ((BlockScope)this).referenceType().binding; + } else if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated()) { // inside field declaration ? check field modifier to see if deprecated - if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated()) + return true; + } + SourceTypeBinding declaringType = ((BlockScope)this).referenceType().binding; + if (declaringType != null) { + declaringType.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then + if (declaringType.isViewedAsDeprecated()) return true; - if (type != null) { - type.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then - if (type.isViewedAsDeprecated()) - return true; - } } break; case Scope.CLASS_SCOPE :