Skip to content

Commit 702faac

Browse files
committed
refactor: reduce PivotQuery visitor complexity
1 parent cfe3f07 commit 702faac

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -375,36 +375,33 @@ public <S> Void visit(PlainSelect plainSelect, S context) {
375375

376376
@Override
377377
public <S> Void visit(PivotQuery pivotQuery, S context) {
378-
List<WithItem<?>> withItemsList = pivotQuery.getWithItemsList();
379-
if (withItemsList != null && !withItemsList.isEmpty()) {
380-
for (WithItem<?> withItem : withItemsList) {
381-
withItem.accept((SelectVisitor<?>) this, context);
382-
}
383-
}
378+
visitWithItems(pivotQuery.getWithItemsList(), context);
379+
visitFromItem(pivotQuery.getFromItem(), context);
380+
visitExpressions(pivotQuery.getOnExpressions(), context);
381+
visitSelectItems(pivotQuery.getUsingItems(), context);
382+
visitExpressions(pivotQuery.getGroupByExpressions(), context);
383+
visitOrderBy(pivotQuery.getOrderByElements(), context);
384+
visitLimit(pivotQuery.getLimit(), context);
384385

385-
if (pivotQuery.getFromItem() != null) {
386-
pivotQuery.getFromItem().accept(this, context);
387-
}
388-
if (pivotQuery.getOnExpressions() != null) {
389-
pivotQuery.getOnExpressions().accept(this, context);
390-
}
391-
if (pivotQuery.getUsingItems() != null) {
392-
for (SelectItem<?> item : pivotQuery.getUsingItems()) {
386+
visitPivotPagination(pivotQuery, context);
387+
return null;
388+
}
389+
390+
private <S> void visitSelectItems(List<? extends SelectItem<?>> selectItems, S context) {
391+
if (selectItems != null) {
392+
for (SelectItem<?> item : selectItems) {
393393
item.accept(this, context);
394394
}
395395
}
396-
if (pivotQuery.getGroupByExpressions() != null) {
397-
pivotQuery.getGroupByExpressions().accept(this, context);
398-
}
399-
visitOrderBy(pivotQuery.getOrderByElements(), context);
400-
visitLimit(pivotQuery.getLimit(), context);
396+
}
397+
398+
private <S> void visitPivotPagination(PivotQuery pivotQuery, S context) {
401399
if (pivotQuery.getOffset() != null) {
402400
pivotQuery.getOffset().getOffset().accept(this, context);
403401
}
404402
if (pivotQuery.getFetch() != null && pivotQuery.getFetch().getExpression() != null) {
405403
pivotQuery.getFetch().getExpression().accept(this, context);
406404
}
407-
return null;
408405
}
409406

410407
@Override

0 commit comments

Comments
 (0)