Refine search
public static Statement declS(Expression target, Expression init) { return new ExpressionStatement(new DeclarationExpression(target, ASSIGN, init)); }
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; }
} else if (statement instanceof ExpressionStatement) { ExpressionStatement es = (ExpressionStatement) statement; ex = es.getExpression(); } else { throw new GroovyBugError("unknown statement type :"+statement.getClass()); ex = declaration.getLeftExpression(); if (ex instanceof TupleExpression) return false; meta.declaredVariableExpression = declaration.getVariableExpression(); declaration.getLeftExpression(), declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration); assignment.copyNodeMetaData(declaration); } else if (statement instanceof ExpressionStatement) { ExpressionStatement es = (ExpressionStatement) statement; es.setExpression(assignment); } else { throw new GroovyBugError("unknown statement type :"+statement.getClass());
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; }
@Override public void visitDeclarationExpression(DeclarationExpression expression) { if(expression.isMultipleAssignmentDeclaration()) return; VariableExpression variableExpression = expression.getVariableExpression(); if (isValueRecorderExpression(variableExpression)) { valueRecorderIndex++; expression.setLeftExpression(valueRecorderExpression()); } else if (isErrorCollectorExpression(variableExpression)) { errorCollectorIndex++; expression.setLeftExpression(errorCollectorExpression()); } super.visitDeclarationExpression(expression); }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
de.getLeftExpression(), de.getOperation(), de.getRightExpression()); expressions.set(i, be); de.setRightExpression(ConstantExpression.NULL); visitDeclarationExpression(de);
@Override public void visitExpressionStatement(ExpressionStatement es) { Expression exp = es.getExpression(); if (exp instanceof DeclarationExpression) { DeclarationExpression de = (DeclarationExpression) exp; Expression leftExpression = de.getLeftExpression(); if (leftExpression instanceof VariableExpression) { // Only cast and transform if the RHS is *not* an EmptyExpression, i.e., "String foo;" would not be cast/transformed. if (!(de.getRightExpression() instanceof EmptyExpression) && mightBePositionalArgumentConstructor((VariableExpression) leftExpression)) { CastExpression ce = new CastExpression(leftExpression.getType(), de.getRightExpression()); ce.setCoerce(true); es.setExpression(transform(new DeclarationExpression(leftExpression, de.getOperation(), ce))); return; } } else { throw new UnsupportedOperationException("not supporting tuples yet"); // cf. "Unexpected LHS of an assignment" above } } super.visitExpressionStatement(es); }
if (shouldTransform(de)) { candidate = null; Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right); newDecl.addAnnotations(de.getAnnotations()); return newDecl;
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } Expression value = node.getMember("value"); if (value != null) { addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value); return; } ClassNode cNode = de.getDeclaringClass(); ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference(); de.setRightExpression(new VariableExpression("this")); changeBaseScriptType(de, cNode, baseScriptType); }
private void extractModelTypesFromStatement(final Statement code, final Map<String, ClassNode> model) { if (code instanceof BlockStatement) { BlockStatement block = (BlockStatement) code; for (Statement statement : block.getStatements()) { extractModelTypesFromStatement(statement, model); } } else if (code instanceof ExpressionStatement) { Expression expression = ((ExpressionStatement) code).getExpression(); if (expression instanceof DeclarationExpression) { VariableExpression var = ((DeclarationExpression) expression).getVariableExpression(); model.put(var.getName(), var.getOriginType()); } } }
private void moveVariableDeclarations(List<Statement> from, List<Statement> to) { for (Statement stat : from) { DeclarationExpression declExpr = AstUtil.getExpression(stat, DeclarationExpression.class); if (declExpr == null) continue; ((ExpressionStatement) stat).setExpression( new BinaryExpression( copyLhsVariableExpressions(declExpr), Token.newSymbol(Types.ASSIGN, -1, -1), declExpr.getRightExpression())); declExpr.setRightExpression(createDefaultValueInitializer(declExpr)); to.add(new ExpressionStatement(declExpr)); } }
private void rewriteDerivedParameterization(BinaryExpression parameterization, Statement enclosingStat) throws InvalidSpecCompileException { VariableExpression dataVar = createDataProcessorVariable(parameterization.getLeftExpression(), enclosingStat); ExpressionStatement exprStat = new ExpressionStatement( new DeclarationExpression( dataVar, Token.newSymbol(Types.ASSIGN, -1, -1), parameterization.getRightExpression())); exprStat.setSourcePosition(enclosingStat); dataProcessorStats.add(exprStat); }
public void visitDeclarationExpression(DeclarationExpression expression) { // visit right side first to avoid the usage of a // variable before its declaration expression.getRightExpression().visit(this); // no need to visit left side, just get the variable name if (expression.isMultipleAssignmentDeclaration()) { ArgumentListExpression list = (ArgumentListExpression) expression.getLeftExpression(); for (Iterator it=list.getExpressions().iterator(); it.hasNext();) { VariableExpression exp = (VariableExpression) it.next(); declare(exp); } } else { declare(expression.getVariableExpression()); } }
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()); }
ClassNode cNode = de.getDeclaringClass(); if (!cNode.isScript()) { addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent); if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent); return; VariableExpression ve = de.getVariableExpression(); variableName = ve.getName(); fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression()); fieldNode.setSourcePosition(de); cNode.addField(fieldNode); if (!de.getAnnotations(OPTION_TYPE).isEmpty()) { addError("Can't have a final field also annotated with @" + OPTION_TYPE.getNameWithoutPackage(), de); final List<AnnotationNode> annotations = de.getAnnotations(); for (AnnotationNode annotation : annotations) {
@Override public VariableExpression captureOldValue(Expression oldValue) { VariableExpression var = new OldValueExpression(oldValue, SpockNames.OLD_VALUE + oldValueCount++); DeclarationExpression decl = new DeclarationExpression( var, Token.newSymbol(Types.ASSIGN, -1, -1), oldValue); decl.setSourcePosition(oldValue); // add declaration at end of block immediately preceding when-block // avoids any problems if when-block gets wrapped in try-statement block.getPrevious().getPrevious().getAst().add(new ExpressionStatement(decl)); return var; }
assertNodeType(VARIABLE_DEF, varDef); DeclarationExpression de = (DeclarationExpression) declarationExpression(varDef); alist.addExpression(de.getVariableExpression()); DeclarationExpression expression = new DeclarationExpression(leftExpression, token, rightExpression); expression.addAnnotations(annotations); configureAST(expression, variableDef); ExpressionStatement expressionStatement = new ExpressionStatement(expression); configureAST(expressionStatement, variableDef); return expression;
public void visitDeclarationExpression(DeclarationExpression expression) { visitAnnotations(expression); // visit right side first to avoid the usage of a // variable before its declaration expression.getRightExpression().visit(this); if (expression.isMultipleAssignmentDeclaration()) { TupleExpression list = expression.getTupleExpression(); for (Expression e : list.getExpressions()) { declare((VariableExpression) e); } } else { declare(expression.getVariableExpression()); } }
ConstructorCallExpression cce = new ConstructorCallExpression(ARRAYLIST_CLASSNODE, ArgumentListExpression.EMPTY_ARGUMENTS); cce.setNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, ARRAYLIST_CONSTRUCTOR); DeclarationExpression declr = new DeclarationExpression( result, Token.newSymbol("=", spreadExpression.getLineNumber(), spreadExpression.getColumnNumber()), cce ); declr.visit(controller.getAcg()); iterator, receiver, new ExpressionStatement(add) ); stmt.visit(controller.getAcg());