use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class SqlValidator method visitForNode.
@Override
public Void visitForNode(ForNode node, Void p) {
SqlLocation location = node.getLocation();
String identifier = node.getIdentifier();
String expression = node.getExpression();
TypeDeclaration typeDeclaration = validateExpressionVariable(location, expression);
TypeMirror typeMirror = typeDeclaration.getType();
List<? extends TypeMirror> typeArgs;
if (ctx.getMoreTypes().isAssignableWithErasure(typeMirror, Iterable.class)) {
DeclaredType declaredType = ctx.getMoreTypes().toDeclaredType(typeMirror);
typeArgs = declaredType.getTypeArguments();
} else if (ctx.getMoreTypes().isArray(typeMirror)) {
ArrayType arrayType = ctx.getMoreTypes().toArrayType(typeMirror);
typeArgs = Collections.singletonList(arrayType.getComponentType());
} else {
String sql = getSql(location);
throw new AptException(Message.DOMA4149, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
}
if (typeArgs.isEmpty()) {
String sql = getSql(location);
throw new AptException(Message.DOMA4150, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
}
TypeMirror originalIdentifierType = expressionValidator.removeParameterType(identifier);
expressionValidator.putParameterType(identifier, typeArgs.get(0));
String hasNextVariable = identifier + ForBlockNode.HAS_NEXT_SUFFIX;
TypeMirror originalHasNextType = expressionValidator.removeParameterType(hasNextVariable);
expressionValidator.putParameterType(hasNextVariable, ctx.getMoreTypes().getTypeMirror(boolean.class));
String indexVariable = identifier + ForBlockNode.INDEX_SUFFIX;
TypeMirror originalIndexType = expressionValidator.removeParameterType(indexVariable);
expressionValidator.putParameterType(indexVariable, ctx.getMoreTypes().getTypeMirror(int.class));
visitNode(node, p);
if (originalIdentifierType == null) {
expressionValidator.removeParameterType(identifier);
} else {
expressionValidator.putParameterType(identifier, originalIdentifierType);
}
if (originalHasNextType == null) {
expressionValidator.removeParameterType(hasNextVariable);
} else {
expressionValidator.putParameterType(hasNextVariable, originalHasNextType);
}
if (originalIndexType == null) {
expressionValidator.removeParameterType(indexVariable);
} else {
expressionValidator.putParameterType(indexVariable, originalIndexType);
}
return null;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class SqlValidator method visitElseifNode.
@Override
public Void visitElseifNode(ElseifNode node, Void p) {
SqlLocation location = node.getLocation();
String expression = node.getExpression();
TypeDeclaration typeDeclaration = validateExpressionVariable(location, expression);
if (!typeDeclaration.isBooleanType()) {
String sql = getSql(location);
throw new AptException(Message.DOMA4141, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
}
visitNode(node, p);
return null;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class SqlValidator method visitEmbeddedVariableNode.
@Override
public Void visitEmbeddedVariableNode(EmbeddedVariableNode node, Void p) {
SqlLocation location = node.getLocation();
String variableName = node.getVariableName();
validateExpressionVariable(location, variableName);
visitNode(node, p);
return null;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class SqlValidator method visitExpandNode.
@Override
public Void visitExpandNode(ExpandNode node, Void p) {
if (!expandable) {
SqlLocation location = node.getLocation();
String sql = getSql(location);
throw new AptException(Message.DOMA4257, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition() });
}
return visitNode(node, p);
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class AbstractSelectQuery method expandColumns.
protected List<String> expandColumns(ExpandNode node) {
if (entityType == null) {
SqlLocation location = node.getLocation();
throw new JdbcException(Message.DOMA2144, location.getSql(), location.getLineNumber(), location.getPosition());
}
Naming naming = config.getNaming();
Dialect dialect = config.getDialect();
return entityType.getEntityPropertyTypes().stream().map(p -> p.getColumnName(naming::apply, dialect::applyQuote)).collect(Collectors.toList());
}
Aggregations