package freemarker.core;
import java.util.List;
abstract class BuiltInWithParseTimeParameters extends SpecialBuiltIn {
abstract void bindToParameters(List parameters, Token openParen, Token closeParen)
throws ParseException;
@Override
public String getCanonicalForm() {
StringBuilder buf = new StringBuilder();
buf.append(super.getCanonicalForm());
buf.append("(");
Listargs = getArgumentsAsList();
int size = args.size();
for (int i = 0; i < size; i++) {
if (i != 0) {
buf.append(", ");
}
Expression arg = (Expression) args.get(i);
buf.append(arg.getCanonicalForm());
}
buf.append(")");
return buf.toString();
}
@Override
String getNodeTypeSymbol() {
return super.getNodeTypeSymbol() + "(...)";
}
@Override
int getParameterCount() {
return super.getParameterCount() + getArgumentsCount();
}
@Override
Object getParameterValue(int idx) {
final int superParamCnt = super.getParameterCount();
if (idx < superParamCnt) {
return super.getParameterValue(idx);
}
final int argIdx = idx - superParamCnt;
return getArgumentParameterValue(argIdx);
}
@Override
ParameterRole getParameterRole(int idx) {
final int superParamCnt = super.getParameterCount();
if (idx < superParamCnt) {
return super.getParameterRole(idx);
}
if (idx - superParamCnt < getArgumentsCount()) {
return ParameterRole.ARGUMENT_VALUE;
} else {
throw new IndexOutOfBoundsException();
}
}
protected ParseException newArgumentCountException(String ordinalityDesc, Token openParen, Token closeParen) {
return new ParseException(
"?" + key + "(...) " + ordinalityDesc + " parameters", this.getTemplate(),
openParen.beginLine, openParen.beginColumn,
closeParen.endLine, closeParen.endColumn);
}
@Override
protected Expression deepCloneWithIdentifierReplaced_inner(
String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) {
final Expression clone = super.deepCloneWithIdentifierReplaced_inner(replacedIdentifier, replacement, replacementState);
cloneArguments(clone, replacedIdentifier, replacement, replacementState);
return clone;
}
protected abstract List getArgumentsAsList();
protected abstract int getArgumentsCount();
protected abstract Expression getArgumentParameterValue(int argIdx);
protected abstract void cloneArguments(Expression clone, String replacedIdentifier,
Expression replacement, ReplacemenetState replacementState);
}