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

Method flatten

basex-core/src/main/java/org/basex/query/expr/path/Path.java:267–296  ·  view source on GitHub ↗

Flattens nested path expressions. @param cc compilation context @return original or optimized expression

(final CompileContext cc)

Source from the content-addressed store, hash-verified

265 * @return original or optimized expression
266 */
267 private Expr flatten(final CompileContext cc) {
268 // new list with steps
269 boolean changed = false;
270 final ExprList tmp = new ExprList(steps.length);
271
272 // flatten nested path
273 Expr rt = root;
274 if(rt instanceof final Path path) {
275 tmp.add(path.steps);
276 rt = path.root;
277 cc.info(QueryText.OPTFLAT_X_X, (Supplier<?>) path::description, path);
278 changed = true;
279 }
280
281 // add steps of input array
282 for(final Expr step : steps) {
283 Expr expr = step;
284 if(expr instanceof final Path path) {
285 // rewrite nested path to axis steps
286 if(path.root != null && !(path.root instanceof ContextValue)) tmp.add(path.root);
287 final int pl = path.steps.length - 1;
288 for(int i = 0; i < pl; i++) tmp.add(path.steps[i]);
289 expr = path.steps[pl];
290 cc.info(QueryText.OPTFLAT_X_X, (Supplier<?>) path::description, path);
291 changed = true;
292 }
293 tmp.add(expr);
294 }
295 return changed ? get(info, rt, tmp.finish()) : this;
296 }
297
298 /**
299 * Simplifies the path expression.

Callers 1

optimizeMethod · 0.95

Calls 4

getMethod · 0.95
addMethod · 0.65
infoMethod · 0.65
finishMethod · 0.45

Tested by

no test coverage detected