diff options
Diffstat (limited to 'plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java')
-rw-r--r-- | plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java | 95 |
1 files changed, 48 insertions, 47 deletions
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java index 548edaf7..a20607b0 100644 --- a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java +++ b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandFacade.java @@ -28,59 +28,60 @@ import org.eclipse.xtend.typesystem.Type; * @author Sven Efftinge (http://www.efftinge.de) * */ public class XpandFacade { - private XpandExecutionContext ctx = null; + private XpandExecutionContext ctx = null; - /** - * @deprecated use XpandFacade.create instead - */ - public XpandFacade(final XpandExecutionContext ctx) { - this.ctx = ctx; - } + /** + * @deprecated use XpandFacade.create instead + */ + @Deprecated + public XpandFacade(final XpandExecutionContext ctx) { + this.ctx = ctx; + } - public void evaluate(final String definitionName, final Object targetObject, Object... params) { - params = params == null ? new Object[0] : params; - final Type targetType = ctx.getType(targetObject); - final Type[] paramTypes = new Type[params.length]; - for (int i = 0; i < paramTypes.length; i++) { - paramTypes[i] = ctx.getType(params[i]); - } + public void evaluate(final String definitionName, final Object targetObject, Object... params) { + params = params == null ? new Object[0] : params; + final Type targetType = ctx.getType(targetObject); + final Type[] paramTypes = new Type[params.length]; + for (int i = 0; i < paramTypes.length; i++) { + paramTypes[i] = ctx.getType(params[i]); + } - final XpandDefinition def = ctx.findDefinition(definitionName, targetType, paramTypes); - if (def == null) - throw new EvaluationException("No Definition " + definitionName + getParamString(paramTypes) + " for " - + targetType.getName() + " could be found!", null, ctx); + final XpandDefinition def = ctx.findDefinition(definitionName, targetType, paramTypes); + if (def == null) + throw new EvaluationException("No Definition " + definitionName + getParamString(paramTypes) + " for " + + targetType.getName() + " could be found!", null, ctx); - ctx = (XpandExecutionContext) ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, - targetObject)); - for (int i = 0; i < params.length; i++) { - final Variable v = new Variable(def.getParams()[i].getName().getValue(), params[i]); - ctx = (XpandExecutionContext) ctx.cloneWithVariable(v); - } - ctx = (XpandExecutionContext) ctx.cloneWithResource(def.getOwner()); - def.evaluate(ctx); - } + ctx = (XpandExecutionContext) ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, + targetObject)); + for (int i = 0; i < params.length; i++) { + final Variable v = new Variable(def.getParams()[i].getName().getValue(), params[i]); + ctx = (XpandExecutionContext) ctx.cloneWithVariable(v); + } + ctx = (XpandExecutionContext) ctx.cloneWithResource(def.getOwner()); + def.evaluate(ctx); + } - private String getParamString(final Type[] paramTypes) { - if (paramTypes.length == 0) - return ""; - final StringBuffer buff = new StringBuffer("("); - for (int i = 0; i < paramTypes.length; i++) { - final Type t = paramTypes[i]; - buff.append(t.getName()); - if (i + 1 < paramTypes.length) { - buff.append(","); - } - } - buff.append(")"); - return buff.toString(); - } + private String getParamString(final Type[] paramTypes) { + if (paramTypes.length == 0) + return ""; + final StringBuffer buff = new StringBuffer("("); + for (int i = 0; i < paramTypes.length; i++) { + final Type t = paramTypes[i]; + buff.append(t.getName()); + if (i + 1 < paramTypes.length) { + buff.append(","); + } + } + buff.append(")"); + return buff.toString(); + } - public AnalysationIssue[] analyze(final String templateName) { - final Set<AnalysationIssue> issues = new HashSet<AnalysationIssue>(); - final XpandResource tpl = ctx.findTemplate(templateName); - tpl.analyze(ctx, issues); - return issues.toArray(new AnalysationIssue[issues.size()]); - } + public AnalysationIssue[] analyze(final String templateName) { + final Set<AnalysationIssue> issues = new HashSet<AnalysationIssue>(); + final XpandResource tpl = ctx.findTemplate(templateName); + tpl.analyze(ctx, issues); + return issues.toArray(new AnalysationIssue[issues.size()]); + } public static XpandFacade create(XpandExecutionContextImpl execCtx) { return new XpandFacade(execCtx); |