/** * Calculates the position of the given {@link Expression} by calculating the length of what is before. * * @param expression The {@link Expression} for which its position within the parsed tree needs * to be determined * @param length The current cursor position within the JPQL query while digging into the tree * until the search reaches the expression * @return The length of the string representation for what is coming before the given {@link Expression} * @since 2.4 */ protected final int calculatePosition(Expression expression, int length) { Expression parent = expression.getParent(); // Reach the root if (parent == null) { return length; } // Traverse the child expression until the expression for (Expression childExpression : parent.orderedChildren()) { // Continue to calculate the position by going up the hierarchy if (childExpression == expression) { return calculatePosition(parent, length); } length += childExpression.getLength(); } // It should never reach this throw new RuntimeException("The position of the Expression could not be calculated: " + expression); }
/** * Calculates the position of the given {@link Expression} by calculating the length of what is before. * * @param expression The {@link Expression} for which its position within the parsed tree needs * to be determined * @param length The current cursor position within the JPQL query while digging into the tree * until the search reaches the expression * @return The length of the string representation for what is coming before the given {@link Expression} * @since 2.4 */ protected final int calculatePosition(Expression expression, int length) { Expression parent = expression.getParent(); // Reach the root if (parent == null) { return length; } // Traverse the child expression until the expression for (Expression childExpression : parent.orderedChildren()) { // Continue to calculate the position by going up the hierarchy if (childExpression == expression) { return calculatePosition(parent, length); } length += childExpression.getLength(); } // It should never reach this throw new RuntimeException("The position of the Expression could not be calculated: " + expression); }