From f12aea84959dac0eeb6af03bead7d3d40e21fe44 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 2 Apr 2016 19:39:04 +0200 Subject: [PATCH] Don't allow implicit functions in CustomFunction --- .../java/jscl/math/function/CustomFunction.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jscl/src/main/java/jscl/math/function/CustomFunction.java b/jscl/src/main/java/jscl/math/function/CustomFunction.java index cd4c2b6a..e6327656 100644 --- a/jscl/src/main/java/jscl/math/function/CustomFunction.java +++ b/jscl/src/main/java/jscl/math/function/CustomFunction.java @@ -5,7 +5,10 @@ import jscl.CustomFunctionCalculationException; import jscl.JsclMathEngine; import jscl.math.*; import jscl.text.ParseException; +import jscl.text.msg.JsclMessage; +import jscl.text.msg.Messages; import org.solovyev.common.math.MathEntity; +import org.solovyev.common.msg.MessageType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -58,6 +61,7 @@ public class CustomFunction extends Function implements IFunction { this.parameterNames = parameterNames; try { this.content = Expression.valueOf(content); + ensureNoImplicitFunctions(); } catch (ParseException e) { throw new CustomFunctionCalculationException(this, e); } @@ -65,6 +69,18 @@ public class CustomFunction extends Function implements IFunction { this.id = counter.incrementAndGet(); } + private void ensureNoImplicitFunctions() { + for (int i = 0; i < this.content.size(); i++) { + final Literal literal = this.content.literal(i); + for (int j = 0; j < literal.size(); j++) { + final Variable variable = literal.getVariable(j); + if (variable instanceof ImplicitFunction) { + throw new CustomFunctionCalculationException(this, new JsclMessage(Messages.msg_13, MessageType.error, variable.getName())); + } + } + } + } + @Override public int getMinParameters() { return parameterNames == null ? 0 : parameterNames.size();