public static Expression getInvocationTarget(Expression expr) { if (expr instanceof PropertyExpression) return ((PropertyExpression) expr).getObjectExpression(); if (expr instanceof MethodCallExpression) return ((MethodCallExpression) expr).getObjectExpression(); if (expr instanceof StaticMethodCallExpression) return new ClassExpression(((StaticMethodCallExpression) expr).getOwnerType()); if (expr instanceof ConstructorCallExpression) return new ClassExpression(((ConstructorCallExpression) expr).getType()); return null; }
public static MethodCallExpression createGetAtMethod(Expression expression, int index) { return new MethodCallExpression(expression, GET_AT_METHOD_NAME, new ConstantExpression(index)); }
private void call(String method, Expression... args) { builderExpr = new MethodCallExpression( builderExpr, method, new ArgumentListExpression(args)); }
private MethodCallExpression referenceToCurrentClosure() { return new MethodCallExpression( new VariableExpression("this"), new ConstantExpression("each"), new ArgumentListExpression( new PropertyExpression( new ClassExpression(ClassHelper.makeWithoutCaching(Closure.class)), new ConstantExpression("IDENTITY") ) ) ); }
private Expression unrecord(Expression expr) { if (!(expr instanceof MethodCallExpression)) return expr; MethodCallExpression methodExpr = (MethodCallExpression) expr; Expression targetExpr = methodExpr.getObjectExpression(); if (!(targetExpr instanceof VariableExpression)) return expr; VariableExpression var = (VariableExpression)targetExpr; if (!SpockNames.VALUE_RECORDER.equals(var.getName())) return expr; if(!ValueRecorder.RECORD.equals(methodExpr.getMethodAsString())) return expr; return ((ArgumentListExpression)methodExpr.getArguments()).getExpression(1); }
private Expression copyLhsVariableExpressions(DeclarationExpression declExpr) { if (declExpr.isMultipleAssignmentDeclaration()) { ArgumentListExpression result = new ArgumentListExpression(); for (Expression expr : declExpr.getTupleExpression().getExpressions()) { result.addExpression(copyVarExpr((VariableExpression) expr)); } return result; } return copyVarExpr(declExpr.getVariableExpression()); }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); ret.addAnnotations(getAnnotations()); ret.setDeclaringClass(getDeclaringClass()); ret.copyNodeMetaData(this); return ret; }
private BinaryExpression createVariableNotNullExpression(VariableExpression var) { return new BinaryExpression( new VariableExpression(var), Token.newSymbol(Types.COMPARE_NOT_EQUAL, -1, -1), new ConstantExpression(null)); }
public static Expression getVariableType(BinaryExpression assignment) { ClassNode type = assignment.getLeftExpression().getType(); return type == null || type == ClassHelper.DYNAMIC_TYPE ? ConstantExpression.NULL : new ClassExpression(type); }
public static Expression getVariableName(BinaryExpression assignment) { Expression left = assignment.getLeftExpression(); if (left instanceof Variable) return new ConstantExpression(((Variable) left).getName()); if (left instanceof FieldExpression) return new ConstantExpression(((FieldExpression) left).getFieldName()); return ConstantExpression.NULL; }
public static Expression getArguments(Expression invocation) { if (invocation instanceof MethodCallExpression) return ((MethodCallExpression) invocation).getArguments(); if (invocation instanceof StaticMethodCallExpression) return ((StaticMethodCallExpression) invocation).getArguments(); if (invocation instanceof ConstructorCallExpression) return ((ConstructorCallExpression) invocation).getArguments(); return null; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new NotExpression(transformer.transform(getExpression())); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; } }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new ElvisOperatorExpression( transformer.transform(getTrueExpression()), transformer.transform(getFalseExpression())); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; } }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new BinaryExpression(transformer.transform(leftExpression), operation, transformer.transform(rightExpression)); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new MapEntryExpression(transformer.transform(keyExpression), transformer.transform(valueExpression)); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
public void visitBooleanExpression(BooleanExpression expression) { expression.getExpression().visit(this); }
public static String getMethodName(Expression invocation) { if (invocation instanceof MethodCallExpression) { return ((MethodCallExpression) invocation).getMethodAsString(); } if (invocation instanceof StaticMethodCallExpression) { return ((StaticMethodCallExpression) invocation).getMethod(); } return null; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new UnaryMinusExpression(transformer.transform(expression)); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new SpreadExpression(transformer.transform(expression)); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
public static boolean isInvocationWithImplicitThis(Expression invocation) { if (invocation instanceof PropertyExpression) { return ((PropertyExpression) invocation).isImplicitThis(); } if (invocation instanceof MethodCallExpression) { return ((MethodCallExpression) invocation).isImplicitThis(); } return false; }