|
37 | 37 | * <li>the expression consists of the literal {@code null}, or |
38 | 38 | * <li>the expression consists of a single identifier, where the identifier is a formal method |
39 | 39 | * 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")}). |
41 | 46 | * </ol> |
42 | 47 | * |
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 | | - * |
46 | 48 | * <p>For example, the following code snippet is legal: |
47 | 49 | * |
48 | 50 | * <pre>{@code |
49 | 51 | * public class C { |
50 | 52 | * private static final String S = "Hello"; |
51 | | - * void m(@CompileTimeConstant final String s) { } |
| 53 | + * void m(@CompileTimeConstant final String s) {} |
52 | 54 | * void n(@CompileTimeConstant final String t) { |
53 | 55 | * m(S + " World!"); |
54 | 56 | * m(null); |
55 | 57 | * m(t); |
56 | 58 | * } |
| 59 | + * void o(boolean enabled) { |
| 60 | + * m(enabled ? "on" : "off"); |
| 61 | + * } |
57 | 62 | * } |
58 | 63 | * }</pre> |
59 | 64 | * |
60 | 65 | * <p>In contrast, the following is illegal: |
61 | 66 | * |
62 | 67 | * <pre>{@code |
63 | 68 | * public class C { |
64 | | - * void m(@CompileTimeConstant final String s) { } |
| 69 | + * void m(@CompileTimeConstant final String s) {} |
65 | 70 | * void n(String t) { |
66 | 71 | * m(t); |
67 | 72 | * } |
|
70 | 75 | * |
71 | 76 | * <p>When a class field is annotated with the {@link CompileTimeConstant} type annotation, the |
72 | 77 | * 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. |
86 | 79 | * |
87 | 80 | * <p>For example, the following code snippet is legal: |
88 | 81 | * |
89 | 82 | * <pre>{@code |
90 | 83 | * public class C { |
91 | | - * @CompileTimeConstant final String S; |
| 84 | + * @CompileTimeConstant final String s; |
92 | 85 | * public C(@CompileTimeConstant String s) { |
93 | | - * this.S = s; |
| 86 | + * this.s = s; |
94 | 87 | * } |
95 | | - * void m(@CompileTimeConstant final String s) { } |
| 88 | + * void m(@CompileTimeConstant final String s) {} |
96 | 89 | * void n() { |
97 | | - * m(S); |
| 90 | + * m(s); |
98 | 91 | * } |
99 | 92 | * } |
100 | 93 | * }</pre> |
|
132 | 125 | * compile-time-constant values in a collection. APIs will typically accommodate such use cases via |
133 | 126 | * domain-specific types that capture domain-specific aspects of trustworthiness that arise from |
134 | 127 | * values being under application control. |
| 128 | + * |
| 129 | + * <p>These constraints are enforced by <a href="https://errorprone.info">error-prone</a>. |
135 | 130 | */ |
136 | 131 | @Documented |
137 | 132 | @Retention(CLASS) |
|
0 commit comments