forked from lykhonis/FJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosureAnonymous.java
More file actions
35 lines (28 loc) · 915 Bytes
/
Copy pathClosureAnonymous.java
File metadata and controls
35 lines (28 loc) · 915 Bytes
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
package com.fjava.translator;
import static com.fjava.translator.TokenType.ASSIGN;
import static com.fjava.translator.TokenType.LBRACE;
import static com.fjava.translator.TokenType.LPAREN;
import static com.fjava.translator.TokenType.RBRACE;
import static com.fjava.translator.TokenType.RPAREN;
import static com.fjava.translator.TokenType.RT;
public class ClosureAnonymous extends Atom {
public ClosureAnonymous(TranslatorFactory factory) {
super(factory);
}
@Override
public String translate() {
final StringBuilder result = new StringBuilder(format("new F() { @Override public void invoke() { "));
skipRequired();
TokenType type = require();
while (type != RBRACE) {
result.append(get());
type = require();
}
result.append("}}");
return result.toString();
}
@Override
public boolean test() {
return test(LPAREN, RPAREN, ASSIGN, RT, LBRACE) || test(ASSIGN, RT, LBRACE);
}
}