Skip to content

Commit 9065a7f

Browse files
authored
Merge pull request #7573 from tamasvajk/fix/java-field-decl-tostr
Java: Fix toString on field declarations with single field
2 parents 8a80e02 + b9e0310 commit 9065a7f

File tree

16 files changed

+55
-55
lines changed

16 files changed

+55
-55
lines changed

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class FieldDeclaration extends ExprParent, @fielddecl, Annotatable {
587587
int getNumField() { result = max(int idx | fieldDeclaredIn(_, this, idx) | idx) + 1 }
588588

589589
override string toString() {
590-
if this.getNumField() = 0
590+
if this.getNumField() = 1
591591
then result = this.getTypeAccess() + " " + this.getField(0) + ";"
592592
else result = this.getTypeAccess() + " " + this.getField(0) + ", ...;"
593593
}

java/ql/test/library-tests/JDK/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jdk/A.java:
6363
jdk/SystemGetPropertyCall.java:
6464
# 0| [CompilationUnit] SystemGetPropertyCall
6565
# 3| 1: [Class] SystemGetPropertyCall
66-
# 4| 3: [FieldDeclaration] String USER_DIR_PROPERTY, ...;
66+
# 4| 3: [FieldDeclaration] String USER_DIR_PROPERTY;
6767
# 4| -1: [TypeAccess] String
6868
# 4| 0: [StringLiteral] "user.dir"
6969
# 6| 4: [Method] a

java/ql/test/library-tests/arrays/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
arrays/A.java:
22
# 0| [CompilationUnit] A
33
# 3| 1: [Class] A
4-
# 4| 2: [FieldDeclaration] ...[] a, ...;
4+
# 4| 2: [FieldDeclaration] ...[] a;
55
# 4| -1: [ArrayTypeAccess] ...[]
66
# 4| 0: [TypeAccess] String
7-
# 5| 3: [FieldDeclaration] ...[] b, ...;
7+
# 5| 3: [FieldDeclaration] ...[] b;
88
# 5| -1: [ArrayTypeAccess] ...[]
99
# 5| 0: [ArrayTypeAccess] ...[]
1010
# 5| 0: [TypeAccess] String

java/ql/test/library-tests/collections/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ collections/Test.java:
33
#-----| -1: (Imports)
44
# 3| 1: [ImportOnDemandFromPackage] import java.util.*
55
# 5| 1: [Class] Test
6-
# 6| 3: [FieldDeclaration] Map<String,Integer> m, ...;
6+
# 6| 3: [FieldDeclaration] Map<String,Integer> m;
77
# 6| -1: [TypeAccess] Map<String,Integer>
88
# 6| 0: [TypeAccess] String
99
# 6| 1: [TypeAccess] Integer

java/ql/test/library-tests/constants/PrintAst.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ constants/Constants.java:
7070
constants/Initializers.java:
7171
# 0| [CompilationUnit] Initializers
7272
# 3| 1: [Class] Initializers
73-
# 4| 3: [FieldDeclaration] int SFIELD, ...;
73+
# 4| 3: [FieldDeclaration] int SFIELD;
7474
# 4| -1: [TypeAccess] int
7575
# 4| 0: [IntegerLiteral] 12
76-
# 6| 4: [FieldDeclaration] int IFIELD, ...;
76+
# 6| 4: [FieldDeclaration] int IFIELD;
7777
# 6| -1: [TypeAccess] int
7878
# 6| 0: [IntegerLiteral] 20
79-
# 8| 5: [FieldDeclaration] int IFIELD2, ...;
79+
# 8| 5: [FieldDeclaration] int IFIELD2;
8080
# 8| -1: [TypeAccess] int
8181
# 10| 6: [Constructor] Initializers
8282
# 10| 5: [BlockStmt] { ... }
@@ -98,17 +98,17 @@ constants/Initializers.java:
9898
# 18| 0: [AssignExpr] ...=...
9999
# 18| 0: [VarAccess] y
100100
# 18| 1: [IntegerLiteral] 400
101-
# 21| 8: [FieldDeclaration] Object SFIELD_OBJECT, ...;
101+
# 21| 8: [FieldDeclaration] Object SFIELD_OBJECT;
102102
# 21| -1: [TypeAccess] Object
103103
# 21| 0: [StringLiteral] "a string"
104-
# 23| 9: [FieldDeclaration] int fsf, ...;
104+
# 23| 9: [FieldDeclaration] int fsf;
105105
# 23| -1: [TypeAccess] int
106-
# 24| 10: [FieldDeclaration] int sf, ...;
106+
# 24| 10: [FieldDeclaration] int sf;
107107
# 24| -1: [TypeAccess] int
108108
# 24| 0: [IntegerLiteral] 3
109-
# 25| 11: [FieldDeclaration] int ff, ...;
109+
# 25| 11: [FieldDeclaration] int ff;
110110
# 25| -1: [TypeAccess] int
111-
# 26| 12: [FieldDeclaration] int f, ...;
111+
# 26| 12: [FieldDeclaration] int f;
112112
# 26| -1: [TypeAccess] int
113113
# 26| 0: [IntegerLiteral] 4
114114
# 28| 13: [BlockStmt] { ... }
@@ -135,7 +135,7 @@ constants/Values.java:
135135
#-----| -4: (Javadoc)
136136
# 3| 1: [Javadoc] /** Tests of the getIntValue() predicate */
137137
# 3| 0: [JavadocText] Tests of the getIntValue() predicate
138-
# 6| 3: [FieldDeclaration] int final_field, ...;
138+
# 6| 3: [FieldDeclaration] int final_field;
139139
# 6| -1: [TypeAccess] int
140140
# 6| 0: [IntegerLiteral] 42
141141
# 8| 4: [Method] values

java/ql/test/library-tests/constructors/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ constructors/A.java:
2020
# 11| 0: [ExprStmt] <Expr>;
2121
# 11| 0: [ClassInstanceExpr] new A(...)
2222
# 11| -3: [TypeAccess] A
23-
# 14| 6: [FieldDeclaration] String STATIC, ...;
23+
# 14| 6: [FieldDeclaration] String STATIC;
2424
# 14| -1: [TypeAccess] String
2525
# 14| 0: [StringLiteral] "static string"
26-
# 15| 7: [FieldDeclaration] String INSTANCE, ...;
26+
# 15| 7: [FieldDeclaration] String INSTANCE;
2727
# 15| -1: [TypeAccess] String
2828
# 15| 0: [StringLiteral] "instance string"
2929
# 17| 8: [BlockStmt] { ... }

java/ql/test/library-tests/dependency/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ dependency/A.java:
55
# 3| 0: [TypeVariable] T
66
# 6| 2: [Class] B
77
# 9| 3: [Class] C
8-
# 10| 2: [FieldDeclaration] A<B> b, ...;
8+
# 10| 2: [FieldDeclaration] A<B> b;
99
# 10| -1: [TypeAccess] A<B>
1010
# 10| 0: [TypeAccess] B
11-
# 11| 3: [FieldDeclaration] ...[] c, ...;
11+
# 11| 3: [FieldDeclaration] ...[] c;
1212
# 11| -1: [ArrayTypeAccess] ...[]
1313
# 11| 0: [TypeAccess] C
1414
# 14| 4: [Class] D

java/ql/test/library-tests/fields/FieldDecl.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| fields/FieldTest.java:5:9:5:39 | Object obj, ...; | 1/2 | fields/FieldTest.java:5:35:5:38 | obj2 |
66
| fields/FieldTest.java:6:9:6:58 | List<> l, ...; | 0/2 | fields/FieldTest.java:6:54:6:54 | l |
77
| fields/FieldTest.java:6:9:6:58 | List<> l, ...; | 1/2 | fields/FieldTest.java:6:57:6:57 | m |
8-
| fields/FieldTest.java:7:9:7:18 | int x, ...; | 0/1 | fields/FieldTest.java:7:13:7:13 | x |
9-
| fields/FieldTest.java:8:9:8:22 | int y, ...; | 0/1 | fields/FieldTest.java:8:13:8:13 | y |
10-
| fields/FieldTest.java:12:9:12:25 | int z, ...; | 0/1 | fields/FieldTest.java:12:20:12:20 | z |
11-
| fields/FieldTest.java:13:9:13:29 | int w, ...; | 0/1 | fields/FieldTest.java:13:20:13:20 | w |
8+
| fields/FieldTest.java:7:9:7:18 | int x; | 0/1 | fields/FieldTest.java:7:13:7:13 | x |
9+
| fields/FieldTest.java:8:9:8:22 | int y; | 0/1 | fields/FieldTest.java:8:13:8:13 | y |
10+
| fields/FieldTest.java:12:9:12:25 | int z; | 0/1 | fields/FieldTest.java:12:20:12:20 | z |
11+
| fields/FieldTest.java:13:9:13:29 | int w; | 0/1 | fields/FieldTest.java:13:20:13:20 | w |
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| List<> l, ...; | 6 | 9 | 6 | 58 |
22
| Object obj, ...; | 5 | 9 | 5 | 39 |
33
| float ff, ...; | 4 | 9 | 4 | 32 |
4-
| int w, ...; | 13 | 9 | 13 | 29 |
5-
| int x, ...; | 7 | 9 | 7 | 18 |
6-
| int y, ...; | 8 | 9 | 8 | 22 |
7-
| int z, ...; | 12 | 9 | 12 | 25 |
4+
| int w; | 13 | 9 | 13 | 29 |
5+
| int x; | 7 | 9 | 7 | 18 |
6+
| int y; | 8 | 9 | 8 | 22 |
7+
| int z; | 12 | 9 | 12 | 25 |

java/ql/test/library-tests/fields/PrintAst.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ fields/FieldTest.java:
1212
# 6| 1: [Annotation] SuppressWarnings
1313
# 6| 1: [StringLiteral] "rawtypes"
1414
# 6| -1: [TypeAccess] List<>
15-
# 7| 7: [FieldDeclaration] int x, ...;
15+
# 7| 7: [FieldDeclaration] int x;
1616
# 7| -1: [TypeAccess] int
1717
# 7| 0: [IntegerLiteral] 0
18-
# 8| 8: [FieldDeclaration] int y, ...;
18+
# 8| 8: [FieldDeclaration] int y;
1919
# 8| -1: [TypeAccess] int
2020
# 8| 0: [AssignExpr] ...=...
2121
# 8| 0: [VarAccess] x
@@ -25,10 +25,10 @@ fields/FieldTest.java:
2525
# 10| 0: [AssignExpr] ...=...
2626
# 10| 0: [VarAccess] x
2727
# 10| 1: [IntegerLiteral] 2
28-
# 12| 10: [FieldDeclaration] int z, ...;
28+
# 12| 10: [FieldDeclaration] int z;
2929
# 12| -1: [TypeAccess] int
3030
# 12| 0: [IntegerLiteral] 0
31-
# 13| 11: [FieldDeclaration] int w, ...;
31+
# 13| 11: [FieldDeclaration] int w;
3232
# 13| -1: [TypeAccess] int
3333
# 13| 0: [AssignExpr] ...=...
3434
# 13| 0: [VarAccess] z

0 commit comments

Comments
 (0)