/** * Returns the length of the string representation of the given {@link Expression}. * * @param expression The {@link Expression} to retrieve the length of its string * @return The length of the string representation of the given {@link Expression} */ protected int length(Expression expression) { return expression.getLength(); }
/** * Returns the length of the string representation of the given {@link Expression}. * * @param expression The {@link Expression} to retrieve the length of its string * @return The length of the string representation of the given {@link Expression} */ protected int length(Expression expression) { return expression.getLength(); }
/** * {@inheritDoc} */ public int preExpressionLength(IdentificationVariableDeclaration expression) { return expression.getRangeVariableDeclaration().getLength(); }
/** * {@inheritDoc} */ public int preExpressionLength(UpdateClause expression) { // There is a SPACE_LENGTH less, it's added automatically return UPDATE.length() + SPACE_LENGTH + expression.getRangeVariableDeclaration().getLength() + SPACE_LENGTH + SET.length(); }
/** * 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); }
/** * {@inheritDoc} */ @Override public void visit(EmptyCollectionComparisonExpression expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasExpression()) { length = expression.getExpression().getLength() + SPACE_LENGTH; } // Within the <identifier> if (isPositionWithin(position, length, expression.getIdentifier())) { proposals.addIdentifier(IS_EMPTY); proposals.addIdentifier(IS_NOT_EMPTY); } }
/** * {@inheritDoc} */ public void visit(JPQLExpression expression) { if (expression.hasQueryStatement()) { Expression queryStatement = expression.getQueryStatement(); queryStatement.accept(this); queryPosition.addPosition(expression, queryStatement.getLength() - correction); } else { queryPosition.setExpression(expression); queryPosition.addPosition(expression, 0); } }
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { int position = visitor.queryPosition.getPosition(expression) - visitor.corrections.peek(); int length = 0; if (expression.hasExpression()) { length += expression.getExpression().getLength() + SPACE_LENGTH; } // Within "IN" if (visitor.isPositionWithin(position, length, expression.getIdentifier())) { boolean hasOnlyIdentifier = !expression.hasExpression() && !expression.hasInItems(); if (hasOnlyIdentifier) { visitor.corrections.add(visitor.queryPosition.getPosition(expression)); } super.visit(expression); if (hasOnlyIdentifier) { visitor.corrections.pop(); } } else { super.visit(expression); } } }
/** * {@inheritDoc} */ @Override public void visit(NullComparisonExpression expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasExpression()) { length += expression.getExpression().getLength() + SPACE_LENGTH; } // Within "IS NULL" or "IS NOT NULL" if (isPositionWithin(position, length, expression.getIdentifier())) { proposals.addIdentifier(IS_NULL); proposals.addIdentifier(IS_NOT_NULL); } }
/** * {@inheritDoc} */ @Override public void visit(LikeExpression expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); if (expression.hasStringExpression()) { int length = expression.getStringExpression().getLength() + SPACE_LENGTH; // Within "LIKE" or "NOT LIKE" if (isPositionWithin(position, length, expression.getIdentifier())) { proposals.addIdentifier(LIKE); proposals.addIdentifier(NOT_LIKE); } // After "LIKE " or "NOT LIKE " else if (expression.hasSpaceAfterLike()) { length += expression.getIdentifier().length() + SPACE_LENGTH; // After "<pattern value> " if (expression.hasPatternValue() && expression.hasSpaceAfterPatternValue()) { length += expression.getPatternValue().getLength() + SPACE_LENGTH; // Within "ESCAPE" if (isPositionWithin(position, length, ESCAPE)) { proposals.addIdentifier(ESCAPE); } } } } }
/** * {@inheritDoc} */ @Override public void visit(IdentificationVariableDeclaration expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); if ((position > 0) && (expression.hasSpace() || hasVirtualSpace())) { Expression rangeVariableDeclaration = expression.getRangeVariableDeclaration(); int length = rangeVariableDeclaration.getLength() + SPACE_LENGTH; if (position == length) { if (isComplete(rangeVariableDeclaration)) { addJoinIdentifiers(); } } else { visitCollectionExpression(expression, ExpressionTools.EMPTY_STRING, getJoinCollectionHelper()); } } }
/** * {@inheritDoc} */ @Override public void visit(RangeVariableDeclaration expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); // After "<abstract schema name> " if (expression.hasRootObject()) { int length = expression.getRootObject().getLength(); // After "<abstract schema name> " if (expression.hasSpaceAfterRootObject()) { length++; // Right after "<abstract schema name> " if (position == length) { addIdentifier(AS); } // Within 'AS' else if (expression.hasAs() && isPositionWithin(position, length, AS)) { addIdentifier(AS); } } } }
/** * Visits the given {@link LogicalExpression} and attempts to find valid proposals. * * @param expression The {@link LogicalExpression} to inspect */ protected void visitLogicalExpression(LogicalExpression expression) { if (isFollowingInvalidExpression(expression)) { return; } int position = queryPosition.getPosition(expression) - corrections.peek(); String identifier = expression.getIdentifier(); int length = 0; if (expression.hasLeftExpression()) { length += expression.getLeftExpression().getLength() + SPACE_LENGTH; } // Within "AND" or "OR" if (isPositionWithin(position, length, identifier)) { proposals.addIdentifier(identifier); } // After "AND " or "OR " else if (expression.hasSpaceAfterIdentifier()) { length += identifier.length() + SPACE_LENGTH; // Right after "AND " or "OR " if (position == length) { addIdentificationVariables(); addFunctionIdentifiers(expression.getRightExpressionQueryBNFId()); } } }
/** * Visits the given {@link ArithmeticExpression} and attempts to find valid proposals. * * @param expression The {@link ArithmeticExpression} to inspect */ protected void visitArithmeticExpression(ArithmeticExpression expression) { int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasLeftExpression()) { length += expression.getLeftExpression().getLength() + SPACE_LENGTH; } // Within the arithmetic sign if (isPositionWithin(position, length, PLUS)) { addAggregateIdentifiers(expression.getQueryBNF()); } // After the arithmetic sign, with or without the space else if (expression.hasSpaceAfterIdentifier()) { length += 2; // Right after the space if (position == length) { addIdentificationVariables(); addFunctionIdentifiers(expression.getRightExpressionQueryBNFId()); } } }
/** * {@inheritDoc} */ @Override public void visit(RegexpExpression expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasStringExpression()) { length += expression.getStringExpression().getLength(); if (expression.hasSpaceAfterStringExpression()) { length += SPACE_LENGTH; } } // Within "REGEXP" if (isPositionWithin(position, length, REGEXP)) { proposals.addIdentifier(REGEXP); } // After "REGEXP" else { length += 6 /* REGEXP */; // After "REGEXP " if (expression.hasSpaceAfterIdentifier()) { length += SPACE_LENGTH; // Right after "REGEXP " addIdentificationVariables(); addFunctionIdentifiers(PatternValueBNF.ID); } } }
/** * {@inheritDoc} */ @Override public void visit(ComparisonExpression expression) { super.visit(expression); int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasLeftExpression()) { length += expression.getLeftExpression().getLength() + SPACE_LENGTH; } // Within the comparison operator if (isPositionWithin(position, length, expression.getComparisonOperator())) { addExpressionFactoryIdentifiers(ComparisonExpressionFactory.ID); } // After the comparison operator length += expression.getComparisonOperator().length(); if (expression.hasSpaceAfterIdentifier()) { length++; } // Right after the comparison operator if (position == length) { addIdentificationVariables(); addFunctionIdentifiers(expression.getRightExpressionQueryBNFId()); addClauseIdentifiers(expression.getRightExpressionQueryBNFId()); } }
length = expression.getExpression().getLength() + SPACE_LENGTH;
expression.hasSpaceAfterStateFieldPathExpression()) { length += expression.getStateFieldPathExpression().getLength() + SPACE_LENGTH;
int length = selectItem.getLength() + SPACE_LENGTH;