forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnderscoreIdentifier.ql
More file actions
36 lines (33 loc) · 1023 Bytes
/
UnderscoreIdentifier.ql
File metadata and controls
36 lines (33 loc) · 1023 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
32
33
34
35
36
/**
* @name Underscore used as identifier
* @description Use of a single underscore character as an identifier
* results in a compiler error with Java source level 9 or later.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id java/underscore-identifier
* @tags quality
* maintainability
* readability
*/
import java
class IdentifierElement extends Element {
IdentifierElement() {
this instanceof CompilationUnit or
this.(RefType).isSourceDeclaration() or
this.(Callable).isSourceDeclaration() or
this instanceof Variable
}
}
from IdentifierElement e, string msg
where
e.getCompilationUnit().isJavaSourceFile() and
not e.(Constructor).isDefaultConstructor() and
(
e.getName() = "_" and
msg = "."
or
e.(CompilationUnit).getPackage().getName().splitAt(".") = "_" and
msg = " in package name '" + e.(CompilationUnit).getPackage().getName() + "'."
)
select e, "Use of underscore as a one-character identifier" + msg