* @return The status of the comparison between the left and right expression: <code>true</code>
* if the two expressions pass the rules defined by this method; <code>false</code> otherwise
*/
protected boolean validateComparisonExpression(ComparisonExpression expression) {
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
boolean valid = true;
// First determine what is being compared and validate them as well
ComparisonExpressionVisitor validator = getComparisonExpressionVisitor();
try {
// Visit the left expression and gather its information
validator.validatingLeftExpression = true;
leftExpression.accept(validator);
// Visit the right expression and gather its information
validator.validatingLeftExpression = false;
rightExpression.accept(validator);
// '<', '<=', '>=', '>'
if (isOrderComparison(expression)) {
// The left expression cannot be an identification variable
if (validator.leftIdentificationVariable &&
validator.leftIdentificationVariableValid) {
IdentificationVariable variable = (IdentificationVariable) leftExpression;
// There is a specific EclipseLink case where it is valid to use an
// identification variable, which is when the identification variable
// maps to a direct collection mapping
if (!isIdentificationVariableValidInComparison(variable)) {
addProblem(
leftExpression,
ComparisonExpression_IdentificationVariable,
leftExpression.toActualText(),
expression.getComparisonOperator()
);
valid = false;
}
}
// The left expression is a path expression
else if (validator.leftStateFieldPathExpression &&
validator.leftStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(leftExpression);
// The path expression cannot be a non-basic mapping
if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
addProblem(
leftExpression,
ComparisonExpression_AssociationField,
leftExpression.toActualText(),
expression.getComparisonOperator()
);
valid = false;
}
}
// The right expression cannot be an identification variable
if (validator.rightIdentificationVariable &&
validator.rightIdentificationVariableValid) {
IdentificationVariable variable = (IdentificationVariable) rightExpression;
// There is a specific EclipseLink case where it is valid to use an
// identification variable, which is when the identification variable
// maps to a direct collection mapping
if (!isIdentificationVariableValidInComparison(variable)) {
addProblem(
rightExpression,
ComparisonExpression_IdentificationVariable,
rightExpression.toActualText(),
expression.getComparisonOperator()
);
valid = false;
}
}
// The right expression is a path expression
else if (validator.rightStateFieldPathExpression &&
validator.rightStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(rightExpression);
// The path expression cannot be a non-basic mapping
if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
addProblem(
rightExpression,
ComparisonExpression_AssociationField,
rightExpression.toActualText(),
expression.getComparisonOperator()
);
valid = false;
}
}
}
// '=', '<>'
else {
// The left expression is an identification variable
// The right expression is a path expression
if (validator.leftIdentificationVariable &&
validator.leftIdentificationVariableValid &&
validator.rightStateFieldPathExpression &&
validator.rightStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(rightExpression);
IdentificationVariable variable = (IdentificationVariable) leftExpression;
// The path expression can only be a non-basic mapping.
// There is a specific EclipseLink case where it is valid to use an
// identification variable, which is when the identification variable
// maps to a direct collection mapping
if ((mapping != null) && helper.isPropertyMapping(mapping) &&
!isIdentificationVariableValidInComparison(variable)) {
addProblem(
rightExpression,
ComparisonExpression_BasicField,
rightExpression.toActualText(),
expression.getComparisonOperator()
);
valid = false;
}