mirror of
https://github.com/github/codeql.git
synced 2026-01-25 04:12:58 +01:00
35 lines
958 B
Plaintext
35 lines
958 B
Plaintext
/**
|
|
* @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 maintainability
|
|
*/
|
|
|
|
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.fromSource() 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
|