Skip to content

Commit 7fa1d00

Browse files
authored
Merge pull request #5021 from line-o/overloaded
Rename Function flag overloaded to variadic
2 parents 4fff15a + e04765f commit 7fa1d00

File tree

8 files changed

+36
-24
lines changed

8 files changed

+36
-24
lines changed

exist-core/src/main/java/org/exist/xquery/Function.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public Expression getParent() {
219219
* @throws XPathException if an error occurs setting the arguments
220220
*/
221221
public void setArguments(final List<Expression> arguments) throws XPathException {
222-
if ((!mySignature.isOverloaded()) && arguments.size() != mySignature.getArgumentCount()) {
222+
if ((!mySignature.isVariadic()) && arguments.size() != mySignature.getArgumentCount()) {
223223
throw new XPathException(this, ErrorCodes.XPST0017,
224224
"Number of arguments of function " + getName() + " doesn't match function signature (expected " +
225225
mySignature.getArgumentCount() + ", got " + arguments.size() + ')');

exist-core/src/main/java/org/exist/xquery/FunctionSignature.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static SequenceType[] singleArgument(final SequenceType arg) {
6060
private final QName name;
6161
private SequenceType[] arguments;
6262
private SequenceType returnType;
63-
private boolean isOverloaded = false;
63+
private boolean isVariadic = false;
6464
private String description = null;
6565
private String deprecated = null;
6666
private Map<String, String> metadata = null;
@@ -70,7 +70,7 @@ public FunctionSignature(final FunctionSignature other) {
7070
this.arguments = other.arguments != null ? Arrays.copyOf(other.arguments, other.arguments.length) : null;
7171
this.returnType = other.returnType;
7272
this.annotations = other.annotations != null ? Arrays.copyOf(other.annotations, other.annotations.length) : null;
73-
this.isOverloaded = other.isOverloaded;
73+
this.isVariadic = other.isVariadic;
7474
this.deprecated = other.deprecated;
7575
this.description = other.description;
7676
this.metadata = other.metadata != null ? new HashMap<>(other.metadata) : null;
@@ -84,8 +84,8 @@ public FunctionSignature(final QName name, final SequenceType[] arguments, final
8484
this(name, null, arguments, returnType);
8585
}
8686

87-
public FunctionSignature(final QName name, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded) {
88-
this(name, null, arguments, returnType, overloaded);
87+
public FunctionSignature(final QName name, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic) {
88+
this(name, null, arguments, returnType, variadic);
8989
}
9090

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

104-
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded, final String deprecated) {
105-
this(name, description, arguments, returnType, overloaded);
104+
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic, final String deprecated) {
105+
this(name, description, arguments, returnType, variadic);
106106
setDeprecated(deprecated);
107107
}
108108

@@ -113,13 +113,13 @@ public FunctionSignature(final QName name, final String description, final Seque
113113
* @param description documentation string describing the function
114114
* @param arguments the sequence types of all expected arguments
115115
* @param returnType the sequence type returned by the function
116-
* @param overloaded set to true if the function may expect additional parameters
116+
* @param variadic set to true if the function may expect additional parameters
117117
*/
118-
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded) {
118+
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean variadic) {
119119
this.name = name;
120120
this.arguments = arguments;
121121
this.returnType = returnType;
122-
this.isOverloaded = overloaded;
122+
this.isVariadic = variadic;
123123
this.description = description;
124124
}
125125

@@ -132,7 +132,7 @@ public QName getName() {
132132
}
133133

134134
public int getArgumentCount() {
135-
if(isOverloaded) {
135+
if(isVariadic) {
136136
return -1;
137137
}
138138
return arguments != null ? arguments.length : 0;
@@ -193,8 +193,8 @@ public Map<String, String> getMetadata() {
193193
return metadata;
194194
}
195195

196-
public boolean isOverloaded() {
197-
return isOverloaded;
196+
public boolean isVariadic() {
197+
return isVariadic;
198198
}
199199

200200
public boolean isDeprecated() {
@@ -247,7 +247,7 @@ public String toString() {
247247
buf.append(arguments[i].toString());
248248
}
249249

250-
if(isOverloaded) {
250+
if(isVariadic) {
251251
buf.append(", ...");
252252
}
253253
}
@@ -289,7 +289,7 @@ public FunctionSignature rename(final QName newName) {
289289
final SequenceType[] argumentsCopy = arguments != null ? Arrays.copyOf(arguments, arguments.length) : null;
290290
final FunctionSignature newFunctionSignature = new FunctionSignature(newName, description, argumentsCopy, returnType, deprecated);
291291
newFunctionSignature.annotations = annotations != null ? Arrays.copyOf(annotations, annotations.length) : null;
292-
newFunctionSignature.isOverloaded = isOverloaded;
292+
newFunctionSignature.isVariadic = isVariadic;
293293
newFunctionSignature.metadata = metadata != null ? new HashMap<>(metadata) : null;
294294
return newFunctionSignature;
295295
}

exist-core/src/main/java/org/exist/xquery/functions/fn/FunHigherOrderFun.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private Sequence foldRight(final FunctionReference ref, final Sequence zero, fin
252252
}
253253

254254
private boolean funcRefHasDifferentArity(final FunctionReference ref, final int n) {
255-
return (!ref.getSignature().isOverloaded() &&
255+
return (!ref.getSignature().isVariadic() &&
256256
ref.getSignature().getArgumentCount() != n);
257257
}
258258
}

exist-core/src/main/java/org/exist/xquery/functions/fn/FunNamespaceURI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ public class FunNamespaceURI extends Function {
7171
new QName("namespace-uri", Function.BUILTIN_FUNCTION_NS),
7272
FUNCTION_DESCRIPTION_0_PARAM + FUNCTION_DESCRIPTION_COMMON,
7373
new SequenceType[0],
74-
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI"),
75-
false),
74+
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI")
75+
),
7676
new FunctionSignature(
7777
new QName("namespace-uri", Function.BUILTIN_FUNCTION_NS),
7878
FUNCTION_DESCRIPTION_1_PARAM + FUNCTION_DESCRIPTION_COMMON,
7979
new SequenceType[] {
8080
new FunctionParameterSequenceType("arg", Type.NODE, Cardinality.ZERO_OR_ONE, "The input node")
8181
},
82-
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI"),
83-
false)
82+
new FunctionReturnSequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE, "the namespace URI")
83+
)
8484
};
8585

8686
public FunNamespaceURI(final XQueryContext context, final FunctionSignature signature) {

exist-core/src/main/java/org/exist/xquery/functions/fn/LoadXQueryModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static void addFunctionRefsFromModule(final Expression parent, final XQue
251251
if (!signature.isPrivate()) {
252252
if (module.isInternalModule()) {
253253
int arity;
254-
if (signature.isOverloaded()) {
254+
if (signature.isVariadic()) {
255255
arity = signature.getArgumentTypes().length;
256256
}
257257
else {

exist-core/src/main/java/org/exist/xquery/functions/response/StreamBinary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class StreamBinary extends StrictResponseFunction {
5252
+ "Note: the servlet output stream will be closed afterwards and mime-type settings in the prolog "
5353
+ "will not be passed.",
5454
new SequenceType[]{BINARY_DATA_PARAM, CONTENT_TYPE_PARAM, FILENAME_PARAM},
55-
new SequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE),
56-
true);
55+
new SequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE)
56+
);
5757

5858
public StreamBinary(final XQueryContext context) {
5959
super(context, signature);

exist-core/src/main/java/org/exist/xquery/functions/util/GetFragmentBetween.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public class GetFragmentBetween extends BasicFunction {
8989
new FunctionParameterSequenceType("make-fragment", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "The flag make a fragment."),
9090
new FunctionParameterSequenceType("display-root-namespace", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "Display the namespace of the root node of the fragment.")
9191
},
92-
new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the string containing the fragment between the two node/milestone elements."), true);
92+
new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the string containing the fragment between the two node/milestone elements.")
93+
);
9394

9495
public GetFragmentBetween(final XQueryContext context) {
9596
super(context, signature);

extensions/indexes/range/src/test/xquery/range/range.xql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,17 @@ function rt:equality-field-nested($type as xs:string, $subtype as xs:string, $na
369369
collection("/db/rangetest")//range:field-eq(("type", "subtype", "name"), $type, $subtype, $name)/text()
370370
};
371371

372+
(: Test multi-value field lookups :)
373+
declare
374+
%test:assertEquals("Hofthiergarten", "Dorfprozelten")
375+
function rt:equality-field-nested-multi() {
376+
collection("/db/rangetest")
377+
//range:field-eq(
378+
("type", "subtype", "name"),
379+
"main", "official", ("Hofthiergarten", "Dorfprozelten"))
380+
/text()
381+
};
382+
372383
declare
373384
%test:assertEquals("Almweide")
374385
function rt:remove-document() {

0 commit comments

Comments
 (0)