Skip to content

Commit

Permalink
Merge pull request #5021 from line-o/overloaded
Browse files Browse the repository at this point in the history
Rename Function flag overloaded to variadic
  • Loading branch information
reinhapa authored Aug 26, 2023
2 parents 4fff15a + e04765f commit 7fa1d00
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion exist-core/src/main/java/org/exist/xquery/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public Expression getParent() {
* @throws XPathException if an error occurs setting the arguments
*/
public void setArguments(final List<Expression> arguments) throws XPathException {
if ((!mySignature.isOverloaded()) && arguments.size() != mySignature.getArgumentCount()) {
if ((!mySignature.isVariadic()) && arguments.size() != mySignature.getArgumentCount()) {
throw new XPathException(this, ErrorCodes.XPST0017,
"Number of arguments of function " + getName() + " doesn't match function signature (expected " +
mySignature.getArgumentCount() + ", got " + arguments.size() + ')');
Expand Down
28 changes: 14 additions & 14 deletions exist-core/src/main/java/org/exist/xquery/FunctionSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static SequenceType[] singleArgument(final SequenceType arg) {
private final QName name;
private SequenceType[] arguments;
private SequenceType returnType;
private boolean isOverloaded = false;
private boolean isVariadic = false;
private String description = null;
private String deprecated = null;
private Map<String, String> metadata = null;
Expand All @@ -70,7 +70,7 @@ public FunctionSignature(final FunctionSignature other) {
this.arguments = other.arguments != null ? Arrays.copyOf(other.arguments, other.arguments.length) : null;
this.returnType = other.returnType;
this.annotations = other.annotations != null ? Arrays.copyOf(other.annotations, other.annotations.length) : null;
this.isOverloaded = other.isOverloaded;
this.isVariadic = other.isVariadic;
this.deprecated = other.deprecated;
this.description = other.description;
this.metadata = other.metadata != null ? new HashMap<>(other.metadata) : null;
Expand All @@ -84,8 +84,8 @@ public FunctionSignature(final QName name, final SequenceType[] arguments, final
this(name, null, arguments, returnType);
}

public FunctionSignature(final QName name, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded) {
this(name, null, arguments, returnType, overloaded);
public FunctionSignature(final QName name, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic) {
this(name, null, arguments, returnType, variadic);
}

public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType) {
Expand All @@ -101,8 +101,8 @@ public FunctionSignature(final QName name, final String description, final Seque
// this(name, description, arguments, returnType, false, "Moved to the module: " + deprecatedBy.getName().getNamespaceURI() + ", you should now use '" + deprecatedBy.getName().getPrefix() + ":" + deprecatedBy.getName().getLocalPart() + "' instead!");
// }

public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded, final String deprecated) {
this(name, description, arguments, returnType, overloaded);
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic, final String deprecated) {
this(name, description, arguments, returnType, variadic);
setDeprecated(deprecated);
}

Expand All @@ -113,13 +113,13 @@ public FunctionSignature(final QName name, final String description, final Seque
* @param description documentation string describing the function
* @param arguments the sequence types of all expected arguments
* @param returnType the sequence type returned by the function
* @param overloaded set to true if the function may expect additional parameters
* @param variadic set to true if the function may expect additional parameters
*/
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded) {
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic) {
this.name = name;
this.arguments = arguments;
this.returnType = returnType;
this.isOverloaded = overloaded;
this.isVariadic = variadic;
this.description = description;
}

Expand All @@ -132,7 +132,7 @@ public QName getName() {
}

public int getArgumentCount() {
if(isOverloaded) {
if(isVariadic) {
return -1;
}
return arguments != null ? arguments.length : 0;
Expand Down Expand Up @@ -193,8 +193,8 @@ public Map<String, String> getMetadata() {
return metadata;
}

public boolean isOverloaded() {
return isOverloaded;
public boolean isVariadic() {
return isVariadic;
}

public boolean isDeprecated() {
Expand Down Expand Up @@ -247,7 +247,7 @@ public String toString() {
buf.append(arguments[i].toString());
}

if(isOverloaded) {
if(isVariadic) {
buf.append(", ...");
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public FunctionSignature rename(final QName newName) {
final SequenceType[] argumentsCopy = arguments != null ? Arrays.copyOf(arguments, arguments.length) : null;
final FunctionSignature newFunctionSignature = new FunctionSignature(newName, description, argumentsCopy, returnType, deprecated);
newFunctionSignature.annotations = annotations != null ? Arrays.copyOf(annotations, annotations.length) : null;
newFunctionSignature.isOverloaded = isOverloaded;
newFunctionSignature.isVariadic = isVariadic;
newFunctionSignature.metadata = metadata != null ? new HashMap<>(metadata) : null;
return newFunctionSignature;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private Sequence foldRight(final FunctionReference ref, final Sequence zero, fin
}

private boolean funcRefHasDifferentArity(final FunctionReference ref, final int n) {
return (!ref.getSignature().isOverloaded() &&
return (!ref.getSignature().isVariadic() &&
ref.getSignature().getArgumentCount() != n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ public class FunNamespaceURI extends Function {
new QName("namespace-uri", Function.BUILTIN_FUNCTION_NS),
FUNCTION_DESCRIPTION_0_PARAM + FUNCTION_DESCRIPTION_COMMON,
new SequenceType[0],
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI"),
false),
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI")
),
new FunctionSignature(
new QName("namespace-uri", Function.BUILTIN_FUNCTION_NS),
FUNCTION_DESCRIPTION_1_PARAM + FUNCTION_DESCRIPTION_COMMON,
new SequenceType[] {
new FunctionParameterSequenceType("arg", Type.NODE, Cardinality.ZERO_OR_ONE, "The input node")
},
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI"),
false)
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI")
)
};

public FunNamespaceURI(final XQueryContext context, final FunctionSignature signature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static void addFunctionRefsFromModule(final Expression parent, final XQue
if (!signature.isPrivate()) {
if (module.isInternalModule()) {
int arity;
if (signature.isOverloaded()) {
if (signature.isVariadic()) {
arity = signature.getArgumentTypes().length;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class StreamBinary extends StrictResponseFunction {
+ "Note: the servlet output stream will be closed afterwards and mime-type settings in the prolog "
+ "will not be passed.",
new SequenceType[]{BINARY_DATA_PARAM, CONTENT_TYPE_PARAM, FILENAME_PARAM},
new SequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE),
true);
new SequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE)
);

public StreamBinary(final XQueryContext context) {
super(context, signature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public class GetFragmentBetween extends BasicFunction {
new FunctionParameterSequenceType("make-fragment", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "The flag make a fragment."),
new FunctionParameterSequenceType("display-root-namespace", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "Display the namespace of the root node of the fragment.")
},
new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the string containing the fragment between the two node/milestone elements."), true);
new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the string containing the fragment between the two node/milestone elements.")
);

public GetFragmentBetween(final XQueryContext context) {
super(context, signature);
Expand Down
11 changes: 11 additions & 0 deletions extensions/indexes/range/src/test/xquery/range/range.xql
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ function rt:equality-field-nested($type as xs:string, $subtype as xs:string, $na
collection("/db/rangetest")//range:field-eq(("type", "subtype", "name"), $type, $subtype, $name)/text()
};

(: Test multi-value field lookups :)
declare
%test:assertEquals("Hofthiergarten", "Dorfprozelten")
function rt:equality-field-nested-multi() {
collection("/db/rangetest")
//range:field-eq(
("type", "subtype", "name"),
"main", "official", ("Hofthiergarten", "Dorfprozelten"))
/text()
};

declare
%test:assertEquals("Almweide")
function rt:remove-document() {
Expand Down

0 comments on commit 7fa1d00

Please sign in to comment.