public static Statement declS(Expression target, Expression init) { return new ExpressionStatement(new DeclarationExpression(target, ASSIGN, init)); }
private Statement createVariableDeclarationStatement(VariableExpression var) { DeclarationExpression throwableDecl = new DeclarationExpression( var, Token.newSymbol(Types.ASSIGN, -1, -1), EmptyExpression.INSTANCE); return new ExpressionStatement(throwableDecl); }
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); }
private void rewriteSimpleParameterization(BinaryExpression binExpr, ASTNode sourcePos) throws InvalidSpecCompileException { int nextDataVariableIndex = dataProcessorVars.size(); Parameter dataProcessorParameter = createDataProcessorParameter(); VariableExpression arg = (VariableExpression) binExpr.getLeftExpression(); VariableExpression dataVar = createDataProcessorVariable(arg, sourcePos); ExpressionStatement exprStat = new ExpressionStatement( new DeclarationExpression( dataVar, Token.newSymbol(Types.ASSIGN, -1, -1), new VariableExpression(dataProcessorParameter))); exprStat.setSourcePosition(sourcePos); dataProcessorStats.add(exprStat); createDataProviderMethod(binExpr.getRightExpression(), nextDataVariableIndex); }
@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; }
private void rewriteMultiParameterization(BinaryExpression binExpr, Statement enclosingStat) throws InvalidSpecCompileException { int nextDataVariableIndex = dataProcessorVars.size(); Parameter dataProcessorParameter = createDataProcessorParameter(); ListExpression list = (ListExpression) binExpr.getLeftExpression(); @SuppressWarnings("unchecked") List<Expression> listElems = list.getExpressions(); for (int i = 0; i < listElems.size(); i++) { Expression listElem = listElems.get(i); if (AstUtil.isWildcardRef(listElem)) continue; VariableExpression dataVar = createDataProcessorVariable(listElem, enclosingStat); ExpressionStatement exprStat = new ExpressionStatement( new DeclarationExpression( dataVar, Token.newSymbol(Types.ASSIGN, -1, -1), createGetAtMethod(new VariableExpression(dataProcessorParameter), i))); exprStat.setSourcePosition(enclosingStat); dataProcessorStats.add(exprStat); } createDataProviderMethod(binExpr.getRightExpression(), nextDataVariableIndex); }
private ClassNode infer(ClassNode target, ClassNode source) { DeclarationExpression virtualDecl = new DeclarationExpression( varX("{target}", target), Token.newSymbol(EQUAL, -1, -1), varX("{source}", source) ); virtualDecl.visit(this); ClassNode newlyInferred = (ClassNode) virtualDecl.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); return !missesGenericsTypes(newlyInferred) ? newlyInferred : null; }
new DeclarationExpression( new VariableExpression(SpockNames.VALUE_RECORDER, nodeCache.ValueRecorder), Token.newSymbol(Types.ASSIGN, -1, -1), stats.add(0, new ExpressionStatement( new DeclarationExpression( new VariableExpression(SpockNames.ERROR_COLLECTOR, nodeCache.ErrorCollector), Token.newSymbol(Types.ASSIGN, -1, -1),
private static DeclarationExpression optimizeConstantInitialization( final BinaryExpression originalDeclaration, final Token operation, final ConstantExpression constant, final Expression leftExpression, final ClassNode declarationType) { ConstantExpression cexp = new ConstantExpression( convertConstant((Number) constant.getValue(), ClassHelper.getWrapper(declarationType)), true); cexp.setType(declarationType); cexp.setSourcePosition(constant); DeclarationExpression result = new DeclarationExpression( leftExpression, operation, cexp ); result.setSourcePosition(originalDeclaration); result.copyNodeMetaData(originalDeclaration); return result; }
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; }
protected void assertIterate(String methodName, Expression listExpression) throws Exception { ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE); classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null)); classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC, ClassHelper.STRING_TYPE, classNode, null, null, null)); Statement loopStatement = createPrintlnStatement(new VariableExpression("i")); BlockStatement block = new BlockStatement(); block.addStatement(new ExpressionStatement(new DeclarationExpression(new VariableExpression("list"), Token.newSymbol("=", 0, 0), listExpression))); block.addStatement(new ForStatement(new Parameter(ClassHelper.DYNAMIC_TYPE, "i"), new VariableExpression("list"), loopStatement)); classNode.addMethod(new MethodNode(methodName, ACC_PUBLIC, ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, block)); Class fooClass = loadClass(classNode); assertTrue("Loaded a new class", fooClass != null); Object bean = fooClass.newInstance(); assertTrue("Managed to create bean", bean != null); System.out.println("################ Now about to invoke method"); try { InvokerHelper.invokeMethod(bean, methodName, null); } catch (InvokerInvocationException e) { System.out.println("Caught: " + e.getCause()); e.getCause().printStackTrace(); fail("Should not have thrown an exception"); } System.out.println("################ Done"); }
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 (rightIt.hasNext()) { Expression right = rightIt.next(); BinaryExpression bexp = new DeclarationExpression(left, bin.getOperation(), right); bexp.setSourcePosition(right); cle.addExpression(bexp); Expression right = rightIt.next(); VariableExpression tmpVar = new VariableExpression("$tmpVar$" + tmpVarCounter++); BinaryExpression bexp = new DeclarationExpression(tmpVar, bin.getOperation(), right); bexp.setSourcePosition(right); tmpAssignments.add(bexp);
Expression rightTransform = transform(rightExpression); Expression ret = exp instanceof DeclarationExpression ? new DeclarationExpression( leftTransform, operation, rightTransform ) :
block.addStatement( new ExpressionStatement( new DeclarationExpression( new VariableExpression("user"), Token.newSymbol("=", -1, -1), block.addStatement( new ExpressionStatement( new DeclarationExpression(new VariableExpression("str"), Token.newSymbol("=", -1, -1), compositeStringExpr))); block.addStatement( new ExpressionStatement( new DeclarationExpression( new VariableExpression("text"), Token.newSymbol("=", -1, -1),
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()),
DeclarationExpression expression = new DeclarationExpression(leftExpression, token, rightExpression); expression.addAnnotations(annotations); configureAST(expression, variableDef);
Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right); newDecl.addAnnotations(de.getAnnotations()); return newDecl;
new DeclarationExpression( new VariableExpression("ordinal"), assign, new DeclarationExpression( new VariableExpression("ordinal"), assign,
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }