View | Details | Raw Unified | Return to bug 214948 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (-4 lines)
Lines 493-502 Link Here
493
			syntheticTypeDeclaration.javadoc = new Javadoc(syntheticTypeDeclaration.declarationSourceStart, syntheticTypeDeclaration.declarationSourceStart);
493
			syntheticTypeDeclaration.javadoc = new Javadoc(syntheticTypeDeclaration.declarationSourceStart, syntheticTypeDeclaration.declarationSourceStart);
494
		}
494
		}
495
		syntheticTypeDeclaration.resolve(this.scope);
495
		syntheticTypeDeclaration.resolve(this.scope);
496
		// resolve annotations if any, skip this step if we don't have a valid scope due to an earlier error. (bug 252555)
497
		if (this.currentPackage!= null && this.currentPackage.annotations != null && syntheticTypeDeclaration.staticInitializerScope != null) {
498
			resolveAnnotations(syntheticTypeDeclaration.staticInitializerScope, this.currentPackage.annotations, this.scope.fPackage);
499
		}
500
		/*
496
		/*
501
		 * resolve javadoc package if any, skip this step if we don't have a valid scope due to an earlier error (bug 252555)
497
		 * resolve javadoc package if any, skip this step if we don't have a valid scope due to an earlier error (bug 252555)
502
		 * we do it now as the javadoc in the fake type won't be resolved. The peculiar usage of MethodScope to resolve the
498
		 * we do it now as the javadoc in the fake type won't be resolved. The peculiar usage of MethodScope to resolve the
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java (+115 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import java.util.Iterator;
14
import java.util.List;
15
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IPackageFragment;
18
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.JavaModelException;
13
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.core.dom.AST;
22
import org.eclipse.jdt.core.dom.ASTParser;
23
import org.eclipse.jdt.core.dom.Annotation;
24
import org.eclipse.jdt.core.dom.ITypeBinding;
25
import org.eclipse.jdt.core.dom.CompilationUnit;
26
import org.eclipse.jdt.core.dom.IAnnotationBinding;
27
import org.eclipse.jdt.core.dom.PackageDeclaration;
28
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
29
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
30
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
14
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage;
31
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage;
15
import org.eclipse.jdt.internal.compiler.util.HashtableOfType;
32
import org.eclipse.jdt.internal.compiler.util.HashtableOfType;
33
import org.eclipse.jdt.internal.core.NameLookup;
34
import org.eclipse.jdt.internal.core.SearchableEnvironment;
16
35
17
public class PackageBinding extends Binding implements TypeConstants {
36
public class PackageBinding extends Binding implements TypeConstants {
18
	public long tagBits = 0; // See values in the interface TagBits below
37
	public long tagBits = 0; // See values in the interface TagBits below
Lines 205-210 Link Here
205
	return null;
224
	return null;
206
}
225
}
207
226
227
/**
228
 * Compute the tagbits for standard annotations. For source types, these could require
229
 * lazily resolving corresponding annotation nodes, in case of forward references.
230
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
231
 */
232
public long getAnnotationTagBits() {
233
234
	if ((this.tagBits & TagBits.AnnotationResolved) != 0)
235
		return this.tagBits;
236
237
	this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
238
239
	if (this.compoundName == CharOperation.NO_CHAR_CHAR)
240
		return this.tagBits;
241
242
	ReferenceBinding packageInfo = this.getType(TypeConstants.PACKAGE_INFO_NAME);
243
	if (packageInfo != null) {			
244
		this.tagBits |= (packageInfo.getAnnotationTagBits() & TagBits.AllStandardAnnotationsMask);
245
		return this.tagBits;
246
	}
247
248
	// We didn't find package-info.java. This may be due to its absence altogether in the package
249
	// or may merely be due to the fact that the java model hides package-info.java even when it
250
	// exists. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=99662. We work hard to restore
251
	// @Deprecated annotation if it existed in the first place.
252
253
	INameEnvironment nameEnvironment = this.environment.nameEnvironment;
254
	if (!(nameEnvironment instanceof SearchableEnvironment))
255
		return this.tagBits;
256
257
	NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup;
258
	if (nameLookup == null)
259
		return this.tagBits;
260
261
	final String pkgName = new String (readableName());
262
	IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/);
263
	if (pkgs == null)
264
		return this.tagBits;
265
266
	final String javaLangDeprecated = new String(CharOperation.concatWith(TypeConstants.JAVA_LANG_DEPRECATED, '.'));
267
	try {
268
		for (int i = 0, len = pkgs.length; i < len; i++) {
269
			int fragType = pkgs[i].getKind();
270
			if (fragType == IPackageFragmentRoot.K_SOURCE) {
271
				String unitName = "package-info.java"; //$NON-NLS-1$
272
				ICompilationUnit unit = pkgs[i].getCompilationUnit(unitName);
273
				if (unit == null || !unit.exists())
274
					continue;
275
276
				ASTParser p = ASTParser.newParser(AST.JLS3);
277
				p.setSource(unit);
278
				p.setResolveBindings(true);
279
				p.setUnitName(unitName);
280
				p.setFocalPosition(0);
281
				p.setKind(ASTParser.K_COMPILATION_UNIT);
282
				CompilationUnit domUnit = (CompilationUnit) p.createAST(null);
283
				PackageDeclaration pkgDecl = domUnit.getPackage();
284
				if (pkgDecl == null)
285
					return this.tagBits;
286
287
				List annos = pkgDecl.annotations();
288
				if (annos == null || annos.isEmpty())
289
					return this.tagBits;
290
291
				for (Iterator it = annos.iterator(); it.hasNext();) {
292
					IAnnotationBinding result;
293
					result = ((Annotation) it.next()).resolveAnnotationBinding();
294
					ITypeBinding type = result.getAnnotationType();
295
					if (type != null) {
296
						String name = type.getQualifiedName();
297
						if (name.equals(javaLangDeprecated)) {
298
							this.tagBits |= TagBits.AnnotationDeprecated;
299
							return this.tagBits;
300
						}
301
					}
302
				}
303
				return this.tagBits;
304
			}
305
			if (fragType == IPackageFragmentRoot.K_BINARY) {
306
				NameEnvironmentAnswer answer =
307
					nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.compoundName);
308
				if (answer != null) {
309
					if (answer.isBinaryType()) {
310
						IBinaryType type = answer.getBinaryType();
311
						this.tagBits |= (type.getTagBits() & TagBits.AllStandardAnnotationsMask);
312
					}
313
					return this.tagBits;
314
				}
315
			}
316
		}
317
	} catch(JavaModelException e) {
318
		return this.tagBits;
319
	}
320
	return this.tagBits;
321
}
322
208
/* API
323
/* API
209
* Answer the receiver's binding type from Binding.BindingID.
324
* Answer the receiver's binding type from Binding.BindingID.
210
*/
325
*/
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java (-1 / +1 lines)
Lines 1175-1181 Link Here
1175
 */
1175
 */
1176
public final boolean isViewedAsDeprecated() {
1176
public final boolean isViewedAsDeprecated() {
1177
	return (this.modifiers & (ClassFileConstants.AccDeprecated | ExtraCompilerModifiers.AccDeprecatedImplicitly)) != 0
1177
	return (this.modifiers & (ClassFileConstants.AccDeprecated | ExtraCompilerModifiers.AccDeprecatedImplicitly)) != 0
1178
			|| (getPackage().tagBits & TagBits.AnnotationDeprecated) != 0;
1178
			|| (getPackage().getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0;
1179
}
1179
}
1180
1180
1181
public ReferenceBinding[] memberTypes() {
1181
public ReferenceBinding[] memberTypes() {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (+4 lines)
Lines 98-103 Link Here
98
				this.referenceContext.types[0] = declaration;
98
				this.referenceContext.types[0] = declaration;
99
				declaration.name = TypeConstants.PACKAGE_INFO_NAME;
99
				declaration.name = TypeConstants.PACKAGE_INFO_NAME;
100
				declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
100
				declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
101
				declaration.javadoc = this.referenceContext.javadoc;
101
				firstIsSynthetic = true;
102
				firstIsSynthetic = true;
102
			}
103
			}
103
			// ensure the package annotations are copied over before resolution
104
			// ensure the package annotations are copied over before resolution
Lines 105-110 Link Here
105
				this.referenceContext.types[0].annotations = this.referenceContext.currentPackage.annotations;
106
				this.referenceContext.types[0].annotations = this.referenceContext.currentPackage.annotations;
106
		}
107
		}
107
		recordQualifiedReference(this.currentPackageName); // always dependent on your own package
108
		recordQualifiedReference(this.currentPackageName); // always dependent on your own package
109
		// Record a reference arc against "package-info", so a delta against package-info.java causes
110
		// the current unit to be compiled afresh. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=214948
111
		recordQualifiedReference(CharOperation.arrayConcat(this.currentPackageName, TypeConstants.PACKAGE_INFO_NAME));
108
	}
112
	}
109
113
110
	// Skip typeDeclarations which know of previously reported errors
114
	// Skip typeDeclarations which know of previously reported errors
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-8 / +7 lines)
Lines 2809-2824 Link Here
2809
					MethodBinding context = ((AbstractMethodDeclaration)methodScope.referenceContext).binding;
2809
					MethodBinding context = ((AbstractMethodDeclaration)methodScope.referenceContext).binding;
2810
					if (context != null && context.isViewedAsDeprecated())
2810
					if (context != null && context.isViewedAsDeprecated())
2811
						return true;
2811
						return true;
2812
				} else {
2812
				} else if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated()) {
2813
					SourceTypeBinding type = ((BlockScope)this).referenceType().binding;
2814
					// inside field declaration ? check field modifier to see if deprecated
2813
					// inside field declaration ? check field modifier to see if deprecated
2815
					if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated())
2814
					return true;
2815
				}
2816
				SourceTypeBinding declaringType = ((BlockScope)this).referenceType().binding;
2817
				if (declaringType != null) {
2818
					declaringType.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then
2819
					if (declaringType.isViewedAsDeprecated())
2816
						return true;
2820
						return true;
2817
					if (type != null) {
2818
						type.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then
2819
						if (type.isViewedAsDeprecated())
2820
							return true;
2821
					}
2822
				}
2821
				}
2823
				break;
2822
				break;
2824
			case Scope.CLASS_SCOPE :
2823
			case Scope.CLASS_SCOPE :

Return to bug 214948