-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestSecurity.java
41 lines (33 loc) · 1.54 KB
/
TestSecurity.java
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
package generated;
import java.util.Arrays;
import java.util.List;
import recaf.demo.direct.Student;
import recaf.demo.direct.StudentPolicy;
import recaf.demo.direct.Security;
class Printer2 {
public Void print(Object o) {
System.out.print(o);
return null;
}
}
public class TestSecurity{
private static Security<Object> alg = new Security<Object>(new StudentPolicy());
public static Void printGrades(List<Student> students) {
recaf.core.Ref<List<Student>> $students = new recaf.core.Ref<List<Student>>(students);
return (Void )alg.Method(alg.Decl(alg.New(Printer2.class), (recaf.core.Ref<Printer2 > p) -> {return alg.<Student >ForEach(alg.Ref("$students", $students), (recaf.core.Ref<Student > s) -> alg.Seq(alg.ExpStat(alg.Invoke(alg.Ref("p", p), "print", alg.Field(alg.Ref("s", s), "name"))), alg.Seq(alg.ExpStat(alg.Invoke(alg.Ref("p", p), "print", alg.Lit(" -> "))), alg.Seq(alg.ExpStat(alg.Invoke(alg.Ref("p", p), "print", alg.Field(alg.Ref("s", s), "grade"))), alg.ExpStat(alg.Invoke(alg.Ref("p", p), "print", alg.Lit("\n")))))));}));
}
public static Void failStudent(Student s) {
recaf.core.Ref<Student > $s = new recaf.core.Ref<Student >(s);
return (Void )alg.Method(alg.ExpStat(alg.Assign(alg.Field(alg.Ref("$s", $s), "grade"), alg.Lit("F"))));
}
public static void main(String[] args){
List<Student> students =
Arrays.asList(new Student[]{
new Student("Alice", "A",1),
new Student("Bob","B", 2),
new Student("Cathy","F",1)});
failStudent(students.get(0));
failStudent(students.get(1));
printGrades(students);
}
}