Skip to content

Commit 287e82f

Browse files
Incorrect warning for @SuppressWarnings for forRemoval deprecations in light of JEP 277 (#4595)
Inside deprecated code suppress only ordinary deprecation warnings Some more clean-up after PR #4564: + remove distinction isDeprecated() vs. isViewedAsDeprecated() + remove obsolete dead branch regarding implicit deprecation Let Deprecated9Test opt-in to run.javac mode Improve test isolation Fixes #4579
1 parent 2ecf692 commit 287e82f

File tree

9 files changed

+268
-58
lines changed

9 files changed

+268
-58
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,16 @@ public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, int f
492492
}
493493
}
494494

495-
if (!field.isViewedAsDeprecated()) return false;
495+
if (!field.isDeprecated()) return false;
496496

497497
// inside same outermost enclosing type - no report
498498
if (scope.isDefinedInSameEnclosingType(field.declaringClass.outermostEnclosingType())) return false;
499499

500-
// if context is deprecated, may avoid reporting
501-
if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
500+
// if context is deprecated, may avoid reporting ordinary deprecation
501+
if ((field.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0
502+
&& !scope.compilerOptions().reportDeprecationInsideDeprecatedCode
503+
&& scope.isInsideDeprecatedCode())
504+
return false;
502505
return true;
503506
}
504507

@@ -542,19 +545,16 @@ public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope,
542545
}
543546
}
544547

545-
if (!method.isViewedAsDeprecated()) return false;
548+
if (!method.isDeprecated()) return false;
546549

547550
// inside same outermost enclosing type - no report
548551
if (scope.isDefinedInSameEnclosingType(method.declaringClass.outermostEnclosingType())) return false;
549552

550-
// non explicit use and non explicitly deprecated - no report
551-
if (!isExplicitUse &&
552-
(method.modifiers & ClassFileConstants.AccDeprecated) == 0) {
553+
// if context is deprecated, may avoid reporting ordinary deprecation
554+
if ((method.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0
555+
&& !scope.compilerOptions().reportDeprecationInsideDeprecatedCode
556+
&& scope.isInsideDeprecatedCode())
553557
return false;
554-
}
555-
556-
// if context is deprecated, may avoid reporting
557-
if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
558558
return true;
559559
}
560560

@@ -615,13 +615,16 @@ public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
615615
// force annotations resolution before deciding whether the type may be deprecated
616616
refType.initializeDeprecatedAnnotationTagBits();
617617

618-
if (!refType.isViewedAsDeprecated()) return false;
618+
if (!refType.isDeprecated()) return false;
619619

620620
// inside same outermost enclosing type - no report
621621
if (scope.isDefinedInSameEnclosingType(refType.outermostEnclosingType())) return false;
622622

623-
// if context is deprecated, may avoid reporting
624-
if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
623+
// if context is deprecated, may avoid reporting ordinary deprecation
624+
if ((type.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0
625+
&& !scope.compilerOptions().reportDeprecationInsideDeprecatedCode
626+
&& scope.isInsideDeprecatedCode())
627+
return false;
625628
return true;
626629
}
627630

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,6 @@ public final boolean isUsedOnlyInCompound() {
370370
/* Answer true if the receiver has protected visibility
371371
*/
372372

373-
public final boolean isViewedAsDeprecated() {
374-
return (this.modifiers & ClassFileConstants.AccDeprecated) != 0;
375-
}
376-
/* Answer true if the receiver is a volatile field
377-
*/
378-
379373
@Override
380374
public final boolean isVolatile() {
381375
return (this.modifiers & ClassFileConstants.AccVolatile) != 0;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,6 @@ public boolean isParameterizedGeneric() {
981981
public boolean isPolymorphic() {
982982
return false;
983983
}
984-
/* Answer true if the receiver's declaring type is deprecated (or any of its enclosing types)
985-
*/
986-
public final boolean isViewedAsDeprecated() {
987-
return (this.modifiers & ClassFileConstants.AccDeprecated) != 0;
988-
}
989-
990984
@Override
991985
public final int kind() {
992986
return Binding.METHOD;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ void checkAgainstInheritedMethods(MethodBinding currentMethod, MethodBinding[] m
183183
if(inheritedMethod.isSynchronized() && !currentMethod.isSynchronized()) {
184184
problemReporter(currentMethod).missingSynchronizedOnInheritedMethod(currentMethod, inheritedMethod);
185185
}
186-
if (options.reportDeprecationWhenOverridingDeprecatedMethod && inheritedMethod.isViewedAsDeprecated()) {
187-
if (!currentMethod.isViewedAsDeprecated() || options.reportDeprecationInsideDeprecatedCode) {
186+
if (options.reportDeprecationWhenOverridingDeprecatedMethod && inheritedMethod.isDeprecated()) {
187+
if (!currentMethod.isDeprecated() || options.reportDeprecationInsideDeprecatedCode) {
188188
// check against the other inherited methods to see if they hide this inheritedMethod
189189
ReferenceBinding declaringClass = inheritedMethod.declaringClass;
190190
if (declaringClass.isInterface())

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,14 +1833,6 @@ public final boolean isUsed() {
18331833
return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) != 0;
18341834
}
18351835

1836-
/**
1837-
* Answer true if the receiver is deprecated (or any of its enclosing types)
1838-
*/
1839-
public final boolean isViewedAsDeprecated() {
1840-
if ((this.modifiers & ClassFileConstants.AccDeprecated) != 0)
1841-
return true;
1842-
return false;
1843-
}
18441836
public boolean isImplicitType() {
18451837
return false;
18461838
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,28 +3897,28 @@ public boolean isInsideDeprecatedCode(){
38973897
ReferenceContext referenceContext = methodScope.referenceContext();
38983898
if (referenceContext instanceof AbstractMethodDeclaration) {
38993899
MethodBinding context = ((AbstractMethodDeclaration) referenceContext).binding;
3900-
if (context != null && context.isViewedAsDeprecated())
3900+
if (context != null && context.isDeprecated())
39013901
return true;
39023902
} else if (referenceContext instanceof ModuleDeclaration) {
39033903
ModuleBinding context = ((ModuleDeclaration) referenceContext).binding;
39043904
return context != null && context.isDeprecated();
39053905
}
3906-
} else if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated()) {
3906+
} else if (methodScope.initializedField != null && methodScope.initializedField.isDeprecated()) {
39073907
// inside field declaration ? check field modifier to see if deprecated
39083908
return true;
39093909
}
39103910
SourceTypeBinding declaringType = ((BlockScope)this).referenceType().binding;
39113911
if (declaringType != null) {
39123912
declaringType.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then
3913-
if (declaringType.isViewedAsDeprecated())
3913+
if (declaringType.isDeprecated())
39143914
return true;
39153915
}
39163916
break;
39173917
case Scope.CLASS_SCOPE :
39183918
ReferenceBinding context = ((ClassScope)this).referenceType().binding;
39193919
if (context != null) {
39203920
context.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then
3921-
if (context.isViewedAsDeprecated())
3921+
if (context.isDeprecated())
39223922
return true;
39233923
}
39243924
break;
@@ -3929,7 +3929,7 @@ public boolean isInsideDeprecatedCode(){
39293929
SourceTypeBinding type = unit.types[0].binding;
39303930
if (type != null) {
39313931
type.initializeDeprecatedAnnotationTagBits(); // may not have been resolved until then
3932-
if (type.isViewedAsDeprecated())
3932+
if (type.isDeprecated())
39333933
return true;
39343934
}
39353935
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,7 @@ protected void tearDown() throws Exception {
42524252
Util.flushDirectoryContent(JAVAC_OUTPUT_DIR);
42534253
}
42544254
printJavacResultsSummary();
4255+
javacUsePathOption(" -classpath ");
42554256
}
42564257
}
42574258
/**

0 commit comments

Comments
 (0)