use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class SqlWhereVisitor method visitBinaryExpression.
public void visitBinaryExpression(BinaryExpression expression) {
Expression left = expression.getLeftExpression();
Expression right = expression.getRightExpression();
boolean leaf = (right instanceof ConstantExpression || left instanceof ConstantExpression);
if (!leaf)
buffer.append("(");
left.visit(this);
buffer.append(" ");
Token token = expression.getOperation();
buffer.append(tokenAsSql(token));
buffer.append(" ");
right.visit(this);
if (!leaf)
buffer.append(")");
}
use of org.codehaus.groovy.ast.expr.Expression in project spring-boot by spring-projects.
the class GenericBomAstTransformation method addDependencyManagementBom.
private void addDependencyManagementBom(ModuleNode node, String module) {
AnnotatedNode annotated = getAnnotatedNode(node);
if (annotated != null) {
AnnotationNode bom = getAnnotation(annotated);
List<Expression> expressions = new ArrayList<>(getConstantExpressions(bom.getMember("value")));
expressions.add(new ConstantExpression(module));
bom.setMember("value", new ListExpression(expressions));
}
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy by apache.
the class SuperCallTraitTransformer method transformBinaryExpression.
private Expression transformBinaryExpression(final BinaryExpression exp) {
Expression trn = super.transform(exp);
if (trn instanceof BinaryExpression) {
BinaryExpression bin = (BinaryExpression) trn;
Expression leftExpression = bin.getLeftExpression();
if (bin.getOperation().getType() == Types.EQUAL && leftExpression instanceof PropertyExpression) {
ClassNode traitReceiver = null;
PropertyExpression leftPropertyExpression = (PropertyExpression) leftExpression;
if (isTraitSuperPropertyExpression(leftPropertyExpression.getObjectExpression())) {
PropertyExpression pexp = (PropertyExpression) leftPropertyExpression.getObjectExpression();
traitReceiver = pexp.getObjectExpression().getType();
}
if (traitReceiver != null) {
// A.super.foo = ...
TraitHelpersTuple helpers = Traits.findHelpers(traitReceiver);
ClassNode helper = helpers.getHelper();
String setterName = MetaProperty.getSetterName(leftPropertyExpression.getPropertyAsString());
List<MethodNode> methods = helper.getMethods(setterName);
for (MethodNode method : methods) {
Parameter[] parameters = method.getParameters();
if (parameters.length == 2 && parameters[0].getType().equals(traitReceiver)) {
ArgumentListExpression args = new ArgumentListExpression(new VariableExpression("this"), transform(exp.getRightExpression()));
MethodCallExpression setterCall = new MethodCallExpression(new ClassExpression(helper), setterName, args);
setterCall.setMethodTarget(method);
setterCall.setImplicitThis(false);
return setterCall;
}
}
return bin;
}
}
}
return trn;
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy by apache.
the class Verifier method addFieldInitialization.
protected void addFieldInitialization(List list, List staticList, FieldNode fieldNode, boolean isEnumClassNode, List initStmtsAfterEnumValuesInit, Set explicitStaticPropsInEnum) {
Expression expression = fieldNode.getInitialExpression();
if (expression != null) {
final FieldExpression fe = new FieldExpression(fieldNode);
if (fieldNode.getType().equals(ClassHelper.REFERENCE_TYPE) && ((fieldNode.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0)) {
fe.setUseReferenceDirectly(true);
}
ExpressionStatement statement = new ExpressionStatement(new BinaryExpression(fe, Token.newSymbol(Types.EQUAL, fieldNode.getLineNumber(), fieldNode.getColumnNumber()), expression));
if (fieldNode.isStatic()) {
// GROOVY-3311: pre-defined constants added by groovy compiler for numbers/characters should be
// initialized first so that code dependent on it does not see their values as empty
Expression initialValueExpression = fieldNode.getInitialValueExpression();
if (initialValueExpression instanceof ConstantExpression) {
ConstantExpression cexp = (ConstantExpression) initialValueExpression;
cexp = transformToPrimitiveConstantIfPossible(cexp);
if (fieldNode.isFinal() && ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(fieldNode.getType())) {
// GROOVY-5150: primitive type constants will be initialized directly
return;
}
staticList.add(0, statement);
} else {
staticList.add(statement);
}
// to avoid double initialization in case of several constructors
fieldNode.setInitialValueExpression(null);
/*
* If it is a statement for an explicitly declared static field inside an enum, store its
* reference. For enums, they need to be handled differently as such init statements should
* come after the enum values have been initialized inside <clinit> block. GROOVY-3161.
*/
if (isEnumClassNode && explicitStaticPropsInEnum.contains(fieldNode.getName())) {
initStmtsAfterEnumValuesInit.add(statement);
}
} else {
list.add(statement);
}
}
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy by apache.
the class BinaryExpressionHelper method evaluateBinaryExpressionWithAssignment.
protected void evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression) {
Expression leftExpression = expression.getLeftExpression();
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
if (leftExpression instanceof BinaryExpression) {
BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
evaluateArrayAssignmentWithOperator(method, expression, leftBinExpr);
return;
}
}
evaluateBinaryExpression(method, expression);
// br to leave a copy of rvalue on the stack. see also isPopRequired()
operandStack.dup();
controller.getCompileStack().pushLHS(true);
leftExpression.visit(acg);
controller.getCompileStack().popLHS();
}
Aggregations