mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Java: Add toString consistency query
This commit is contained in:
33
java/ql/consistency-queries/toString.ql
Normal file
33
java/ql/consistency-queries/toString.ql
Normal file
@@ -0,0 +1,33 @@
|
||||
import java
|
||||
|
||||
string topToString(Top t) {
|
||||
result = t.toString()
|
||||
or
|
||||
// TypeBound doesn't extend Top (but probably should)
|
||||
result = t.(TypeBound).toString()
|
||||
or
|
||||
// XMLLocatable doesn't extend Top (but probably should)
|
||||
result = t.(XMLLocatable).toString()
|
||||
or
|
||||
// Java #142
|
||||
t instanceof FieldDeclaration and not exists(t.toString()) and result = "<FieldDeclaration>"
|
||||
or
|
||||
// Java #143
|
||||
t instanceof Javadoc and not exists(t.toString()) and result = "<Javadoc>"
|
||||
or
|
||||
// Java #144
|
||||
t instanceof ReflectiveAccessAnnotation and not exists(t.toString()) and result = "<ReflectiveAccessAnnotation>"
|
||||
}
|
||||
|
||||
string not1ToString() {
|
||||
exists(Top t | count(topToString(t)) != 1 and result = "Top which doesn't have exactly 1 toString: " + concat(t.getAQlClass(), ", "))
|
||||
or
|
||||
exists(Location l | count(l.toString()) != 1 and result = "Location which doesn't have exactly 1 toString: " + concat(l.getAQlClass(), ", "))
|
||||
or
|
||||
exists(Module m | count(m.toString()) != 1 and result = "Module which doesn't have exactly 1 toString: " + concat(m.getAQlClass(), ", "))
|
||||
or
|
||||
exists(Directive d | count(d.toString()) != 1 and result = "Directive which doesn't have exactly 1 toString: " + concat(d.getAQlClass(), ", "))
|
||||
}
|
||||
|
||||
select not1ToString()
|
||||
|
||||
Reference in New Issue
Block a user