Skip to content

Commit f968217

Browse files
committed
Java: Deprecate RetentionAnnotation.getRetentionPolicyExpression()
1 parent 8e02d5d commit f968217

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

java/ql/lib/semmle/code/java/JDKAnnotations.qll

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,23 @@ class RetentionAnnotation extends Annotation {
5959
RetentionAnnotation() { this.getType().hasQualifiedName("java.lang.annotation", "Retention") }
6060

6161
/**
62+
* DEPRECATED: Getting the field access expression is rarely useful. Use `getRetentionPolicy()`
63+
* to get the name of the retention policy.
64+
*
6265
* Gets the retention policy expression within this annotation.
6366
*
6467
* For example, the field access `RetentionPolicy.RUNTIME` is the
6568
* retention policy expression in `@Retention(RetentionPolicy.RUNTIME)`.
6669
*/
67-
Expr getRetentionPolicyExpression() { result = this.getValue("value") }
70+
deprecated Expr getRetentionPolicyExpression() { result = this.getValue("value") }
6871

6972
/**
7073
* Gets the name of the retention policy of this annotation.
7174
*
7275
* For example, `RUNTIME` is the name of the retention policy
7376
* in `@Retention(RetentionPolicy.RUNTIME)`.
7477
*/
75-
string getRetentionPolicy() {
76-
exists(EnumConstant ec |
77-
ec = this.getRetentionPolicyExpression().(FieldRead).getField() and
78-
ec.getDeclaringType().hasQualifiedName("java.lang.annotation", "RetentionPolicy")
79-
|
80-
result = ec.getName()
81-
)
82-
}
78+
string getRetentionPolicy() { result = this.getEnumConstantValue("value").getName() }
8379
}
8480

8581
/** A `@Repeatable` annotation. */
@@ -122,11 +118,7 @@ abstract class NonReflectiveAnnotation extends Annotation { }
122118

123119
library class StandardNonReflectiveAnnotation extends NonReflectiveAnnotation {
124120
StandardNonReflectiveAnnotation() {
125-
exists(AnnotationType anntp | anntp = this.getType() |
126-
anntp.hasQualifiedName("java.lang", "Override") or
127-
anntp.hasQualifiedName("java.lang", "Deprecated") or
128-
anntp.hasQualifiedName("java.lang", "SuppressWarnings") or
129-
anntp.hasQualifiedName("java.lang", "SafeVarargs")
130-
)
121+
this.getType()
122+
.hasQualifiedName("java.lang", ["Override", "Deprecated", "SuppressWarnings", "SafeVarargs"])
131123
}
132124
}

0 commit comments

Comments
 (0)