use of org.eclipse.persistence.jpa.jpql.parser.CompoundExpression in project eclipselink by eclipse-ee4j.
the class AbstractGrammarValidator method validateCompoundExpression.
protected void validateCompoundExpression(CompoundExpression expression, String identifier, String missingLeftExpression, String invalidLeftExpression, String missingRightExpression, String invalidRightExpression, String leftExpressionQueryBNF, String rightExpressionQueryBNF) {
// Missing left expression
if (!expression.hasLeftExpression()) {
int startPosition = position(expression);
addProblem(expression, startPosition, missingLeftExpression);
} else {
Expression leftExpression = expression.getLeftExpression();
// Invalid left expression
if (!isValid(leftExpression, leftExpressionQueryBNF)) {
int startPosition = position(expression);
int endPosition = startPosition + length(leftExpression);
addProblem(expression, startPosition, endPosition, invalidLeftExpression);
} else {
leftExpression.accept(this);
}
}
// Missing right expression
if (!expression.hasRightExpression()) {
int startPosition = position(expression) + length(expression.getLeftExpression()) + (expression.hasLeftExpression() ? 1 : 0) + identifier.length() + (expression.hasSpaceAfterIdentifier() ? 1 : 0);
addProblem(expression, startPosition, missingRightExpression);
} else {
Expression rightExpression = expression.getRightExpression();
// Invalid right expression
if (!isValid(rightExpression, rightExpressionQueryBNF)) {
int startPosition = position(expression) + length(expression.getLeftExpression()) + (expression.hasLeftExpression() ? 1 : 0) + identifier.length() + (expression.hasSpaceAfterIdentifier() ? 1 : 0);
int endPosition = startPosition + length(rightExpression);
addProblem(expression, startPosition, endPosition, invalidRightExpression);
} else {
rightExpression.accept(this);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.CompoundExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateFunctionPathExpression.
/**
* Validates the left and right expressions of the given compound expression. The test to perform is:
* <ul>
* <li>If the left or the right expression is a path expression, validation makes sure it is a
* basic mapping, an association field is not allowed.</li>
* </ul>
*
* @param expression The {@link CompoundExpression} to validate by validating its left and right
* expressions
* @param pathType The type of field that is allowed
* @return A number indicating the validation result. {@link #isValid(int, int)} can be used to
* determine the validation status of an expression based on its position
*/
protected int validateFunctionPathExpression(CompoundExpression expression, PathType pathType) {
int result = 0;
// Left expression
if (expression.hasLeftExpression()) {
Expression leftExpression = expression.getLeftExpression();
StateFieldPathExpression pathExpression = getStateFieldPathExpression(leftExpression);
if (pathExpression != null) {
boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
updateStatus(result, 0, valid);
} else {
leftExpression.accept(this);
}
}
// Right expression
if (expression.hasRightExpression()) {
Expression rightExpression = expression.getRightExpression();
StateFieldPathExpression pathExpression = getStateFieldPathExpression(rightExpression);
if (pathExpression != null) {
boolean valid = validateStateFieldPathExpression(pathExpression, pathType);
updateStatus(result, 1, valid);
} else {
rightExpression.accept(this);
}
}
return result;
}
use of org.eclipse.persistence.jpa.jpql.parser.CompoundExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method toStringCompound.
protected void toStringCompound(CompoundExpressionStateObject stateObject, String identifier) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
CompoundExpression expression = stateObject.getExpression();
// Left expression
if (stateObject.hasLeft()) {
stateObject.getLeft().accept(this);
writer.append(SPACE);
}
// Identifier
appendIdentifier((expression != null) ? expression.getActualIdentifier() : identifier, identifier);
if (shouldOutput(expression) || expression.hasSpaceAfterIdentifier()) {
writer.append(SPACE);
}
// Right expression
if (stateObject.hasRight()) {
stateObject.getRight().accept(this);
}
}
}
Aggregations