Merges adjacent operands. @param cc compilation context @return resulting expression or null @throws QueryException query exception
(final CompileContext cc)
| 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. |
nothing calls this directly
no test coverage detected