-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNonPrivateField.ql
More file actions
31 lines (28 loc) · 897 Bytes
/
NonPrivateField.ql
File metadata and controls
31 lines (28 loc) · 897 Bytes
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
/**
* @name Non-private field
* @description A non-constant field that is not declared 'private',
* but is not accessed outside of its declaring type, may decrease code maintainability.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id java/non-private-field
* @tags quality
* maintainability
* readability
* complexity
*/
import java
class NonConstantSourceField extends Field {
NonConstantSourceField() {
this.fromSource() and
not (this.isFinal() and this.isStatic())
}
}
from NonConstantSourceField f
where
not f.isPrivate() and
not exists(VarAccess va | va.getVariable() = f |
va.getEnclosingCallable().getDeclaringType() != f.getDeclaringType()
) and
not f.getAnAnnotation() instanceof ReflectiveAccessAnnotation
select f, "This non-private field is not accessed outside of its declaring type."