// the FROM clause, and an identification variable declaration can use the result
// of a preceding identification variable declaration of the query string
List<Declaration> declarations = queryContext.getDeclarations();
for (int index = 0, count = declarations.size(); index < count; index++) {
Declaration declaration = declarations.get(index);
// Check the JOIN expressions in the identification variable declaration
if (declaration.isRange() && declaration.hasJoins()) {
List<Map.Entry<Join, String>> joinEntries = declaration.getJoinEntries();
for (int joinIndex = 0, joinCount = joinEntries.size(); joinIndex < joinCount; joinIndex++) {
Map.Entry<Join, String> joinEntry = joinEntries.get(joinIndex);
Join join = joinEntry.getKey();
// Retrieve the identification variable from the join association path
String variableName = queryContext.literal(
join.getJoinAssociationPath(),
LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE
);
// Make sure the identification variable is defined before the JOIN expression
if (ExpressionTools.stringIsNotEmpty(variableName) &&
!isIdentificationVariableDeclaredBefore(variableName, index, joinIndex, declarations)) {
int startPosition = position(join.getJoinAssociationPath());
int endPosition = startPosition + variableName.length();
addProblem(
expression,
startPosition,
endPosition,
AbstractFromClause_WrongOrderOfIdentificationVariableDeclaration,
variableName
);
}
}
}
// Check the collection member declaration
else if (!declaration.isRange()) {
// Retrieve the identification variable from the path expression
String variableName = queryContext.literal(
declaration.getBaseExpression(),
LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE
);
if (ExpressionTools.stringIsNotEmpty(variableName) &&
!isIdentificationVariableDeclaredBefore(variableName, index, -1, declarations)) {
int startPosition = position(declaration.getDeclarationExpression()) - variableName.length();
int endPosition = startPosition + variableName.length();
addProblem(
expression,
startPosition,