Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into refactor-refinement-predicate
  • Loading branch information
rcosta358 committed Apr 11, 2026
commit cd78b7aef34ae036b1970a3e6143465aa41d8cd5
11 changes: 10 additions & 1 deletion liquidjava-api/src/main/java/liquidjava/specification/Ghost.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(GhostMultiple.class)
@Repeatable(Ghost.Multiple.class)
public @interface Ghost {

/**
Expand All @@ -40,4 +40,13 @@
* </pre>
*/
String value();

/**
* Container annotation used by {@link Repeatable} to support multiple ghost declarations.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Multiple {
Ghost[] value();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(RefinementAliasMultiple.class)
@Repeatable(RefinementAlias.Multiple.class)
public @interface RefinementAlias {

/**
Expand All @@ -42,4 +42,13 @@
* </pre>
*/
String value();

/**
* Container annotation used by {@link Repeatable} to support multiple refinement aliases.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Multiple {
RefinementAlias[] value();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(RefinementPredicateMultiple.class)
@Repeatable(RefinementPredicate.Multiple.class)
public @interface RefinementPredicate {

/**
Expand All @@ -43,4 +43,13 @@
* </pre>
*/
String value();

/**
* Container annotation used by {@link Repeatable} to support multiple refinement predicates.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Multiple {
RefinementPredicate[] value();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Repeatable(StateRefinementMultiple.class)
@Repeatable(StateRefinement.Multiple.class)
public @interface StateRefinement {

/**
Expand Down Expand Up @@ -66,4 +66,13 @@
* </pre>
*/
String msg() default "";

/**
* Container annotation used by {@link Repeatable} to support multiple state transitions.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@interface Multiple {
StateRefinement[] value();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(StateSets.class)
@Repeatable(StateSet.Multiple.class)
public @interface StateSet {

/**
Expand All @@ -42,4 +42,13 @@
* </pre>
*/
String[] value();

/**
* Container annotation used by {@link Repeatable} to support multiple state sets.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Multiple {
StateSet[] value();
}
}

This file was deleted.

23 changes: 23 additions & 0 deletions liquidjava-example/src/main/java/testSuite/CorrectEnumField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package testSuite;

import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
class CorrectEnumField {
enum Color {
Red, Green, Blue
}

@Refinement("color != Color.Blue")
Color color;

void setColor(@Refinement("c != Color.Blue") Color c) {
color = c;
}

public static void main(String[] args) {
CorrectEnumField cef = new CorrectEnumField();
cef.setColor(Color.Red); // correct
cef.setColor(Color.Green); // correct
}
}
19 changes: 19 additions & 0 deletions liquidjava-example/src/main/java/testSuite/CorrectEnumParam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package testSuite;

import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
class CorrectEnumParam {
enum Status {
Active, Inactive, Pending
}

Status process(@Refinement("status == Status.Inactive") Status status) {
return Status.Active;
}

public static void main(String[] args) {
CorrectEnumParam cep = new CorrectEnumParam();
cep.process(Status.Inactive); // correct
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testSuite;

import liquidjava.specification.Refinement;

class CorrectEnumRefinement {
enum Lever {
Up, Down, Middle
}

public static void main(String[] args) {
@Refinement("_==Lever.Up || _==Lever.Down")
Lever lever = Lever.Up;
System.out.println(lever);
}
}
45 changes: 45 additions & 0 deletions liquidjava-example/src/main/java/testSuite/CorrectEnumUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package testSuite;

import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;

@SuppressWarnings("unused")
@StateSet({"photoMode", "videoMode", "noMode"})
class CorrectEnumUsage {
enum Mode {
Photo, Video, Unknown
}

Mode mode;
@StateRefinement(to="noMode(this)")
public CorrectEnumUsage() {}

@StateRefinement(from="noMode(this) && mode == Mode.Photo", to="photoMode(this)")
@StateRefinement(from="noMode(this) && mode == Mode.Video", to="videoMode(this)")
public void setMode(Mode mode) {
this.mode = mode;
}

@StateRefinement(from="photoMode(this)", to="noMode(this)")
@StateRefinement(from="videoMode(this)", to="noMode(this)")
public void resetMode() {
this.mode = null;
}

@StateRefinement(from="photoMode(this)")
public void takePhoto() {}

@StateRefinement(from="videoMode(this)")
public void takeVideo() {}


public static void main(String[] args) {
// Correct
CorrectEnumUsage st = new CorrectEnumUsage();
st.setMode(Mode.Photo); // noMode -> photoMode
st.takePhoto();
st.resetMode(); // photoMode -> noMode
st.setMode(Mode.Video); // noMode -> videoMode
st.takeVideo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package testSuite;

import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
class ErrorEnumFunctionRefinement {
enum Color {
Red, Green, Blue
}

Color c;

Color changeColor(@Refinement("newColor == Color.Red || newColor == Color.Green") Color newColor) {
c = newColor;
return c;
}

public static void main(String[] args) {
ErrorEnumFunctionRefinement e = new ErrorEnumFunctionRefinement();
e.changeColor(Color.Red);
e.changeColor(Color.Blue); // Refinement Error
}
}
18 changes: 18 additions & 0 deletions liquidjava-example/src/main/java/testSuite/ErrorEnumNegation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testSuite;

import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
class ErrorEnumNegation {
enum Status {
Active, Inactive, Pending
}

void process(@Refinement("status != Status.Inactive") Status status) {}

public static void main(String[] args) {
ErrorEnumNegation e = new ErrorEnumNegation();
e.process(Status.Active);
e.process(Status.Inactive); // Refinement Error
}
}
15 changes: 15 additions & 0 deletions liquidjava-example/src/main/java/testSuite/ErrorEnumNull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testSuite;

import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
class ErrorEnumNull {
enum Color {
Red, Green, Blue
}

public static void main(String[] args) {
@Refinement("c == Color.Red || c == Color.Green")
Color c = null; // Refinement Error
}
}
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.