-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
855 lines (778 loc) · 36.7 KB
/
index.html
File metadata and controls
855 lines (778 loc) · 36.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<!--
Author: W3layouts
Author URL: http://w3layouts.com
-->
<!doctype html>
<html lang="en">
<head>
<link rel="icon" type="image/jpg" href="assets/images/iconLJ.png" sizes="228x228" />
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Liquid Java</title>
<!-- web fonts -->
<link href="//fonts.googleapis.com/css?family=Nunito:400,600,700,800,900&display=swap" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Hind&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
<!-- //web fonts -->
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Mermaid for state diagrams in the examples gallery -->
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js" defer></script>
<!-- Prism (Monokai theme) for code syntax highlighting in the gallery -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-okaidia.min.css" rel="stylesheet">
<!-- Template CSS (must load AFTER Prism so our font-size overrides win) -->
<link rel="stylesheet" href="assets/css/style-starter.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-clike.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-java.min.js" defer></script>
</head>
<body>
<!-- <section class="w3l-bootstrap-header">
<nav class="navbar navbar-expand-lg navbar-light py-lg-3 py-2">
<div class="container">
<a class="navbar-brand" href="index.html">Catarina Gamboa</a> -->
<!-- if logo is image enable this
<a class="navbar-brand" href="#index.html">
<img src="image-path" alt="Your logo" title="Your logo" style="height:35px;" />
</a> -->
<!-- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon fa fa-bars"></span>
</button> -->
<!-- <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="projects.html">Papers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="activities.html">Other Activities</a>
</li>
</ul>
</div> -->
<!-- </div>
</nav>
</section> -->
<!-- <section class="w3l-about-breadcrum">
<div class="breadcrum-bg">
<div class="container py-5">
<p> <br/><!--<a href="index.html">Home</a> / About--></p>
</div>
</div>
</section>
<!-- w3l-content-photo-5 -->
<div class="w3l-content-photo-5 py-5" id="about">
<div class="content-main pt-lg-5 pt-md-3 pb-0" style='padding-top: 0rem !important;'>
<div class="container">
<div style='text-align: right;'>
<p>Project developed at
<img src="assets/images/logos.png" alt="Logo" width="50%">
<!-- <img src="assets/images/normal.png" alt="Lasige logo" width="150" height="55">
<img src="assets/images/ciencias_ul_azul_h_s-ass.png" alt="FCUL logo" width="100" height="40"> -->
<!-- Add lasige and FCUL logo -->
</p>
</div>
<br/><br/><br/>
<div class="row">
<div class="col-lg-5 content-photo">
<a href="#"><img src="assets/images/Liquid2.png" class="img-fluid" alt="content-photo"></a>
</div>
<div class="col-lg-7 content-left mt-lg-0 mt-5 pl-lg-5">
<h3>Extending Java with <br/>Liquid Types</h3>
<p class="mb-0">
<b>Extend your Java code with Refinement Types and catch bugs earlier!</b><br/>
LiquidJava implements an additional type system with Refinement Types on top of Java.
It allows developers to express better restrictions on the code and discover more bugs before executing the program.
</p>
</div>
</div>
<br/><br/>
<br/>
<div class="row">
<div class="col-lg-2 content-left mt-lg-0 mt-5 pl-lg-5">
</div>
<div class="col-lg-7 content-left mt-lg-0 mt-5 pl-lg-5">
<div class="iframe_container">
<iframe class="responsive-iframe" src="https://www.youtube-nocookie.com/embed/MOZESsOtUAU" title="YouTube video player" style="border:0;" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div>
</div>
</div>
<br/><br/><br/>
<div class="row">
<div class="col-lg-12 content-left mt-lg-0 mt-5 pl-lg-5">
<h4><b>Learn more</b> about LiquidJava!</h4>
<div class="lj-resources">
<a class="lj-resource-card" href="https://github.com/liquid-java" target="_blank" rel="noopener">
<span class="lj-resource-icon fa fa-github" aria-hidden="true"></span>
<span class="lj-resource-title">GitHub organization</span>
<span class="lj-resource-sub">Verifier, API, examples, external libs — all in one place.</span>
</a>
<a class="lj-resource-card" href="https://liquid-java.github.io/liquidjava-docs/" target="_blank" rel="noopener">
<span class="lj-resource-icon fa fa-book" aria-hidden="true"></span>
<span class="lj-resource-title">Documentation</span>
<span class="lj-resource-sub">Annotation reference and language guide.</span>
</a>
<a class="lj-resource-card" href="https://github.com/liquid-java/liquidjava-tutorial" target="_blank" rel="noopener">
<span class="lj-resource-icon fa fa-graduation-cap" aria-hidden="true"></span>
<span class="lj-resource-title">Tutorial</span>
<span class="lj-resource-sub">Hands-on walkthrough — learn LiquidJava by example.</span>
</a>
<a class="lj-resource-card" href="https://dl.acm.org/doi/abs/10.1109/ICSE48619.2023.00132" target="_blank" rel="noopener">
<span class="lj-resource-icon fa fa-file-text-o" aria-hidden="true"></span>
<span class="lj-resource-title">Research paper</span>
<span class="lj-resource-sub">Usability-Oriented Design of Liquid Types for Java — ICSE 2023.</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<section class="w3l-feature-code lj-install" id="features">
<div class="grid top-bottom">
<div class="container">
<div class="lj-install-head">
<span class="lj-install-eyebrow">Get started</span>
<h3 class="lj-install-title">Refine your Java in three steps</h3>
<p class="lj-install-lede">
The LiquidJava plugin runs inside Visual Studio Code and gives you inline diagnostics
as you type — no separate verifier window to babysit.
</p>
<div class="lj-install-cta">
<a class="lj-install-btn lj-install-btn--primary"
href="https://marketplace.visualstudio.com/items?itemName=AlcidesFonseca.liquid-java"
target="_blank" rel="noopener">
<span class="fa fa-download" aria-hidden="true"></span>
Install for VS Code
</a>
<a class="lj-install-btn lj-install-btn--secondary"
href="https://open-vsx.org/extension/AlcidesFonseca/liquid-java"
target="_blank" rel="noopener">
Get on Open VSX
</a>
</div>
</div>
<ol class="lj-steps">
<li class="lj-step">
<span class="lj-step-num">1</span>
<h5 class="lj-step-title">Set up your toolchain</h5>
<p class="lj-step-desc">You'll need the basics installed first.</p>
<ul class="lj-step-reqs">
<li><a href="https://code.visualstudio.com/#alt-downloads" target="_blank" rel="noopener">Visual Studio Code <span class="fa fa-external-link" aria-hidden="true"></span></a></li>
<li><a href="https://www.oracle.com/java/technologies/downloads/#java20" target="_blank" rel="noopener">JDK 20 <span class="fa fa-external-link" aria-hidden="true"></span></a></li>
<li><a href="https://marketplace.visualstudio.com/items?itemName=redhat.java" target="_blank" rel="noopener">Red Hat Java extension <span class="fa fa-external-link" aria-hidden="true"></span></a></li>
</ul>
</li>
<li class="lj-step">
<span class="lj-step-num">2</span>
<h5 class="lj-step-title">Install the plugin</h5>
<p class="lj-step-desc">
One click from the Marketplace, or search <code class="lj-step-code">LiquidJava</code> inside VS Code's extensions panel.
</p>
</li>
<li class="lj-step">
<span class="lj-step-num">3</span>
<h5 class="lj-step-title">Add the API to your project</h5>
<p class="lj-step-desc">
Drop the LiquidJava API dependency into your build, sprinkle <code class="lj-step-code">@Refinement</code> annotations, and watch the diagnostics light up.
</p>
<p class="lj-step-links">
<a href="https://github.com/liquid-java/liquidjava-docs" target="_blank" rel="noopener">Maven / Gradle setup →</a>
<a href="https://github.com/liquid-java/liquidjava-tutorial" target="_blank" rel="noopener">Tutorial guide →</a>
</p>
</li>
</ol>
</div>
</div>
</section>
<section class="w3l-about lj-pred-section">
<div class="container py-md-4 py-3">
<header class="lj-pred-header">
<span class="lj-eyebrow-mini">Reference</span>
<h3 class="lj-pred-title">Predicates</h3>
<p class="lj-pred-lede">
Refinement Types extend the language with predicates over basic types.
<code class="lj-inline">@Refinement("x > 0") int x;</code> declares an
<code class="lj-inline">int</code> refined by <code class="lj-inline">x > 0</code>.
Predicates live in <i>quantifier-free linear integer arithmetic</i>.
</p>
</header>
<div class="lj-pred-picker">
<label class="lj-pred-pickerlabel" for="ljPredSelect">Browse predicates</label>
<select id="ljPredSelect" class="lj-pred-select">
<optgroup label="Operators">
<option value="op-eq">== Equals</option>
<option value="op-neq">!= Different</option>
<option value="op-ineq">< <= > >= Inequalities</option>
<option value="op-not">! Negate</option>
<option value="op-and">&& And</option>
<option value="op-or">|| Or</option>
<option value="op-add">+ − Add & subtract</option>
<option value="op-mul">* / % Multiplicative</option>
<option value="op-wild">_ This-variable wildcard</option>
<option value="op-ite">? : If-then-else</option>
</optgroup>
<optgroup label="Aliases">
<option value="al-def">@RefinementAlias Define</option>
<option value="al-use">Percentage(_) Apply</option>
</optgroup>
<optgroup label="Object state & ghost">
<option value="st-set">@StateSet Class states</option>
<option value="st-ref">@StateRefinement Use states</option>
<option value="st-ghost">@Ghost Class ghost</option>
<option value="st-old">old(this) Use ghost</option>
</optgroup>
</select>
</div>
<article class="lj-pred-card lj-pred-card--single" id="ljPredCard">
<div class="lj-pred-meta">
<span class="lj-pred-glyph" id="ljPredGlyph"></span>
<span class="lj-pred-name" id="ljPredName"></span>
</div>
<p class="lj-pred-blurb" id="ljPredBlurb"></p>
<pre class="lj-pred-code"><code class="language-java" id="ljPredCode"></code></pre>
</article>
<script>
(function () {
var preds = {
'op-eq': { group: 'Operators', glyph: '==', name: 'Equals',
blurb: '', code: '@Refinement("x == 0")\nint x;' },
'op-neq': { group: 'Operators', glyph: '!=', name: 'Different',
blurb: '', code: '@Refinement("x != 0")\nint x;' },
'op-ineq': { group: 'Operators', glyph: '< <= > >=', name: 'Inequalities',
blurb: '', code: '@Refinement("y <= 0")\nint y = 0;' },
'op-not': { group: 'Operators', glyph: '!', name: 'Negate',
blurb: '', code: '@Refinement("!(y > 0)")\nint y = -200;' },
'op-and': { group: 'Operators', glyph: '&&', name: 'And',
blurb: '', code: '@Refinement("(0 <= y) && (y <= 100)")\nint y = 25;' },
'op-or': { group: 'Operators', glyph: '||', name: 'Or',
blurb: '', code: '@Refinement("(x == 0) || (x == 100)")\nint y = 100;' },
'op-add': { group: 'Operators', glyph: '+ −', name: 'Add & subtract',
blurb: '', code: '@Refinement("(v + 20) < 100")\nint v = 79;' },
'op-mul': { group: 'Operators', glyph: '* / %', name: 'Multiplicative',
blurb: '', code: '@Refinement("(odd % 2) != 0")\nint odd = 5;' },
'op-wild': { group: 'Operators', glyph: '_', name: 'This-variable wildcard',
blurb: 'The underscore stands in for the value being refined.',
code: '@Refinement("_ > 0")\nint y = 100;' },
'op-ite': { group: 'Operators', glyph: '? :', name: 'If-then-else',
blurb: '', code: '@Refinement("(a > b) ? (_ == a) : (_ == b)")\npublic int max(int a, int b) {...}' },
'al-def': { group: 'Aliases', glyph: '@RefinementAlias', name: 'Define',
blurb: 'Give a predicate a name so you can reuse it across @Refinement annotations.',
code: '@RefinementAlias("Percentage(int v) { 0 <= v && v <= 100 }")\npublic class X {...}' },
'al-use': { group: 'Aliases', glyph: 'Percentage(_)', name: 'Apply',
blurb: 'Use the alias inside any @Refinement.',
code: '@Refinement("Percentage(y)")\nint y = 25;' },
'st-set': { group: 'Object state & ghost', glyph: '@StateSet', name: 'Class states',
blurb: 'Declare the named states an object can occupy.',
code: '@StateSet({"open", "close"})\npublic class ReadFile {...}' },
'st-ref': { group: 'Object state & ghost', glyph: '@StateRefinement', name: 'Use states',
blurb: 'Constrain the state before and after a method call.',
code: '@StateRefinement(from="open(this)", to="close(this)")\npublic void closeFile() {...}' },
'st-ghost': { group: 'Object state & ghost', glyph: '@Ghost', name: 'Class ghost',
blurb: 'Track an auxiliary value that is not in the source code.',
code: '@Ghost("int size")\npublic class List {...}' },
'st-old': { group: 'Object state & ghost', glyph: 'old(this)', name: 'Use ghost',
blurb: 'Refer to the ghost value before the method ran.',
code: '@StateRefinement(to = "size(this) == (size(old(this)) + 1)")\npublic void add(int elem) {...}' }
};
var sel = document.getElementById('ljPredSelect');
var glyph = document.getElementById('ljPredGlyph');
var name = document.getElementById('ljPredName');
var blurb = document.getElementById('ljPredBlurb');
var code = document.getElementById('ljPredCode');
function render(id) {
var p = preds[id]; if (!p) return;
glyph.textContent = p.glyph;
name.textContent = p.name;
if (p.blurb) { blurb.textContent = p.blurb; blurb.style.display = ''; }
else { blurb.textContent = ''; blurb.style.display = 'none'; }
code.textContent = p.code;
if (window.Prism) Prism.highlightElement(code);
}
sel.addEventListener('change', function () { render(sel.value); });
render(sel.value || 'op-eq');
})();
</script>
</div>
</section>
<section class="w3l-feature-code" id="features">
<div class="grid top-bottom">
<div class="container">
<div class="heading text-center mx-auto">
<h3 class="head text-white">LiquidJava Examples</h3>
<p class="my-3 head text-white"> Find examples of LiquidJava in different parts of code.</p>
</div>
<div class="middle-section grid-column text-center mt-5 pt-3">
<a href="#refinementVariables"><div class="three-grids-columns">
<span class="fa fa-bullseye"></span>
<h4>Variables</h4>
<p>Examples of refinements in variables and class fields</p>
</div></a>
<a href="#refinementMethods"><div class="three-grids-columns">
<span class="fa fa-cogs"></span>
<h4>Methods</h4>
<p>Examples of methods with refinements in their parameters and return value.</p>
</div></a>
<a href="#refinementClasses"><div class="three-grids-columns">
<span class="fa fa-puzzle-piece"></span>
<h4>Classes</h4>
<p>Examples of object type state modelling using State Sets and Ghost attributes</p>
</div></a>
</div>
</div>
</div>
</section>
<section class="w3l-about ">
<div class="skills-bars py-5" style="background-color: #fff;">
</div>
</section>
<section class="w3l-about lj-section">
<a id="refinementVariables"></a>
<div class="container py-md-4 py-3">
<header class="lj-section-header">
<span class="lj-section-eyebrow">Variables</span>
<h3 class="lj-section-title">Refinements in Variables</h3>
<p class="lj-section-lede">
Add a <code class="lj-inline">@Refinement</code> wherever you already have a basic type — local variables, fields, or anywhere else.
</p>
</header>
</div>
</section>
<section class="w3l-about lj-mini-section">
<div class="container py-md-4 py-3">
<div class="lj-mini-grid">
<article class="lj-mini-card">
<header class="lj-mini-head">
<span class="lj-mini-eyebrow">Variable</span>
<h5 class="lj-mini-title">Positive</h5>
</header>
<p class="lj-mini-desc">The variable has a value greater than zero.</p>
<pre class="lj-mini-code"><code class="language-java">@Refinement("positive > 0")
int positive;
positive = 50; // Correct
positive = -1; // Error</code></pre>
</article>
<article class="lj-mini-card">
<header class="lj-mini-head">
<span class="lj-mini-eyebrow">Variable</span>
<h5 class="lj-mini-title">Percentage</h5>
</header>
<p class="lj-mini-desc">Lower and upper bounds set on a variable. The <code class="lj-inline">_</code> wildcard refers to the variable being refined.</p>
<pre class="lj-mini-code"><code class="language-java">@Refinement("_ >= 0 && _ <= 100")
int percentage;
percentage = 50; // Correct
percentage = 10 + 99; // Error</code></pre>
</article>
<article class="lj-mini-card lj-mini-card--wide">
<header class="lj-mini-head">
<span class="lj-mini-eyebrow">Class fields · alias</span>
<h5 class="lj-mini-title">RGB fields</h5>
</header>
<p class="lj-mini-desc">Class fields can be refined like any local variable. The <code class="lj-inline">RGB</code> alias keeps each channel between 0 and 255.</p>
<pre class="lj-mini-code"><code class="language-java">@RefinementAlias("RGB(int x) { x >= 0 && x <= 255 }")
class MyColor {
@Refinement("RGB(r)") int r;
@Refinement("RGB(_)") int g;
@Refinement("RGB(_)") int b;
}</code></pre>
</article>
</div>
</div>
</section>
<section class="w3l-about lj-section">
<a id="refinementMethods"></a>
<div class="container py-md-4 py-3">
<header class="lj-section-header">
<span class="lj-section-eyebrow">Methods</span>
<h3 class="lj-section-title">Refinements in Methods</h3>
<p class="lj-section-lede">
Both parameters and return values can be refined. Parameter refinements constrain how the method may be called; the return refinement constrains what the body may return.
</p>
</header>
</div>
</section>
<section class="w3l-about lj-mini-section">
<div class="container py-md-4 py-3">
<div class="lj-mini-grid">
<article class="lj-mini-card">
<header class="lj-mini-head">
<span class="lj-mini-eyebrow">Method · return</span>
<h5 class="lj-mini-title">Absolute</h5>
</header>
<p class="lj-mini-desc">Refine the <b>return type</b> with an annotation above the method. The <code class="lj-inline">_</code> wildcard refers to the return value.</p>
<pre class="lj-mini-code"><code class="language-java">@Refinement("_ >= 0 && _ >= n")
public static int absolute(int n) {
if (0 <= n) return n;
else return 0 - n;
}</code></pre>
</article>
<article class="lj-mini-card lj-mini-card--wide">
<header class="lj-mini-head">
<span class="lj-mini-eyebrow">Method · parameters</span>
<h5 class="lj-mini-title">Add Bonus — Grade</h5>
</header>
<p class="lj-mini-desc">Refine method <b>parameters</b>. Both must satisfy the <code class="lj-inline">Percentage</code> alias, and <code class="lj-inline">bonus</code> can refer to <code class="lj-inline">grade</code> (later parameters can mention earlier ones, never the reverse).</p>
<pre class="lj-mini-code"><code class="language-java">@RefinementAlias("Percentage(int x) { x >= 0 && x <= 100 }")
public class Grade {
@Refinement("Percentage(_)")
public static int addBonus(
@Refinement("Percentage(_)") int grade,
@Refinement("Percentage(_) && bonus < grade") int bonus) {
if ((bonus + grade) > 100) return 100;
else return grade + bonus;
}
}</code></pre>
</article>
</div>
</div>
</section>
<section class="w3l-about lj-section">
<a id="refinementClasses"></a>
<div class="container py-md-4 py-3">
<header class="lj-section-header">
<span class="lj-section-eyebrow">Classes</span>
<h3 class="lj-section-title">Refinements in Classes</h3>
<p class="lj-section-lede">
LiquidJava models object lifecycles with two primitives: <code class="lj-inline">@StateSet</code> for named states and <code class="lj-inline">@Ghost</code> for auxiliary integer/boolean properties. Methods declare allowed transitions with <code class="lj-inline">@StateRefinement(from = …, to = …)</code>; use <code class="lj-inline">old(this)</code> inside <code class="lj-inline">to</code> to refer to the pre-call state. Browse real JDK protocols below.
</p>
</header>
</div>
</section>
<section class="w3l-about lj-gallery-section">
<div class="lj-gallery-bg py-5">
<div class="container py-md-3">
<div class="lj-gallery" id="ljGallery">
<aside class="lj-sidebar">
<div class="lj-filters" data-group="complexity" aria-label="Filter by complexity">
<button type="button" class="lj-chip lj-chip--active" data-value="all">All</button>
<button type="button" class="lj-chip" data-value="simple">Simple</button>
<button type="button" class="lj-chip" data-value="moderate">Moderate</button>
<button type="button" class="lj-chip" data-value="complex">Complex</button>
</div>
<div class="lj-filters lj-filters--factor" data-group="factor" aria-label="Filter by factor">
<button type="button" class="lj-chip lj-chip--small" data-value="typestate">typestate</button>
<button type="button" class="lj-chip lj-chip--small" data-value="refinement">refinement</button>
<button type="button" class="lj-chip lj-chip--small" data-value="conditional">conditional</button>
<button type="button" class="lj-chip lj-chip--small" data-value="orthogonal">orthogonal</button>
</div>
<p class="lj-count" id="ljCount"></p>
<ul class="lj-example-list" id="ljList" aria-label="Examples"></ul>
</aside>
<article class="lj-detail" id="ljDetail" aria-live="polite">
<header class="lj-detail-head">
<p class="lj-classname" id="ljClass"></p>
<h5 class="lj-title" id="ljTitle"></h5>
<p class="lj-blurb" id="ljBlurb"></p>
<div class="lj-meta" id="ljMeta"></div>
</header>
<figure class="lj-state-diagram" aria-label="State diagram">
<figcaption class="lj-figcap">State diagram</figcaption>
<div class="lj-mermaid" id="ljMermaid"></div>
</figure>
<div class="lj-tabs" role="tablist" aria-label="Code views">
<button type="button" class="lj-tab lj-tab--active" data-tab="spec" role="tab" aria-selected="true">Spec</button>
<button type="button" class="lj-tab lj-tab--err" data-tab="incorrect" role="tab" aria-selected="false"><span class="lj-glyph">✕</span> Misuse</button>
<button type="button" class="lj-tab lj-tab--ok" data-tab="correct" role="tab" aria-selected="false"><span class="lj-glyph">✓</span> Correct</button>
</div>
<pre class="lj-code"><code id="ljCode"></code></pre>
<div class="lj-verifier" id="ljVerifier" data-state="ok">
<div class="lj-verifier-head">
<span class="lj-verifier-label">verifier</span>
<button type="button" class="lj-run" id="ljRun">▶ Run verifier</button>
</div>
<pre class="lj-verifier-body" id="ljVerifierBody"></pre>
</div>
</article>
</div>
</div>
</div>
</section>
<!-- grids block 5 -->
<section class="w3l-footer-29-main" id="footer">
<div class="footer-29 text-center">
<div class="container">
<div class="main-social-footer-29">
<a href="mailto:cgamboa@andrew.cmu.edu" class="email"><span class="fa fa-envelope-o"></span></a>
<a href="https://github.com/liquid-java" class="github"><span class="fa fa-github"></span></a>
<a href="https://www.linkedin.com/in/catarina-ventura-gamboa-518151172/" class="linkedin"><span class="fa fa-linkedin"></span></a>
</div>
<div class="bottom-copies text-center">
<p class="copy-footer-29">© <span id="year"></span> LiquidJava Website. All rights reserved | Designed by <a href="https://w3layouts.com">W3layouts</a></p>
</div>
</div>
</div>
<!-- move top -->
<button onclick="topFunction()" id="movetop" title="Go to top">
<span class="fa fa-angle-up"></span>
</button>
<script>
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function () {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("movetop").style.display = "block";
} else {
document.getElementById("movetop").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
<!-- /move top -->
</section>
<!-- // grids block 5 -->
<script src="assets/js/jquery-3.3.1.min.js"></script>
<!-- //footer-28 block -->
</section>
<script>
$(function () {
$('.navbar-toggler').click(function () {
$('body').toggleClass('noscroll');
})
});
</script>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous">
</script>
<script>
document.getElementById('year').textContent = new Date().getFullYear();
</script>
<!-- Examples gallery -->
<script>
(function () {
const $ = (id) => document.getElementById(id);
const root = $('ljGallery');
if (!root) return;
const state = {
examples: [],
activeId: null,
activeTab: 'spec',
complexity: 'all',
factors: new Set(),
mermaidReady: false,
runToken: 0,
};
const fileFor = (ex, tab) => ({
spec: 'spec.java',
correct: 'correct.java',
incorrect: 'incorrect.java',
}[tab]);
async function fetchText(path) {
const r = await fetch(path, { cache: 'no-cache' });
if (!r.ok) throw new Error(path + ' -> ' + r.status);
return r.text();
}
function passesFilter(ex) {
if (state.complexity !== 'all' && ex.complexity !== state.complexity) return false;
for (const f of state.factors) if (!ex.factors.includes(f)) return false;
return true;
}
function renderList() {
const list = $('ljList');
list.innerHTML = '';
const visible = state.examples.filter(passesFilter);
$('ljCount').textContent =
visible.length + ' of ' + state.examples.length + ' examples';
for (const ex of visible) {
const li = document.createElement('li');
li.className = 'lj-item' + (ex.id === state.activeId ? ' lj-item--active' : '');
li.dataset.id = ex.id;
li.innerHTML =
'<span class="lj-item-title">' + ex.title + '</span>' +
'<span class="lj-item-class">' + ex.className + '</span>' +
'<span class="lj-badge lj-badge--' + ex.complexity + '">' + ex.complexity + '</span>';
li.addEventListener('click', () => selectExample(ex.id));
list.appendChild(li);
}
if (visible.length && !visible.some(e => e.id === state.activeId)) {
selectExample(visible[0].id);
}
}
async function renderDetail() {
const ex = state.examples.find(e => e.id === state.activeId);
if (!ex) return;
$('ljClass').textContent = ex.className;
$('ljTitle').textContent = ex.title;
$('ljBlurb').textContent = ex.blurb;
const meta = $('ljMeta');
meta.innerHTML =
'<span class="lj-badge lj-badge--' + ex.complexity + '">' + ex.complexity + '</span>' +
ex.factors.map(f =>
'<span class="lj-factor">' + f + '</span>').join('');
// mermaid diagram
const mer = await fetchText('assets/examples/data/' + ex.id + '/state.mmd');
const mountId = 'ljMermaidGraph_' + Date.now();
const host = $('ljMermaid');
host.innerHTML = '';
if (state.mermaidReady && window.mermaid) {
try {
const { svg } = await window.mermaid.render(mountId, mer);
host.innerHTML = svg;
} catch (e) {
host.textContent = mer;
}
} else {
host.textContent = mer;
}
// active tab content
await renderTab();
}
async function renderTab() {
const ex = state.examples.find(e => e.id === state.activeId);
const code = await fetchText(
'assets/examples/data/' + ex.id + '/' + fileFor(ex, state.activeTab));
const codeEl = $('ljCode');
codeEl.className = 'language-java';
codeEl.textContent = code;
if (window.Prism && window.Prism.highlightElement) {
try { window.Prism.highlightElement(codeEl); } catch (e) {}
}
codeEl.classList.remove('lj-code-fade');
// restart fade animation
void codeEl.offsetWidth;
codeEl.classList.add('lj-code-fade');
const verifier = $('ljVerifier');
const body = $('ljVerifierBody');
state.runToken++;
if (state.activeTab === 'incorrect') {
verifier.dataset.state = 'err';
body.textContent = '✕ ' + ex.violation;
} else if (state.activeTab === 'correct') {
verifier.dataset.state = 'ok';
body.textContent = '✓ All refinements verified.';
} else {
verifier.dataset.state = 'spec';
body.textContent = '— Press Run to check a usage in the Misuse / Correct tabs.';
}
}
function runVerifier() {
const body = $('ljVerifierBody');
const target = body.textContent;
if (!target) return;
const myToken = ++state.runToken;
body.textContent = '';
let i = 0;
const tick = () => {
if (myToken !== state.runToken) return;
body.textContent = target.slice(0, i);
i++;
if (i <= target.length) setTimeout(tick, 12);
};
tick();
}
function selectExample(id) {
state.activeId = id;
// update list active state
for (const li of document.querySelectorAll('#ljList .lj-item')) {
li.classList.toggle('lj-item--active', li.dataset.id === id);
}
renderDetail();
}
function selectTab(tab) {
state.activeTab = tab;
for (const btn of document.querySelectorAll('.lj-tab')) {
const isActive = btn.dataset.tab === tab;
btn.classList.toggle('lj-tab--active', isActive);
btn.setAttribute('aria-selected', isActive ? 'true' : 'false');
}
renderTab();
}
function wireFilters() {
for (const group of document.querySelectorAll('.lj-filters')) {
const kind = group.dataset.group;
for (const chip of group.querySelectorAll('.lj-chip')) {
chip.addEventListener('click', () => {
const v = chip.dataset.value;
if (kind === 'complexity') {
state.complexity = v;
for (const c of group.querySelectorAll('.lj-chip'))
c.classList.toggle('lj-chip--active', c === chip);
} else {
if (state.factors.has(v)) state.factors.delete(v);
else state.factors.add(v);
chip.classList.toggle('lj-chip--active', state.factors.has(v));
}
renderList();
});
}
}
}
function wireTabs() {
for (const btn of document.querySelectorAll('.lj-tab')) {
btn.addEventListener('click', () => selectTab(btn.dataset.tab));
}
$('ljRun').addEventListener('click', runVerifier);
}
async function init() {
try {
state.examples = await (await fetch('assets/examples/examples.json', { cache: 'no-cache' })).json();
} catch (e) {
root.innerHTML = '<p class="lj-error">Could not load examples.</p>';
return;
}
if (window.mermaid) {
window.mermaid.initialize({
startOnLoad: false,
theme: 'base',
themeVariables: {
primaryColor: '#ffe7ee',
primaryTextColor: '#212529',
primaryBorderColor: '#cf0e4e',
lineColor: '#cf0e4e',
fontFamily: 'Nunito, system-ui, sans-serif',
fontSize: '14px',
},
flowchart: { htmlLabels: true },
});
state.mermaidReady = true;
} else {
// mermaid loads with `defer`; poll briefly
const start = Date.now();
while (!window.mermaid && Date.now() - start < 3000) {
await new Promise(r => setTimeout(r, 50));
}
if (window.mermaid) {
window.mermaid.initialize({
startOnLoad: false,
theme: 'base',
themeVariables: {
primaryColor: '#fff7ec',
primaryTextColor: '#1a1a2e',
primaryBorderColor: '#1a1a2e',
lineColor: '#1a1a2e',
fontFamily: 'JetBrains Mono, monospace',
fontSize: '14px',
},
});
state.mermaidReady = true;
}
}
wireFilters();
wireTabs();
state.activeId = state.examples[0].id;
renderList();
renderDetail();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
</script>
<!-- Smooth scrolling -->
</body>
</html>
<!-- // grids block 5 -->