forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLombok.qll
More file actions
224 lines (203 loc) · 6.59 KB
/
Lombok.qll
File metadata and controls
224 lines (203 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
* Provides classes and predicates for identifying use of the Lombok framework.
*/
import java
/*
* Lombok annotations.
*/
/**
* An annotation from the Lombok framework.
*/
class LombokAnnotation extends Annotation {
LombokAnnotation() {
getType().getPackage().hasName("lombok") or
getType().getPackage().getName().matches("lombok.%")
}
}
/**
* A Lombok `@NonNull` annotation.
*/
class LombokNonNullAnnotation extends LombokAnnotation {
LombokNonNullAnnotation() { getType().hasName("NonNull") }
}
/**
* A Lombok `@Cleanup` annotation.
*
* Local variable declarations annotated with `@Cleanup` are
* automatically closed by Lombok in a generated try-finally block.
*/
class LombokCleanupAnnotation extends LombokAnnotation {
LombokCleanupAnnotation() { getType().hasName("Cleanup") }
}
/**
* A Lombok `@Getter` annotation.
*
* For fields annotated with `@Getter`, Lombok automatically
* generates a corresponding getter method.
*
* For classes annotated with `@Getter`, Lombok automatically
* generates corresponding getter methods for all non-static
* fields in the annotated class, unless this behavior is
* overridden by specifying `AccessLevel.NONE` for a field.
*/
class LombokGetterAnnotation extends LombokAnnotation {
LombokGetterAnnotation() { getType().hasName("Getter") }
}
/**
* A Lombok `@Setter` annotation.
*
* For fields annotated with `@Setter`, Lombok automatically
* generates a corresponding setter method.
*
* For classes annotated with `@Setter`, Lombok automatically
* generates corresponding setter methods for all non-static
* fields in the annotated class, unless this behavior is
* overridden by specifying `AccessLevel.NONE` for a field.
*/
class LombokSetterAnnotation extends LombokAnnotation {
LombokSetterAnnotation() { getType().hasName("Setter") }
}
/**
* A Lombok `@ToString` annotation.
*
* For classes annotated with `@ToString`, Lombok automatically
* generates a `toString()` method.
*/
class LombokToStringAnnotation extends LombokAnnotation {
LombokToStringAnnotation() { getType().hasName("ToString") }
}
/**
* A Lombok `@EqualsAndHashCode` annotation.
*
* For classes annotated with `@EqualsAndHashCode`, Lombok automatically
* generates suitable `equals` and `hashCode` methods.
*/
class LombokEqualsAndHashCodeAnnotation extends LombokAnnotation {
LombokEqualsAndHashCodeAnnotation() { getType().hasName("EqualsAndHashCode") }
}
/**
* A Lombok `@NoArgsConstructor` annotation.
*
* For classes annotated with `@NoArgsConstructor`, Lombok automatically
* generates a constructor with no parameters.
*/
class LombokNoArgsConstructorAnnotation extends LombokAnnotation {
LombokNoArgsConstructorAnnotation() { getType().hasName("NoArgsConstructor") }
}
/**
* A Lombok `@RequiredArgsConstructor` annotation.
*
* For classes annotated with `@RequiredArgsConstructor`, Lombok automatically
* generates a constructor with a parameter for each non-initialized final
* field as well as any field annotated with `@NonNull` that is not initialized
* where it is declared.
*/
class LombokRequiredArgsConstructorAnnotation extends LombokAnnotation {
LombokRequiredArgsConstructorAnnotation() { getType().hasName("RequiredArgsConstructor") }
}
/**
* A Lombok `@AllArgsConstructor` annotation.
*
* For classes annotated with `@AllArgsConstructor`, Lombok automatically
* generates a constructor with a parameter for each field in the class.
*/
class LombokAllArgsConstructorAnnotation extends LombokAnnotation {
LombokAllArgsConstructorAnnotation() { getType().hasName("AllArgsConstructor") }
}
/**
* A Lombok `@Data` annotation.
*
* A shortcut for `@ToString`, `@EqualsAndHashCode`, `@Getter` on all
* fields, `@Setter` on all non-final fields, and `@RequiredArgsConstructor`.
*/
class LombokDataAnnotation extends LombokAnnotation {
LombokDataAnnotation() { getType().hasName("Data") }
}
/**
* A Lombok `@Value` annotation.
*
* Effectively a shortcut for:
*
* ```
* final @ToString @EqualsAndHashCode @AllArgsConstructor
* @FieldDefaults(makeFinal=true,level=AccessLevel.PRIVATE) @Getter
* ```
*/
class LombokValueAnnotation extends LombokAnnotation {
LombokValueAnnotation() { getType().hasName("Value") }
}
/**
* A Lombok `@Builder` annotation.
*
* For classes annotated with `@Builder`, Lombok automatically
* generates complex builder APIs for the class.
*/
class LombokBuilderAnnotation extends LombokAnnotation {
LombokBuilderAnnotation() { getType().hasName("Builder") }
}
/**
* A Lombok `@SneakyThrows` annotation.
*
* This annotation allows throwing checked exceptions
* without declaring them in a `throws` clause.
*/
class LombokSneakyThrowsAnnotation extends LombokAnnotation {
LombokSneakyThrowsAnnotation() { getType().hasName("SneakyThrows") }
}
/**
* A Lombok `@Synchronized` annotation.
*
* This annotation is treated by Lombok as a variant of the
* `synchronized` modifier. Lombok automatically generates
* suitable lock objects and `synchronized` statements for
* methods annotated with `@Synchronized`.
*/
class LombokSynchronizedAnnotation extends LombokAnnotation {
LombokSynchronizedAnnotation() { getType().hasName("Synchronized") }
}
/**
* A Lombok `@Log` annotation.
*
* For classes annotated with `@Log`, Lombok automatically
* generates a logger field named `log` with a specified type.
*/
class LombokLogAnnotation extends LombokAnnotation {
LombokLogAnnotation() { getType().hasName("Log") }
}
/*
* Elements annotated with Lombok annotations.
*/
/**
* A field for which a getter method is generated by the Lombok framework.
*
* Specifically, a field that is either directly annotated with a Lombok
* `@Getter` annotation or is declared in a class annotated with a Lombok
* `@Getter`, `@Data` or `@Value` annotation.
*/
class LombokGetterAnnotatedField extends Field {
LombokGetterAnnotatedField() {
getAnAnnotation() instanceof LombokGetterAnnotation
or
exists(LombokAnnotation a |
a instanceof LombokGetterAnnotation or
a instanceof LombokDataAnnotation or
a instanceof LombokValueAnnotation
|
a = getDeclaringType().getSourceDeclaration().getAnAnnotation()
)
}
}
/**
* A class for which `equals` and `hashCode` methods are generated
* by the Lombok framework.
*
* Specifically, a class with one of the following annotations:
* `@EqualsAndHashCode`, `@Data`, or `@Value`.
*/
class LombokEqualsAndHashCodeGeneratedClass extends Class {
LombokEqualsAndHashCodeGeneratedClass() {
getAnAnnotation() instanceof LombokEqualsAndHashCodeAnnotation or
getAnAnnotation() instanceof LombokDataAnnotation or
getAnAnnotation() instanceof LombokValueAnnotation
}
}