-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ClassExpressionLookup to access classes declared later in the s…
…cript
- Loading branch information
Showing
3 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...s/tools-evaluation/src/main/java/com/wizzardo/tools/evaluation/ClassExpressionLookup.java
This file contains 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,42 @@ | ||
package com.wizzardo.tools.evaluation; | ||
|
||
import com.wizzardo.tools.misc.Unchecked; | ||
import java.util.Map; | ||
|
||
public class ClassExpressionLookup extends Expression { | ||
|
||
protected final String className; | ||
protected final String key; | ||
protected ClassExpression ce; | ||
|
||
public ClassExpressionLookup(String className, EvaluationContext context) { | ||
super(context); | ||
this.className = className; | ||
this.key = "class " + className; | ||
} | ||
|
||
@Override | ||
public void setVariable(Variable v) { | ||
} | ||
|
||
@Override | ||
public Expression clone() { | ||
return this; | ||
} | ||
|
||
@Override | ||
protected Object doExecute(Map<String, Object> model) { | ||
if (ce == null) { | ||
ce = (ClassExpression) model.get(key); | ||
} | ||
if (ce == null) { | ||
Unchecked.rethrow(new ClassNotFoundException("Can not find class '" + className + "'")); | ||
} | ||
return ce; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return className; | ||
} | ||
} |
This file contains 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 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