-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathEnvironmentMethodLambda.java
More file actions
52 lines (40 loc) · 1.84 KB
/
EnvironmentMethodLambda.java
File metadata and controls
52 lines (40 loc) · 1.84 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
package stanhebben.zenscript.compiler;
import stanhebben.zenscript.expression.*;
import stanhebben.zenscript.expression.partial.*;
import stanhebben.zenscript.symbols.*;
import stanhebben.zenscript.util.*;
import java.util.*;
public class EnvironmentMethodLambda extends EnvironmentMethod {
private static final List<Class<? extends IPartialExpression>> nonCapturedExpressions;
static {
nonCapturedExpressions = Arrays.asList(PartialStaticGetter.class, PartialStaticGenerated.class, PartialStaticMethod.class, ExpressionJavaStaticField.class, ExpressionJavaMethodStatic.class, ExpressionCallStatic.class);
}
private final List<SymbolCaptured> capturedVariables;
private final String clsName;
public EnvironmentMethodLambda(MethodOutput output, IEnvironmentClass environment, String clsName) {
super(output, environment);
this.clsName = clsName;
capturedVariables = new ArrayList<>(0);
}
@Override
public IPartialExpression getValue(String name, ZenPosition position) {
if(local.containsKey(name)) {
return local.get(name).instance(position);
} else {
final IPartialExpression value = environment.getValue(name, position);
if(value != null) {
if(nonCapturedExpressions.stream().anyMatch(c -> c.isInstance(value))) {
return value;
}
final SymbolCaptured capture = new SymbolCaptured(value.eval(environment), name, clsName);
capturedVariables.add(capture);
local.put(name, capture);
return capture.instance(position);
}
return null;
}
}
public List<SymbolCaptured> getCapturedVariables() {
return capturedVariables;
}
}