Skip to content

Commit 58e5bb8

Browse files
graememorganError Prone Team
authored andcommitted
Update and wordsmith the @CompileTimeConstant documentation to reflect changes to the checker.
PiperOrigin-RevId: 566924090
1 parent a8a64b6 commit 58e5bb8

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

annotations/src/main/java/com/google/errorprone/annotations/CompileTimeConstant.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,36 @@
3737
* <li>the expression consists of the literal {@code null}, or
3838
* <li>the expression consists of a single identifier, where the identifier is a formal method
3939
* parameter or class field that is declared {@code final} and has the {@link
40-
* CompileTimeConstant} annotation.
40+
* CompileTimeConstant} annotation, or
41+
* <li>the expression is a {@link String}, and formed from the concatenation of symbols which meet
42+
* these conditions, or
43+
* <li>the expression is a ternary condition, where both branches satisfy these conditions, or
44+
* <li>the expression is an immutable collection with all values known to satisfy these conditions
45+
* (for example, {@code ImmutableSet.of("a", "b", "c")}).
4146
* </ol>
4247
*
43-
* <p>This constraint on call sites of methods or constructors that have one or more formal
44-
* parameters with this annotation is enforced by <a href="https://errorprone.info">error-prone</a>.
45-
*
4648
* <p>For example, the following code snippet is legal:
4749
*
4850
* <pre>{@code
4951
* public class C {
5052
* private static final String S = "Hello";
51-
* void m(@CompileTimeConstant final String s) { }
53+
* void m(@CompileTimeConstant final String s) {}
5254
* void n(@CompileTimeConstant final String t) {
5355
* m(S + " World!");
5456
* m(null);
5557
* m(t);
5658
* }
59+
* void o(boolean enabled) {
60+
* m(enabled ? "on" : "off");
61+
* }
5762
* }
5863
* }</pre>
5964
*
6065
* <p>In contrast, the following is illegal:
6166
*
6267
* <pre>{@code
6368
* public class C {
64-
* void m(@CompileTimeConstant final String s) { }
69+
* void m(@CompileTimeConstant final String s) {}
6570
* void n(String t) {
6671
* m(t);
6772
* }
@@ -70,31 +75,19 @@
7075
*
7176
* <p>When a class field is annotated with the {@link CompileTimeConstant} type annotation, the
7277
* field must also be declared to be {@code final}, and the corresponding initialised value must be
73-
* an expression that satisfies one of the following conditions:
74-
*
75-
* <ol>
76-
* <li>The expression is one for which the Java compiler can determine a constant value at compile
77-
* time, or
78-
* <li>the expression consists of the literal {@code null}, or
79-
* <li>the expression consists of a single identifier, where the identifier is a formal method
80-
* parameter or class field that is declared {@code final} and has the {@link
81-
* CompileTimeConstant} annotation.
82-
* </ol>
83-
*
84-
* <p>This constraint on fields with this annotation is enforced by <a
85-
* href="https://errorprone.info">error-prone</a>.
78+
* an expression that satisfies the conditions above.
8679
*
8780
* <p>For example, the following code snippet is legal:
8881
*
8982
* <pre>{@code
9083
* public class C {
91-
* @CompileTimeConstant final String S;
84+
* @CompileTimeConstant final String s;
9285
* public C(@CompileTimeConstant String s) {
93-
* this.S = s;
86+
* this.s = s;
9487
* }
95-
* void m(@CompileTimeConstant final String s) { }
88+
* void m(@CompileTimeConstant final String s) {}
9689
* void n() {
97-
* m(S);
90+
* m(s);
9891
* }
9992
* }
10093
* }</pre>
@@ -132,6 +125,8 @@
132125
* compile-time-constant values in a collection. APIs will typically accommodate such use cases via
133126
* domain-specific types that capture domain-specific aspects of trustworthiness that arise from
134127
* values being under application control.
128+
*
129+
* <p>These constraints are enforced by <a href="https://errorprone.info">error-prone</a>.
135130
*/
136131
@Documented
137132
@Retention(CLASS)

0 commit comments

Comments
 (0)