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

Method merge

basex-core/src/main/java/org/basex/query/expr/Mapping.java:157–196  ·  view source on GitHub ↗

Merges adjacent operands. @param cc compilation context @return resulting expression or null @throws QueryException query exception

(final CompileContext cc)

Source from the content-addressed store, hash-verified

155 * @throws QueryException query exception
156 */
157 final Expr[] merge(final CompileContext cc) throws QueryException {
158 final int el = exprs.length;
159 final ExprList list = new ExprList(el).add(exprs[0]);
160
161 boolean pushed = false;
162 try {
163 final boolean items = items();
164 for(int e = 1; e < el; e++) {
165 final Expr merged = merge(list.peek(), exprs[e], cc);
166 if(merged != null) {
167 list.set(list.size() - 1, merged);
168 } else {
169 list.add(exprs[e]);
170 }
171 if(list.size() > 1) {
172 final Expr expr = list.get(list.size() - 2);
173 if(pushed) {
174 cc.updateFocus(expr, items);
175 } else {
176 cc.pushFocus(expr, items);
177 pushed = true;
178 }
179 }
180 }
181 } finally {
182 if(pushed) cc.removeFocus();
183 }
184
185 // remove context value references (ignore first expression)
186 // (1 to 10) ! . → (1 to 10)
187 for(int n = list.size() - 1; n > 0; n--) {
188 if(list.get(n) instanceof ContextValue) list.remove(n);
189 }
190
191 final int ls = list.size();
192 if(ls == el) return null;
193
194 cc.info(OPTSIMPLE_X_X, (Supplier<?>) this::description, this);
195 return list.finish();
196 }
197
198 /**
199 * Merges adjacent operands.

Callers

nothing calls this directly

Calls 12

itemsMethod · 0.95
updateFocusMethod · 0.80
removeFocusMethod · 0.80
addMethod · 0.65
setMethod · 0.65
sizeMethod · 0.65
getMethod · 0.65
removeMethod · 0.65
infoMethod · 0.65
peekMethod · 0.45
pushFocusMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected