use of org.eclipse.persistence.jpa.jpql.parser.Expression in project eclipselink by eclipse-ee4j.
the class DefaultSemanticValidator method validateUpdateItemTypes.
protected void validateUpdateItemTypes(UpdateItem expression, Object type) {
if (expression.hasNewValue()) {
Expression newValue = expression.getNewValue();
ITypeHelper typeHelper = getTypeHelper();
boolean nullValue = isNullValue(newValue);
// assigned to a mapping of primitive type
if (nullValue) {
if (typeHelper.isPrimitiveType(type)) {
addProblem(expression, UpdateItem_NullNotAssignableToPrimitive);
}
return;
}
Object newValueType = getType(newValue);
// 2) Any classes related to a number, eg long/Long etc
if (!helper.isTypeResolvable(newValueType) || typeHelper.isDateType(type) && typeHelper.isDateType(newValueType) || (typeHelper.isNumericType(type) || typeHelper.isPrimitiveType(type)) && (typeHelper.isNumericType(newValueType) || typeHelper.isPrimitiveType(newValueType))) {
return;
}
// The new value's type can't be assigned to the item's type
if (!helper.isAssignableTo(newValueType, type)) {
addProblem(expression, UpdateItem_NotAssignable, helper.getTypeName(newValueType), helper.getTypeName(type));
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.Expression in project eclipselink by eclipse-ee4j.
the class DefaultSemanticValidator method validateMapIdentificationVariable.
protected void validateMapIdentificationVariable(EncapsulatedIdentificationVariableExpression expression) {
// or map-valued element collections
if (expression.hasExpression()) {
Expression childExpression = expression.getExpression();
String variableName = literal(childExpression, LiteralType.IDENTIFICATION_VARIABLE);
// Retrieve the identification variable's type without traversing the type parameters
if (ExpressionTools.stringIsNotEmpty(variableName)) {
Object typeDeclaration = helper.getTypeDeclaration(childExpression);
Object type = helper.getType(typeDeclaration);
if (!getTypeHelper().isMapType(type)) {
addProblem(childExpression, EncapsulatedIdentificationVariableExpression_NotMapValued, expression.getIdentifier());
}
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.Expression in project eclipselink by eclipse-ee4j.
the class EclipseLinkContentAssistVisitor method visit.
@Override
public void visit(CastExpression expression) {
super.visit(expression);
int position = queryPosition.getPosition(expression) - corrections.peek();
String identifier = expression.getIdentifier();
// Within CAST
if (isPositionWithin(position, identifier)) {
addIdentifier(identifier);
addIdentificationVariables();
addFunctionIdentifiers(expression.getParent().findQueryBNF(expression));
} else // After "CAST("
if (expression.hasLeftParenthesis()) {
int length = identifier.length() + 1;
// Right after "CAST("
if (position == length) {
addIdentificationVariables();
addFunctionIdentifiers(expression.getEncapsulatedExpressionQueryBNFId());
} else if (expression.hasExpression()) {
Expression scalarExpression = expression.getExpression();
if (isComplete(scalarExpression)) {
length += scalarExpression.getLength();
if (expression.hasSpaceAfterExpression()) {
length++;
// Right before "AS" or database type
if (position == length) {
addAggregateIdentifiers(expression.getEncapsulatedExpressionQueryBNFId());
proposals.addIdentifier(AS);
} else // Within "AS"
if (isPositionWithin(position, length, AS)) {
proposals.addIdentifier(AS);
}
}
}
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.Expression in project eclipselink by eclipse-ee4j.
the class EclipseLinkContentAssistVisitor method getTableName.
protected String getTableName(String variableName) {
Declaration declaration = queryContext.getDeclaration(variableName);
Expression baseExpression = (declaration != null) ? declaration.getBaseExpression() : null;
if ((baseExpression != null) && isTableExpression(baseExpression)) {
return queryContext.literal(baseExpression, LiteralType.STRING_LITERAL);
}
return null;
}
use of org.eclipse.persistence.jpa.jpql.parser.Expression in project eclipselink by eclipse-ee4j.
the class AbstractContentAssistVisitor method buildNonCollectionCompoundTypeFilter.
protected Filter<Expression> buildNonCollectionCompoundTypeFilter() {
return new Filter<Expression>() {
@Override
public boolean accept(Expression expression) {
IType type = queryContext.getType(expression);
TypeHelper typeHelper = queryContext.getTypeHelper();
return !typeHelper.isCollectionType(type) && !typeHelper.isMapType(type);
}
};
}
Aggregations