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

Method optimize

basex-core/src/main/java/org/basex/query/expr/Cast.java:32–49  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

30 }
31
32 @Override
33 public Expr optimize(final CompileContext cc) throws QueryException {
34 super.optimize(cc);
35 if((ZERO_OR_ONE.is(expr) || EXACTLY_ONE.is(expr) || ONE_OR_MORE.is(expr)) &&
36 seqType.occ.instanceOf(expr.seqType().occ)) expr = expr.arg(0);
37
38 final SeqType st = castType();
39 exprType.assign(st);
40
41 final Boolean test = castable(st);
42 if(test == Boolean.FALSE) throw typeError(expr, seqType, info);
43 if(test == Boolean.TRUE) return cc.replaceWith(this, expr);
44
45 final Expr arg = simplify(st, cc);
46 if(arg != null) return new Cast(info, arg, seqType).optimize(cc);
47
48 return expr instanceof Value ? cc.preEval(this) : this;
49 }
50
51 @Override
52 public Value value(final QueryContext qc) throws QueryException {

Callers

nothing calls this directly

Calls 11

castTypeMethod · 0.80
replaceWithMethod · 0.80
isMethod · 0.65
instanceOfMethod · 0.65
seqTypeMethod · 0.65
argMethod · 0.45
assignMethod · 0.45
castableMethod · 0.45
typeErrorMethod · 0.45
simplifyMethod · 0.45
preEvalMethod · 0.45

Tested by

no test coverage detected