/** * This method returns the left hand side of the declaration cast to the VariableExpression type. * This is an unsafe method to call. In a multiple assignment statement, the left hand side will * be a TupleExpression and a ClassCastException will occur. If you invoke this method then * be sure to invoke isMultipleAssignmentDeclaration() first to check that it is safe to do so. * If that method returns true then this method is safe to call. * * @return left hand side of normal variable declarations * @throws ClassCastException if the left hand side is not a VariableExpression (and is probably a multiple assignment statement). */ public VariableExpression getVariableExpression() { return (VariableExpression) this.getLeftExpression(); }
/** * This method tells you if this declaration is a multiple assignment declaration, which * has the form "def (x, y) = ..." in Groovy. If this method returns true, then the left * hand side is an ArgumentListExpression. Do not call "getVariableExpression()" on this * object if this method returns true, instead use "getLeftExpression()". * @return * true if this declaration is a multiple assignment declaration, which means the * left hand side is an ArgumentListExpression. */ public boolean isMultipleAssignmentDeclaration() { return getLeftExpression() instanceof TupleExpression; } }
/** * This method returns the left hand side of the declaration cast to the TupleExpression type. * This is an unsafe method to call. In a single assignment statement, the left hand side will * be a VariableExpression and a ClassCastException will occur. If you invoke this method then * be sure to invoke isMultipleAssignmentDeclaration() first to check that it is safe to do so. * If that method returns true then this method is safe to call. * @return * left hand side of multiple assignment declarations * @throws ClassCastException * if the left hand side is not a TupleExpression (and is probably a VariableExpression). * */ public TupleExpression getTupleExpression() { return (TupleExpression) this.getLeftExpression(); }
if (expr instanceof DeclarationExpression) { DeclarationExpression de = (DeclarationExpression) expr; if (de.getLeftExpression() == candidate.getLeftExpression()) { if (insideScriptBody) {
public void visitDeclarationExpression(DeclarationExpression expression) { //visitNode(expression); is visited afterwards in BinaryExpression. Because //super.visitDeclarationExpression calls visitBinaryExpression visitType(expression.getLeftExpression().getType()); super.visitDeclarationExpression(expression); }
ex = declaration.getLeftExpression(); if (ex instanceof TupleExpression) return false; declaration.getLeftExpression(), declaration.getOperation(), declaration.getRightExpression());
private Expression createDefaultValueInitializer(DeclarationExpression expr) { TupleExpression tupleExpr = ObjectUtil.asInstance(expr.getLeftExpression(), TupleExpression.class); if (tupleExpr == null) { return EmptyExpression.INSTANCE; } assert expr.isMultipleAssignmentDeclaration(); // initializing to empty list only works when none of the element types is primitive, // so create a proper list expression ListExpression listExpr = new ListExpression(); for (Expression elementExpr : tupleExpr.getExpressions()) { Variable variable = (Variable) elementExpr; listExpr.addExpression(new ConstantExpression( ReflectionUtil.getDefaultValue(variable.getOriginType().getTypeClass()))); } return listExpr; }
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; }
de.getLeftExpression(), de.getOperation(), de.getRightExpression());
@Override public void visitDeclarationExpression(DeclarationExpression expression) { Expression right = expression.getRightExpression(); right.visit(this); ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node); Expression rightExpression = expression.getRightExpression(); ClassNode rightType = optimizeDivWithIntOrLongTarget(rightExpression, leftType); if (rightType==null) rightType = typeChooser.resolveType(expression.getRightExpression(), node); if (isPrimitiveType(leftType) && isPrimitiveType(rightType)) { // if right is a constant, then we optimize only if it makes // a block complete, so we set a maybe if (right instanceof ConstantExpression) { opt.chainCanOptimize(true); } else { opt.chainShouldOptimize(true); } StatementMeta meta = addMeta(expression); ClassNode declarationType = typeChooser.resolveType(expression, node); meta.type = declarationType!=null?declarationType:leftType; opt.chainInvolvedType(leftType); opt.chainInvolvedType(rightType); } }
protected Expression transformDeclarationExpression(DeclarationExpression de) { visitAnnotations(de); Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) { fixDeclaringClass(de); return de; } DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setDeclaringClass(de.getDeclaringClass()); fixDeclaringClass(newDeclExpr); newDeclExpr.setSourcePosition(de); newDeclExpr.addAnnotations(de.getAnnotations()); return newDeclExpr; }
if (shouldTransform(de)) { candidate = null; Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right);
/** * This method tells you if this declaration is a multiple assignment declaration, which * has the form "def (x, y) = ..." in Groovy. If this method returns true, then the left * hand side is an ArgumentListExpression. Do not call "getVariableExpression()" on this * object if this method returns true, instead use "getLeftExpression()". * @return * true if this declaration is a multiple assignment declaration, which means the * left hand side is an ArgumentListExpression. */ public boolean isMultipleAssignmentDeclaration() { return getLeftExpression() instanceof TupleExpression; } }
public boolean isMultipleAssignmentDeclaration() { return getLeftExpression() instanceof ArgumentListExpression; } }
public void setRightExpression(Expression rightExpression) { check(getLeftExpression(),rightExpression); super.setRightExpression(rightExpression); }
public void setRightExpression(Expression rightExpression) { check(getLeftExpression(),rightExpression); super.setRightExpression(rightExpression); }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression((VariableExpression) transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; } }
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()); return ret; }