Skip to content

Commit b841eb0

Browse files
Give state hints when the state set or methods come from the receiver's supertypes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 19991d3 commit b841eb0

13 files changed

Lines changed: 366 additions & 38 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
@StateSet({"a", "b", "c"})
7+
public class ErrorStateHintInheritedStates {
8+
9+
@StateRefinement(to = "a(this)")
10+
public ErrorStateHintInheritedStates() {}
11+
12+
@StateRefinement(from = "a(this)", to = "b(this)")
13+
public void ab() {}
14+
15+
@StateRefinement(from = "c(this)")
16+
public void useC() {}
17+
18+
public static void use() {
19+
ErrorStateHintInheritedStatesChild s = new ErrorStateHintInheritedStatesChild();
20+
s.ab();
21+
s.useC(); // Expect: State Refinement Error
22+
}
23+
}
24+
25+
// adds a transition to the states it inherits
26+
class ErrorStateHintInheritedStatesChild extends ErrorStateHintInheritedStates {
27+
28+
@StateRefinement(from = "b(this)", to = "c(this)")
29+
public void bc() {}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
@StateSet({"a", "b", "c"})
7+
public class ErrorStateHintOverride {
8+
9+
@StateRefinement(to = "a(this)")
10+
public ErrorStateHintOverride() {}
11+
12+
@StateRefinement(from = "a(this)", to = "b(this) || c(this)")
13+
public void next() {}
14+
15+
@StateRefinement(from = "c(this)")
16+
public void useC() {}
17+
18+
public static void use() {
19+
ErrorStateHintOverrideChild s = new ErrorStateHintOverrideChild();
20+
s.useC(); // Expect: State Refinement Error
21+
}
22+
}
23+
24+
// the override always moves to c, which the superclass's refinement does not promise
25+
class ErrorStateHintOverrideChild extends ErrorStateHintOverride {
26+
27+
@Override
28+
@StateRefinement(from = "a(this)", to = "c(this)")
29+
public void next() {}
30+
}

‎liquidjava-example/src/main/java/testSuite/ErrorStateHintSubclass.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void ab() {}
1616
public void useC() {}
1717

1818
public static void use() {
19-
ErrorStateHintSubclassChild s = new ErrorStateHintSubclassChild();
19+
ErrorStateHintSubclass s = new ErrorStateHintSubclassChild();
2020
s.ab();
2121
s.useC(); // Expect: State Refinement Error
2222
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package testSuite.classes.state_hints_grandchild_spec_error;
2+
3+
import javax.swing.JFrame;
4+
5+
// JFrame has no spec: its state set comes from Window's, and setUndecorated from Frame's
6+
public class Use {
7+
static void borderless() {
8+
JFrame window = new JFrame("Playfield");
9+
window.pack();
10+
window.setUndecorated(true); // Expect: State Refinement Error
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package testSuite.classes.state_hints_grandchild_spec_error;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.StateRefinement;
5+
import liquidjava.specification.StateSet;
6+
7+
@StateSet({"displayable", "notDisplayable"})
8+
@ExternalRefinementsFor("java.awt.Window")
9+
public interface WindowRefinements {
10+
@StateRefinement(to = "notDisplayable(this)")
11+
void dispose();
12+
13+
@StateRefinement(to = "displayable(this)")
14+
void pack();
15+
}
16+
17+
// the state set is declared in the superclass's spec
18+
@ExternalRefinementsFor("java.awt.Frame")
19+
interface FrameRefinements {
20+
@StateRefinement(to = "notDisplayable(this)")
21+
void Frame(String title);
22+
23+
@StateRefinement(from = "notDisplayable(this)")
24+
void setUndecorated(boolean undecorated);
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package testSuite.classes.state_hints_redeclared_method_error;
2+
3+
import java.awt.Frame;
4+
5+
public class Use {
6+
static void borderless() {
7+
Frame host = new Frame("Playfield");
8+
host.pack();
9+
host.setUndecorated(true); // Expect: State Refinement Error
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package testSuite.classes.state_hints_redeclared_method_error;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.StateRefinement;
5+
import liquidjava.specification.StateSet;
6+
7+
@StateSet({"displayable", "notDisplayable"})
8+
@ExternalRefinementsFor("java.awt.Window")
9+
public interface WindowRefinements {
10+
@StateRefinement(to = "notDisplayable(this)")
11+
void dispose();
12+
13+
@StateRefinement(to = "displayable(this)")
14+
void pack();
15+
16+
// Frame redeclares addNotify, so on a Frame the verifier does not apply this refinement
17+
@StateRefinement(to = "displayable(this)")
18+
void addNotify();
19+
}
20+
21+
@ExternalRefinementsFor("java.awt.Frame")
22+
interface FrameRefinements {
23+
@StateRefinement(to = "notDisplayable(this)")
24+
void Frame(String title);
25+
26+
@StateRefinement(from = "notDisplayable(this)")
27+
void setUndecorated(boolean undecorated);
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package testSuite.classes.state_hints_superclass_spec_error;
2+
3+
import java.awt.Frame;
4+
5+
public class Use {
6+
static void borderless() {
7+
Frame host = new Frame("Playfield");
8+
host.pack();
9+
host.setUndecorated(true); // Expect: State Refinement Error
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package testSuite.classes.state_hints_superclass_spec_error;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.StateRefinement;
5+
import liquidjava.specification.StateSet;
6+
7+
@StateSet({"displayable", "notDisplayable"})
8+
@ExternalRefinementsFor("java.awt.Window")
9+
public interface WindowRefinements {
10+
@StateRefinement(to = "notDisplayable(this)")
11+
void dispose();
12+
13+
@StateRefinement(to = "displayable(this)")
14+
void pack();
15+
}
16+
17+
// the state set is declared in the superclass's spec
18+
@ExternalRefinementsFor("java.awt.Frame")
19+
interface FrameRefinements {
20+
@StateRefinement(to = "notDisplayable(this)")
21+
void Frame(String title);
22+
23+
@StateRefinement(from = "notDisplayable(this)")
24+
void setUndecorated(boolean undecorated);
25+
}

‎liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/object_checkers/AuxHierarchyRefinementsPassage.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static void transferStateRefinements(RefinedFunction superFunction, Refi
139139
ObjectState subState = subStates.get(i);
140140

141141
String thisName = String.format(Formats.FRESH, tc.getContext().getCounter());
142-
createVariableInContext(thisName, tc, subFunction, superFunction, method.getParameters().get(i));
142+
createVariableInContext(thisName, tc, subFunction, superFunction, method);
143143

144144
Predicate superConst = matchVariableNames(thisName, superState.getFrom());
145145
Predicate subConst = matchVariableNames(thisName, superFunction, subFunction, subState.getFrom());
@@ -164,9 +164,9 @@ private static void transferStateRefinements(RefinedFunction superFunction, Refi
164164
}
165165

166166
private static void createVariableInContext(String thisName, TypeChecker tc, RefinedFunction subFunction,
167-
RefinedFunction superFunction, CtParameter<?> ctParameter) {
167+
RefinedFunction superFunction, CtMethod<?> method) {
168168
RefinedVariable rv = tc.getContext().addVarToContext(thisName,
169-
Utils.getType(subFunction.getTargetClass(), tc.getFactory()), new Predicate(), ctParameter);
169+
Utils.getType(subFunction.getTargetClass(), tc.getFactory()), new Predicate(), method);
170170
rv.addSuperType(Utils.getType(superFunction.getTargetClass(), tc.getFactory())); // TODO: change: this only
171171
// works for one superclass
172172
}

0 commit comments

Comments
 (0)