Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbbd5d7

Browse files
committed
Java: Add toString consistency query
1 parent 06d9d30 commit bbbd5d7

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java
2+
3+
string topToString(Top t) {
4+
result = t.toString()
5+
or
6+
// TypeBound doesn't extend Top (but probably should)
7+
result = t.(TypeBound).toString()
8+
or
9+
// XMLLocatable doesn't extend Top (but probably should)
10+
result = t.(XMLLocatable).toString()
11+
or
12+
// Java #142
13+
t instanceof FieldDeclaration and not exists(t.toString()) and result = "<FieldDeclaration>"
14+
or
15+
// Java #143
16+
t instanceof Javadoc and not exists(t.toString()) and result = "<Javadoc>"
17+
or
18+
// Java #144
19+
t instanceof ReflectiveAccessAnnotation and not exists(t.toString()) and result = "<ReflectiveAccessAnnotation>"
20+
}
21+
22+
string not1ToString() {
23+
exists(Top t | count(topToString(t)) != 1 and result = "Top which doesn't have exactly 1 toString: " + concat(t.getAQlClass(), ", "))
24+
or
25+
exists(Location l | count(l.toString()) != 1 and result = "Location which doesn't have exactly 1 toString: " + concat(l.getAQlClass(), ", "))
26+
or
27+
exists(Module m | count(m.toString()) != 1 and result = "Module which doesn't have exactly 1 toString: " + concat(m.getAQlClass(), ", "))
28+
or
29+
exists(Directive d | count(d.toString()) != 1 and result = "Directive which doesn't have exactly 1 toString: " + concat(d.getAQlClass(), ", "))
30+
}
31+
32+
select not1ToString()
33+

0 commit comments

Comments
 (0)