-
Notifications
You must be signed in to change notification settings - Fork 35
Refer return values in StateRefinements #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
15c8287
allow refence to return values in the to of state refinements for obs…
CatarinaGamboa 3bf3c79
full example
CatarinaGamboa 9ea85c7
Update liquidjava-verifier/src/main/java/liquidjava/processor/refinem…
CatarinaGamboa 1d3d515
Update liquidjava-verifier/src/main/java/liquidjava/processor/refinem…
CatarinaGamboa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
liquidjava-example/src/main/java/testSuite/CorrectIteratorReturnHasNext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.*; | ||
|
|
||
| @StateSet({"maybeEmpty", "hasNextElem", "empty"}) | ||
| public class CorrectIteratorReturnHasNext { | ||
|
|
||
| int index; | ||
| int size; | ||
|
|
||
| @StateRefinement(to = "maybeEmpty(this) && index() == 0 && size() == size") | ||
| CorrectIteratorReturnHasNext(int size) { | ||
| this.size = size; | ||
| this.index = 0; | ||
| } | ||
|
|
||
| @StateRefinement(to = "return ? hasNextElem(this) : empty(this)") | ||
| boolean hasNext() { | ||
| return index < size; | ||
| } | ||
|
|
||
| @StateRefinement(from = "hasNextElem(this)", to = "maybeEmpty(this) && index() == index(old(this)) + 1 && size() == size(old(this))") | ||
| int next() { | ||
| index += 1; | ||
| return index; // return index++; does not work | ||
| } | ||
|
|
||
| int main1() { | ||
| CorrectIteratorReturnHasNext it = new CorrectIteratorReturnHasNext(5); | ||
| int sum = 0; | ||
| while (true){ | ||
| if(it.hasNext()){ | ||
| sum += it.next(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
liquidjava-example/src/main/java/testSuite/ErrorIteratorReturnHasNext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.*; | ||
|
|
||
| @StateSet({"maybeEmpty", "hasNextElem", "empty"}) | ||
| public class ErrorIteratorReturnHasNext { | ||
| int index; | ||
| int size; | ||
|
|
||
| @StateRefinement(to = "maybeEmpty(this) && index() == 0 && size() == size") | ||
| ErrorIteratorReturnHasNext(int size) { | ||
| this.size = size; | ||
| this.index = 0; | ||
| } | ||
|
|
||
| @StateRefinement(to = "return ? hasNextElem(this) : empty(this)") | ||
| boolean hasNext() { | ||
| return index < size; | ||
| } | ||
|
|
||
| @StateRefinement(from = "hasNextElem(this)", to = "maybeEmpty(this) && index() == index(old(this)) + 1 && size() == size(old(this))") | ||
| int next() { | ||
| index += 1; | ||
| return index; // return index++; does not work | ||
| } | ||
|
|
||
|
|
||
| void main1() { | ||
| ErrorIteratorReturnHasNext it = new ErrorIteratorReturnHasNext(5); | ||
| if(it.hasNext()){ | ||
| it.next(); | ||
| } else { | ||
| it.next(); // State Refinement Error | ||
| } | ||
| } | ||
|
|
||
| void main2() { | ||
| ErrorIteratorReturnHasNext it = new ErrorIteratorReturnHasNext(5); | ||
| it.next(); // State Refinement Error | ||
| } | ||
|
|
||
| int main3() { | ||
| ErrorIteratorReturnHasNext it = new ErrorIteratorReturnHasNext(5); | ||
| int sum = 0; | ||
| while (true){ | ||
| if(!it.hasNext()){ | ||
| sum += it.next(); // State Refinement Error | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...le/src/main/java/testSuite/classes/image_params_so_error/ImageWriteParamsRefinements.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package testSuite.classes.image_params_so_error; | ||
|
|
||
|
|
||
|
|
||
| import java.util.Locale; | ||
| import liquidjava.specification.*; | ||
| import javax.imageio.ImageWriteParam; | ||
|
|
||
| @ExternalRefinementsFor("javax.imageio.ImageWriteParam") | ||
|
|
||
| @StateSet({"start", "acceptCompression", "compressionExplicit", "compressionSet"}) | ||
| @RefinementAlias("Ratio(float v) { 0 <= v && v <= 1.0 }") | ||
| public interface ImageWriteParamsRefinements { | ||
|
|
||
| @StateRefinement(to="start(this)") | ||
| void ImageWriteParam(Locale locale); | ||
|
|
||
| void setProgressiveMode( | ||
| @Refinement("ImageWriteParam.MODE_DISABLED == mode || mode == ImageWriteParam.MODE_DEFAULT || mode == ImageWriteParam.MODE_COPY_FROM_METADATA") | ||
| int mode | ||
| ); | ||
|
|
||
| @StateRefinement(from= "compressionExplicit() || compressionSet()", | ||
| to = "mode == ImageWriteParam.MODE_EXPLICIT ? compressionExplicit(this) : start(this)") | ||
| @StateRefinement(from="acceptCompression()", | ||
| to = "mode == ImageWriteParam.MODE_EXPLICIT ? compressionExplicit(this) : acceptCompression(this)") | ||
| void setCompressionMode(int mode); | ||
|
|
||
| @StateRefinement(from="compressionExplicit() || compressionSet()") | ||
| void setCompressionQuality(@Refinement("Ratio(_)") float quality); | ||
|
|
||
| @StateRefinement(from = "start(this)", | ||
| to = "return ? acceptCompression(this) : start(this)") | ||
| boolean canWriteCompressed(); | ||
| } |
49 changes: 49 additions & 0 deletions
49
liquidjava-example/src/main/java/testSuite/classes/image_params_so_error/JpegExporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package testSuite.classes.image_params_so_error; | ||
| import java.awt.image.RenderedImage; | ||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.util.Locale; | ||
|
|
||
| import javax.imageio.IIOImage; | ||
| import javax.imageio.ImageIO; | ||
| import javax.imageio.ImageWriteParam; | ||
| import javax.imageio.ImageWriter; | ||
| import javax.imageio.stream.ImageOutputStream; | ||
| import java.util.Iterator; | ||
|
|
||
| class JpegExporter { | ||
|
|
||
| // Adapted from https://stackoverflow.com/questions/72024965/how-to-compress-jpg-and-png-images-in-java | ||
| ImageWriteParam setCompressionPreferences() { | ||
| ImageWriteParam param = new ImageWriteParam(Locale.getDefault()); | ||
| if (param.canWriteCompressed()) { | ||
| param.setCompressionMode(ImageWriteParam.MODE_DEFAULT); | ||
| param.setCompressionQuality(0.85f); // State Refinement Error | ||
| } | ||
| return param; | ||
| } | ||
|
|
||
| public String compressImage(File multipartFile, RenderedImage image) throws IOException { | ||
| String filePath = System.getProperty("java.io.tmpdir"); | ||
| File compressedImageFile = new File(filePath); | ||
| OutputStream os = new FileOutputStream(compressedImageFile.getName()); | ||
| String extension = multipartFile.getName().substring(multipartFile.getName().lastIndexOf('.') + 1); | ||
| Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(extension); | ||
| ImageWriter writer = writers.next(); | ||
|
|
||
| ImageOutputStream ios = ImageIO.createImageOutputStream(os); | ||
| writer.setOutput(ios); | ||
|
|
||
| ImageWriteParam param = writer.getDefaultWriteParam(); | ||
| param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); // State Refinement Error | ||
| param.setCompressionQuality(0.5f); | ||
|
|
||
| writer.write(null, new IIOImage(image, null, null), param); | ||
| os.close(); | ||
| ios.close(); | ||
| writer.dispose(); | ||
| return String.valueOf(compressedImageFile); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.