### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java,v retrieving revision 1.133 diff -u -r1.133 CompilationUnitResolver.java --- dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 27 Aug 2008 16:06:09 -0000 1.133 +++ dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 29 Jan 2009 11:35:02 -0000 @@ -856,10 +856,16 @@ if (unit.scope != null) { // fault in fields & methods unit.scope.faultInTypes(); - if (unit.scope != null && verifyMethods) { + if (verifyMethods) { // http://dev.eclipse.org/bugs/show_bug.cgi?id=23117 - // verify inherited methods + // verify inherited methods unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); + if (!unit.scope.compilerOptions().reportDeprecationInsideDeprecatedCode) { + // If we short circuited some error reporting earlier due to being unable to say precisely + // if we are in a deprecated method, report those errors/warnings (if any) now. + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247206 + unit.scope.reportDeprecatedTypesInSignatures(); + } } // type checking unit.resolve(); Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java,v retrieving revision 1.100 diff -u -r1.100 MethodVerifier.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 4 Dec 2008 17:06:52 -0000 1.100 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 29 Jan 2009 11:34:59 -0000 @@ -168,17 +168,22 @@ if(inheritedMethod.isSynchronized() && !currentMethod.isSynchronized()) { problemReporter(currentMethod).missingSynchronizedOnInheritedMethod(currentMethod, inheritedMethod); } - if (options.reportDeprecationWhenOverridingDeprecatedMethod && inheritedMethod.isViewedAsDeprecated()) { - if (!currentMethod.isViewedAsDeprecated() || options.reportDeprecationInsideDeprecatedCode) { - // check against the other inherited methods to see if they hide this inheritedMethod - ReferenceBinding declaringClass = inheritedMethod.declaringClass; - if (declaringClass.isInterface()) - for (int j = length; --j >= 0;) - if (i != j && methods[j].declaringClass.implementsInterface(declaringClass, false)) - continue nextMethod; + if (inheritedMethod.isViewedAsDeprecated()) { + if (options.reportDeprecationWhenOverridingDeprecatedMethod) { + if (!currentMethod.isViewedAsDeprecated() || options.reportDeprecationInsideDeprecatedCode) { + // check against the other inherited methods to see if they hide this inheritedMethod + ReferenceBinding declaringClass = inheritedMethod.declaringClass; + if (declaringClass.isInterface()) + for (int j = length; --j >= 0;) + if (i != j && methods[j].declaringClass.implementsInterface(declaringClass, false)) + continue nextMethod; // Srikanth - check this. - problemReporter(currentMethod).overridesDeprecatedMethod(currentMethod, inheritedMethod); + problemReporter(currentMethod).overridesDeprecatedMethod(currentMethod, inheritedMethod); + } } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247206 + if (currentMethod.isImplementing() && !currentMethod.isViewedAsDeprecated()) + currentMethod.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; } } checkForBridgeMethod(currentMethod, inheritedMethod, allInheritedMethods); 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.125 diff -u -r1.125 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 12 Jan 2009 18:37:16 -0000 1.125 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 29 Jan 2009 11:34:58 -0000 @@ -813,4 +813,9 @@ for (int i = 0, length = this.topLevelTypes.length; i < length; i++) this.topLevelTypes[i].verifyMethods(verifier); } + +public void reportDeprecatedTypesInSignatures() { + for (int i = 0, length = this.topLevelTypes.length; i < length; i++) + this.topLevelTypes[i].reportDeprecatedTypesInSignatures(); +} } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v retrieving revision 1.170 diff -u -r1.170 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 14 Nov 2008 20:28:06 -0000 1.170 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 29 Jan 2009 11:35:00 -0000 @@ -1295,6 +1295,57 @@ } return null; // should never reach this point } +private void reportDeprecatedUsagesFor(MethodBinding method) { + // Deferred deprecation reporting. Now that the method verification is over, we are able to discover if + // ``method'' overrides an abstract method. If it does and that method is deprecated, then ``method'' itself + // should be considered to be implicitly deprecated. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=247206 + if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) != 0) + return; + + AbstractMethodDeclaration methodDecl = method.sourceMethod(); + if (methodDecl == null) + return; // method could not be resolved in previous iteration + + TypeReference[] exceptionTypes = methodDecl.thrownExceptions; + if (exceptionTypes != null) { + int size = exceptionTypes.length; + for (int i = 0; i < size; i++) { + TypeReference anException = exceptionTypes[i]; + if (anException != null && anException.resolvedType != null) { + if(!anException.resolvedType.isValidBinding()) + continue; + if (anException.isTypeUseDeprecated(anException.resolvedType, methodDecl.scope)) { + methodDecl.scope.problemReporter().deprecatedType(anException.resolvedType, anException); + } + } + } + } + + Argument[] arguments = methodDecl.arguments; + if (arguments != null) { + int size = arguments.length; + + for (int i = 0; i < size; i++) { + Argument anArgument = arguments[i]; + if (anArgument != null && anArgument.type != null && anArgument.type.resolvedType != null) { + if (!anArgument.type.resolvedType.isValidBinding()) + continue; + if (anArgument.isTypeUseDeprecated(anArgument.type.resolvedType, methodDecl.scope)) { + methodDecl.scope.problemReporter().deprecatedType(anArgument.type.resolvedType, anArgument); + } + } + } + } + + if (!method.isConstructor() && methodDecl instanceof MethodDeclaration) { + TypeReference returnType = ((MethodDeclaration) methodDecl).returnType; + if (returnType != null && returnType.resolvedType != null && returnType.resolvedType.isValidBinding()) { + if (returnType.isTypeUseDeprecated(returnType.resolvedType, methodDecl.scope)) { + methodDecl.scope.problemReporter().deprecatedType(returnType.resolvedType, returnType); + } + } + } +} public MethodBinding resolveTypesFor(MethodBinding method) { if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0) return method; @@ -1617,4 +1668,13 @@ for (int i = this.memberTypes.length; --i >= 0;) ((SourceTypeBinding) this.memberTypes[i]).verifyMethods(verifier); } +void reportDeprecatedTypesInSignatures() { + + for (int i = 0, length = this.methods.length; i < length; i++) + this.reportDeprecatedUsagesFor(this.methods[i]); + + for (int i = this.memberTypes.length; --i >= 0;) + ((SourceTypeBinding) this.memberTypes[i]).reportDeprecatedTypesInSignatures(); + +} } 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.110 diff -u -r1.110 Compiler.java --- compiler/org/eclipse/jdt/internal/compiler/Compiler.java 27 Nov 2008 17:30:31 -0000 1.110 +++ compiler/org/eclipse/jdt/internal/compiler/Compiler.java 29 Jan 2009 11:34:55 -0000 @@ -726,13 +726,16 @@ long resolveStart = System.currentTimeMillis(); this.stats.parseTime += resolveStart - parseStart; - // fault in fields & methods - if (unit.scope != null) - unit.scope.faultInTypes(); - - // verify inherited methods - if (unit.scope != null) - unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); + if (unit.scope != null) { + unit.scope.faultInTypes(); // fault in fields & methods + unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); // verify inherited methods + if (!unit.scope.compilerOptions().reportDeprecationInsideDeprecatedCode) { + // If we short circuited some error reporting earlier due to being unable to say precisely + // if we are in a deprecated method, report those errors if any now. + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247206 + unit.scope.reportDeprecatedTypesInSignatures(); + } + } // type checking unit.resolve(); @@ -845,10 +848,16 @@ if (unit.scope != null) { // fault in fields & methods unit.scope.faultInTypes(); - if (unit.scope != null && verifyMethods) { + if (verifyMethods) { // http://dev.eclipse.org/bugs/show_bug.cgi?id=23117 - // verify inherited methods + // verify inherited methods unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); + if (!unit.scope.compilerOptions().reportDeprecationInsideDeprecatedCode) { + // If we short circuited some error reporting earlier due to being unable to say precisely + // if we are in a deprecated method, report those errors/warnings (if any) now. + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247206 + unit.scope.reportDeprecatedTypesInSignatures(); + } } // type checking unit.resolve(); Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v retrieving revision 1.97 diff -u -r1.97 ASTNode.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 8 Jan 2009 20:51:05 -0000 1.97 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 29 Jan 2009 11:34:56 -0000 @@ -472,7 +472,21 @@ if (scope.isDefinedInSameUnit(refType)) return false; // if context is deprecated, may avoid reporting - if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false; + if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode) { + if (scope.isInsideDeprecatedCode()) + return false; + if (scope instanceof MethodScope) { + MethodScope mScope = (MethodScope) scope; + if (!mScope.isInsideInitializer()) { + MethodBinding method = ((AbstractMethodDeclaration) mScope.referenceContext).binding; + // If method is still unresolved, answer false as we cannot conclusively say (yet) + // whether the method is really an implementation of a deprecated interface. + if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) != 0) + return false; + } + } + } + return true; }