Skip to content

Commit 1370c86

Browse files
committed
Merge branch 'main' into improve-test-suite
2 parents 4c87a77 + 1b9d5ac commit 1370c86

35 files changed

+542
-137
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
@SuppressWarnings("unused")
6+
class CorrectEnumField {
7+
enum Color {
8+
Red, Green, Blue
9+
}
10+
11+
@Refinement("color != Color.Blue")
12+
Color color;
13+
14+
void setColor(@Refinement("c != Color.Blue") Color c) {
15+
color = c;
16+
}
17+
18+
public static void main(String[] args) {
19+
CorrectEnumField cef = new CorrectEnumField();
20+
cef.setColor(Color.Red); // correct
21+
cef.setColor(Color.Green); // correct
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
@SuppressWarnings("unused")
6+
class CorrectEnumParam {
7+
enum Status {
8+
Active, Inactive, Pending
9+
}
10+
11+
Status process(@Refinement("status == Status.Inactive") Status status) {
12+
return Status.Active;
13+
}
14+
15+
public static void main(String[] args) {
16+
CorrectEnumParam cep = new CorrectEnumParam();
17+
cep.process(Status.Inactive); // correct
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
class CorrectEnumRefinement {
6+
enum Lever {
7+
Up, Down, Middle
8+
}
9+
10+
public static void main(String[] args) {
11+
@Refinement("_==Lever.Up || _==Lever.Down")
12+
Lever lever = Lever.Up;
13+
System.out.println(lever);
14+
}
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
@SuppressWarnings("unused")
7+
@StateSet({"photoMode", "videoMode", "noMode"})
8+
class CorrectEnumUsage {
9+
enum Mode {
10+
Photo, Video, Unknown
11+
}
12+
13+
Mode mode;
14+
@StateRefinement(to="noMode(this)")
15+
public CorrectEnumUsage() {}
16+
17+
@StateRefinement(from="noMode(this) && mode == Mode.Photo", to="photoMode(this)")
18+
@StateRefinement(from="noMode(this) && mode == Mode.Video", to="videoMode(this)")
19+
public void setMode(Mode mode) {
20+
this.mode = mode;
21+
}
22+
23+
@StateRefinement(from="photoMode(this)", to="noMode(this)")
24+
@StateRefinement(from="videoMode(this)", to="noMode(this)")
25+
public void resetMode() {
26+
this.mode = null;
27+
}
28+
29+
@StateRefinement(from="photoMode(this)")
30+
public void takePhoto() {}
31+
32+
@StateRefinement(from="videoMode(this)")
33+
public void takeVideo() {}
34+
35+
36+
public static void main(String[] args) {
37+
// Correct
38+
CorrectEnumUsage st = new CorrectEnumUsage();
39+
st.setMode(Mode.Photo); // noMode -> photoMode
40+
st.takePhoto();
41+
st.resetMode(); // photoMode -> noMode
42+
st.setMode(Mode.Video); // noMode -> videoMode
43+
st.takeVideo();
44+
}
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Refinement Error
2+
package testSuite;
3+
4+
import liquidjava.specification.Refinement;
5+
6+
@SuppressWarnings("unused")
7+
class ErrorEnumFunctionRefinement {
8+
enum Color { Red, Green, Blue }
9+
10+
Color c;
11+
12+
Color changeColor(@Refinement("newColor == Color.Red || newColor == Color.Green") Color newColor) {
13+
c = newColor; // correct
14+
return c;
15+
}
16+
17+
public static void main(String[] args) {
18+
ErrorEnumFunctionRefinement e = new ErrorEnumFunctionRefinement();
19+
e.changeColor(Color.Red); // correct
20+
e.changeColor(Color.Blue); // error
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Refinement Error
2+
package testSuite;
3+
4+
import liquidjava.specification.Refinement;
5+
6+
@SuppressWarnings("unused")
7+
class ErrorEnumNegation {
8+
enum Status {
9+
Active, Inactive, Pending
10+
}
11+
12+
void process(@Refinement("status != Status.Inactive") Status status) {}
13+
14+
public static void main(String[] args) {
15+
ErrorEnumNegation e = new ErrorEnumNegation();
16+
e.process(Status.Active); // correct
17+
e.process(Status.Inactive); // error
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Refinement Error
2+
package testSuite;
3+
4+
import liquidjava.specification.Refinement;
5+
6+
@SuppressWarnings("unused")
7+
class ErrorEnumNull {
8+
enum Color {
9+
Red, Green, Blue
10+
}
11+
12+
public static void main(String[] args) {
13+
@Refinement("c == Color.Red || c == Color.Green")
14+
Color c = null; // error
15+
}
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// State Refinement Error
2+
package testSuite;
3+
4+
import liquidjava.specification.StateRefinement;
5+
import liquidjava.specification.StateSet;
6+
7+
8+
@SuppressWarnings("unused")
9+
@StateSet({"photoMode", "videoMode", "noMode"})
10+
class ErrorEnumUsage {
11+
enum Mode {
12+
Photo, Video, Unknown
13+
}
14+
15+
Mode mode;
16+
@StateRefinement(to="noMode(this)")
17+
public ErrorEnumUsage() {}
18+
19+
@StateRefinement(from="noMode(this) && mode == Mode.Photo", to="photoMode(this)")
20+
@StateRefinement(from="noMode(this) && mode == Mode.Video", to="videoMode(this)")
21+
public void setMode(Mode mode) {
22+
this.mode = mode;
23+
}
24+
25+
@StateRefinement(from="photoMode(this)")
26+
public void takePhoto() {}
27+
28+
29+
public static void main(String[] args) {
30+
// Correct
31+
ErrorEnumUsage st = new ErrorEnumUsage();
32+
st.setMode(Mode.Video);
33+
st.takePhoto(); //error
34+
}
35+
}

liquidjava-verifier/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>io.github.liquid-java</groupId>
1313
<artifactId>liquidjava-verifier</artifactId>
14-
<version>0.0.14</version>
14+
<version>0.0.16</version>
1515
<name>liquidjava-verifier</name>
1616
<description>LiquidJava Verifier</description>
1717
<url>https://github.com/liquid-java/liquidjava</url>

liquidjava-verifier/src/main/antlr4/rj/grammar/RJ.g4

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ literalExpression:
3838
| literal #lit
3939
| ID #var
4040
| functionCall #invocation
41+
| enumerate #enum
4142
;
4243

43-
functionCall:
44+
functionCall:
4445
ghostCall
4546
| aliasCall
46-
| dotCall;
47+
| dotCall
48+
;
4749

4850
dotCall:
4951
OBJECT_TYPE '(' args? ')'
@@ -55,6 +57,9 @@ ghostCall:
5557
aliasCall:
5658
ID_UPPER '(' args? ')';
5759

60+
enumerate:
61+
ENUM;
62+
5863
args: pred (',' pred)* ;
5964

6065

@@ -94,6 +99,7 @@ ARITHOP : '+'|'*'|'/'|'%';//|'-';
9499

95100
BOOL : 'true' | 'false';
96101
ID_UPPER: ([A-Z][a-zA-Z0-9]*);
102+
ENUM: [A-Z][a-zA-Z0-9_]* '.' [A-Z][a-zA-Z0-9_]*;
97103
OBJECT_TYPE:
98104
(([a-zA-Z][a-zA-Z0-9]+) ('.' [a-zA-Z][a-zA-Z0-9]*)+);
99105
ID : '#'*[a-zA-Z_][a-zA-Z0-9_#]*;

0 commit comments

Comments
 (0)