MCPcopy Create free account
hub / github.com/BaseXdb/basex / item

Method item

basex-core/src/main/java/org/basex/query/func/Closure.java:332–365  ·  view source on GitHub ↗
(final QueryContext qc, final InputInfo ii)

Source from the content-addressed store, hash-verified

330 }
331
332 @Override
333 public FuncItem item(final QueryContext qc, final InputInfo ii) throws QueryException {
334 final Expr body;
335 if(global.isEmpty()) {
336 body = expr;
337 } else {
338 // collect closure
339 final LinkedList<Clause> clauses = new LinkedList<>();
340 for(final Entry<Var, Expr> entry : global.entrySet()) {
341 clauses.add(new Let(entry.getKey(), entry.getValue().value(qc)));
342 }
343 body = new GFLWOR(info, clauses, expr);
344 }
345
346 final SeqType argType = body.seqType();
347 final Expr checked;
348 if(declType == null || argType.instanceOf(declType)) {
349 // return type is already correct
350 checked = body;
351 } else if(body instanceof final Value value) {
352 // we can type check immediately
353 checked = declType.coerce(value, qc, info, name, null);
354 } else {
355 // check at each call: reject impossible arities
356 if(argType.type.instanceOf(declType.type) && argType.occ.intersect(declType.occ) == null &&
357 !body.has(Flag.NDT)) {
358 throw typeError(body, declType, name, info);
359 }
360 checked = new TypeCheck(info, body, declType);
361 }
362
363 final FuncType ft = (FuncType) seqType().type;
364 return new FuncItem(info, checked, params, anns, ft, vs.stackSize(), name);
365 }
366
367 @Override
368 public boolean has(final Flag... flags) {

Callers

nothing calls this directly

Calls 14

seqTypeMethod · 0.95
instanceOfMethod · 0.95
hasMethod · 0.95
getKeyMethod · 0.80
stackSizeMethod · 0.80
addMethod · 0.65
instanceOfMethod · 0.65
intersectMethod · 0.65
seqTypeMethod · 0.65
isEmptyMethod · 0.45
valueMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected