Skip to content

Commit 3eaba22

Browse files
committed
Java: Address review comment. Add prologue field initialization tests
1 parent 3667004 commit 3eaba22

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

java/ql/test/library-tests/flexible-constructors/FlexibleConstructors.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Outer {
3232
private final String prefix = "outer";
3333

3434
class Inner {
35-
private final String full;
35+
private String full;
3636

3737
Inner(String suffix) {
3838
var combined = prefix + "_" + suffix;
@@ -41,3 +41,40 @@ class Inner {
4141
}
4242
}
4343
}
44+
45+
class D {
46+
private final String value;
47+
private final int length;
48+
49+
D(String input) {
50+
var processed = input.toLowerCase();
51+
value = processed;
52+
this.length = processed.length();
53+
super();
54+
}
55+
}
56+
57+
class E extends A {
58+
private boolean isValid;
59+
private String processed;
60+
61+
E(String data) {
62+
var temp = data != null ? data.trim() : "";
63+
this.processed = temp;
64+
isValid = !temp.isEmpty();
65+
super(temp);
66+
}
67+
}
68+
69+
class F {
70+
private int x;
71+
private final int y;
72+
private int sum;
73+
74+
F(int a, int b) {
75+
x = a;
76+
this.y = b;
77+
this.sum = a + b;
78+
super();
79+
}
80+
}

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,93 @@ FlexibleConstructors.java:
8989
# 40| 0: [VarAccess] this.full
9090
# 40| -1: [ThisAccess] this
9191
# 40| 1: [VarAccess] combined
92+
# 45| 6: [Class] D
93+
# 46| 1: [FieldDeclaration] String value;
94+
# 46| -1: [TypeAccess] String
95+
# 47| 2: [FieldDeclaration] int length;
96+
# 47| -1: [TypeAccess] int
97+
# 49| 3: [Constructor] D
98+
#-----| 4: (Parameters)
99+
# 49| 0: [Parameter] input
100+
# 49| 0: [TypeAccess] String
101+
# 49| 5: [BlockStmt] { ... }
102+
# 50| 0: [LocalVariableDeclStmt] var ...;
103+
# 50| 1: [LocalVariableDeclExpr] processed
104+
# 50| 0: [MethodCall] toLowerCase(...)
105+
# 50| -1: [VarAccess] input
106+
# 51| 1: [ExprStmt] <Expr>;
107+
# 51| 0: [AssignExpr] ...=...
108+
# 51| 0: [VarAccess] value
109+
# 51| 1: [VarAccess] processed
110+
# 52| 2: [ExprStmt] <Expr>;
111+
# 52| 0: [AssignExpr] ...=...
112+
# 52| 0: [VarAccess] this.length
113+
# 52| -1: [ThisAccess] this
114+
# 52| 1: [MethodCall] length(...)
115+
# 52| -1: [VarAccess] processed
116+
# 53| 3: [SuperConstructorInvocationStmt] super(...)
117+
# 57| 7: [Class] E
118+
#-----| -1: (Base Types)
119+
# 57| -1: [TypeAccess] A
120+
# 58| 1: [FieldDeclaration] boolean isValid;
121+
# 58| -1: [TypeAccess] boolean
122+
# 59| 2: [FieldDeclaration] String processed;
123+
# 59| -1: [TypeAccess] String
124+
# 61| 3: [Constructor] E
125+
#-----| 4: (Parameters)
126+
# 61| 0: [Parameter] data
127+
# 61| 0: [TypeAccess] String
128+
# 61| 5: [BlockStmt] { ... }
129+
# 62| 0: [LocalVariableDeclStmt] var ...;
130+
# 62| 1: [LocalVariableDeclExpr] temp
131+
# 62| 0: [ConditionalExpr] ...?...:...
132+
# 62| 0: [NEExpr] ... != ...
133+
# 62| 0: [VarAccess] data
134+
# 62| 1: [NullLiteral] null
135+
# 62| 1: [MethodCall] trim(...)
136+
# 62| -1: [VarAccess] data
137+
# 62| 2: [StringLiteral] ""
138+
# 63| 1: [ExprStmt] <Expr>;
139+
# 63| 0: [AssignExpr] ...=...
140+
# 63| 0: [VarAccess] this.processed
141+
# 63| -1: [ThisAccess] this
142+
# 63| 1: [VarAccess] temp
143+
# 64| 2: [ExprStmt] <Expr>;
144+
# 64| 0: [AssignExpr] ...=...
145+
# 64| 0: [VarAccess] isValid
146+
# 64| 1: [LogNotExpr] !...
147+
# 64| 0: [MethodCall] isEmpty(...)
148+
# 64| -1: [VarAccess] temp
149+
# 65| 3: [SuperConstructorInvocationStmt] super(...)
150+
# 65| 0: [VarAccess] temp
151+
# 69| 8: [Class] F
152+
# 70| 1: [FieldDeclaration] int x;
153+
# 70| -1: [TypeAccess] int
154+
# 71| 2: [FieldDeclaration] int y;
155+
# 71| -1: [TypeAccess] int
156+
# 72| 3: [FieldDeclaration] int sum;
157+
# 72| -1: [TypeAccess] int
158+
# 74| 4: [Constructor] F
159+
#-----| 4: (Parameters)
160+
# 74| 0: [Parameter] a
161+
# 74| 0: [TypeAccess] int
162+
# 74| 1: [Parameter] b
163+
# 74| 0: [TypeAccess] int
164+
# 74| 5: [BlockStmt] { ... }
165+
# 75| 0: [ExprStmt] <Expr>;
166+
# 75| 0: [AssignExpr] ...=...
167+
# 75| 0: [VarAccess] x
168+
# 75| 1: [VarAccess] a
169+
# 76| 1: [ExprStmt] <Expr>;
170+
# 76| 0: [AssignExpr] ...=...
171+
# 76| 0: [VarAccess] this.y
172+
# 76| -1: [ThisAccess] this
173+
# 76| 1: [VarAccess] b
174+
# 77| 2: [ExprStmt] <Expr>;
175+
# 77| 0: [AssignExpr] ...=...
176+
# 77| 0: [VarAccess] this.sum
177+
# 77| -1: [ThisAccess] this
178+
# 77| 1: [AddExpr] ... + ...
179+
# 77| 0: [VarAccess] a
180+
# 77| 1: [VarAccess] b
181+
# 78| 3: [SuperConstructorInvocationStmt] super(...)

0 commit comments

Comments
 (0)