Don't allow implicit functions in CustomFunction
This commit is contained in:
parent
7b59bcec2f
commit
f12aea8495
@ -5,7 +5,10 @@ import jscl.CustomFunctionCalculationException;
|
|||||||
import jscl.JsclMathEngine;
|
import jscl.JsclMathEngine;
|
||||||
import jscl.math.*;
|
import jscl.math.*;
|
||||||
import jscl.text.ParseException;
|
import jscl.text.ParseException;
|
||||||
|
import jscl.text.msg.JsclMessage;
|
||||||
|
import jscl.text.msg.Messages;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -58,6 +61,7 @@ public class CustomFunction extends Function implements IFunction {
|
|||||||
this.parameterNames = parameterNames;
|
this.parameterNames = parameterNames;
|
||||||
try {
|
try {
|
||||||
this.content = Expression.valueOf(content);
|
this.content = Expression.valueOf(content);
|
||||||
|
ensureNoImplicitFunctions();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new CustomFunctionCalculationException(this, e);
|
throw new CustomFunctionCalculationException(this, e);
|
||||||
}
|
}
|
||||||
@ -65,6 +69,18 @@ public class CustomFunction extends Function implements IFunction {
|
|||||||
this.id = counter.incrementAndGet();
|
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
|
@Override
|
||||||
public int getMinParameters() {
|
public int getMinParameters() {
|
||||||
return parameterNames == null ? 0 : parameterNames.size();
|
return parameterNames == null ? 0 : parameterNames.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user