saxon文档中的example usage of ExtensionFunctionDefinition无法使用Saxon版本9.5.1-6进行编译
我得到的错误是:
java: <anonymous ShiftLeft$1> is not abstract and does not override abstract method call(net.sf.saxon.expr.XPathContext,net.sf.saxon.om.Sequence[]) in net.sf.saxon.lib.ExtensionFunctionCall
如何在Saxon 9.5中编译此代码?
private static class ShiftLeft extends ExtensionFunctionDefinition {
@Override
public StructuredQName getFunctionQName() {
return new StructuredQName("eg", "http://example.com/saxon-extension", "shift-left");
}
@Override
public SequenceType[] getArgumentTypes() {
return new SequenceType[] {SequenceType.SINGLE_INTEGER, SequenceType.SINGLE_INTEGER};
}
@Override
public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
return SequenceType.SINGLE_INTEGER;
}
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments, XPathContext context) throws XPathException {
long v0 = ((IntegerValue)arguments[0].next()).longValue();
long v1 = ((IntegerValue)arguments[1].next()).longValue();
long result = v0<<v1;
return Value.asIterator(Int64Value.makeIntegerValue(result));
}
};
}
}
答案 0 :(得分:1)
import com.saxonica.config.EnterpriseTransformerFactory;
import com.saxonica.config.ProfessionalConfiguration;
import com.saxonica.objectweb.asm.tree.analysis.Value;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.Int64Value;
import net.sf.saxon.value.IntegerValue;
import net.sf.saxon.value.SequenceType;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.StringWriter;
class ShiftLeft extends ExtensionFunctionDefinition {
@Override
public StructuredQName getFunctionQName() {
return new StructuredQName("eg", "http://example.com/saxon-extension", "shift-left");
}
@Override
public SequenceType[] getArgumentTypes() {
return new SequenceType[]{SequenceType.SINGLE_INTEGER, SequenceType.SINGLE_INTEGER};
}
@Override
public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
return SequenceType.SINGLE_INTEGER;
}
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
long v0 = ((IntegerValue)arguments[0]).longValue();
long v1 = ((IntegerValue)arguments[1]).longValue();
long result = v0<<v1;
return Int64Value.makeIntegerValue(result);
}
};
}
}