public static BlockStatement block(Statement... stmts) { BlockStatement block = new BlockStatement(); for (Statement stmt : stmts) block.addStatement(stmt); return block; }
public static BlockStatement block(VariableScope varScope, List<Statement> stmts) { BlockStatement block = new BlockStatement(); block.setVariableScope(varScope); for (Statement stmt : stmts) block.addStatement(stmt); return block; }
private BlockStatement getBlockStatement(MethodNode targetMethod, Statement code) { BlockStatement toBlock; if (code instanceof BlockStatement) { toBlock = (BlockStatement) code; } else { toBlock = new BlockStatement(); toBlock.addStatement(code); targetMethod.setCode(toBlock); } return toBlock; }
public static BlockStatement block(VariableScope varScope, Statement... stmts) { BlockStatement block = new BlockStatement(); block.setVariableScope(varScope); for (Statement stmt : stmts) block.addStatement(stmt); return block; }
private TryCatchStatement createCleanupTryCatch(CleanupBlock block, VariableExpression featureThrowableVar) { List<Statement> cleanupStats = new ArrayList<>(block.getAst()); TryCatchStatement tryCatchStat = new TryCatchStatement( new BlockStatement(cleanupStats, new VariableScope()), EmptyStatement.INSTANCE); tryCatchStat.addCatch(createHandleSuppressedThrowableStatement(featureThrowableVar)); return tryCatchStat; }
private static Statement toStringPropertyName(Expression result, String fName) { final BlockStatement body = new BlockStatement(); body.addStatement(appendS(result, constX(fName + ":"))); return body; }
private TryCatchStatement tryCatchAssertionFailedError(AnnotationNode annotationNode, MethodNode methodNode, ArrayList<Statement> statements) { TryCatchStatement tryCatchStatement = new TryCatchStatement(new BlockStatement(statements, methodNode.getVariableScope()), EmptyStatement.INSTANCE); tryCatchStatement.addCatch(new CatchStatement(new Parameter(CATCHED_THROWABLE_TYPE, "ex"), ReturnStatement.RETURN_NULL_OR_VOID)); return tryCatchStatement; }
private BlockStatement siblingsToBlockStatement(AST firstSiblingNode) { BlockStatement block = new BlockStatement(); for (AST node = firstSiblingNode; node != null; node = node.getNextSibling()) { block.addStatement(statement(node)); } return block; }
protected void addConstructor(Parameter[] newParams, ConstructorNode ctor, Statement code, ClassNode node) { if (code instanceof ExpressionStatement) {//GROOVY-4508 Statement temp = code; code = new BlockStatement(); ((BlockStatement) code).addStatement(temp); } ConstructorNode ctrNode = new ConstructorNode(ctor.getModifiers(), newParams, ctor.getExceptions(), code); ctrNode.setDeclaringClass(node); constructors.add(ctrNode); }
private FixtureMethod getSharedInitializerMethod() { if (spec.getSharedInitializerMethod() == null) { // method is private s.t. multiple initializer methods along hierarchy can be called independently MethodNode gMethod = new MethodNode(InternalIdentifiers.SHARED_INITIALIZER_METHOD, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement()); spec.getAst().addMethod(gMethod); FixtureMethod method = new FixtureMethod(spec, gMethod); method.addBlock(new AnonymousBlock(method)); spec.setSharedInitializerMethod(method); } return spec.getSharedInitializerMethod(); }
private FixtureMethod getInitializerMethod() { if (spec.getInitializerMethod() == null) { // method is private s.t. multiple initializer methods along hierarchy can be called independently MethodNode gMethod = new MethodNode(InternalIdentifiers.INITIALIZER_METHOD, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement()); spec.getAst().addMethod(gMethod); FixtureMethod method = new FixtureMethod(spec, gMethod); method.addBlock(new AnonymousBlock(method)); spec.setInitializerMethod(method); } return spec.getInitializerMethod(); }
private static MethodNode createBuilderMethod(AnnotationNode anno, ClassNode builder) { String builderMethodName = getMemberStringValue(anno, "builderMethodName", "builder"); final BlockStatement body = new BlockStatement(); body.addStatement(returnS(ctorX(builder))); return new MethodNode(builderMethodName, PUBLIC_STATIC, builder, NO_PARAMS, NO_EXCEPTIONS, body); }
private static MethodNode createBuildMethod(BuilderASTTransformation transform, AnnotationNode anno, ClassNode sourceClass, List<PropertyInfo> fields) { String buildMethodName = transform.getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); Expression sourceClassInstance = initializeInstance(sourceClass, fields, body); body.addStatement(returnS(sourceClassInstance)); return new MethodNode(buildMethodName, ACC_PUBLIC, sourceClass, NO_PARAMS, NO_EXCEPTIONS, body); }
private static MethodNode createBuildMethod(AnnotationNode anno, ClassNode buildee, List<PropertyInfo> props) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); body.addStatement(returnS(initializeInstance(buildee, props, body))); return new MethodNode(buildMethodName, ACC_PUBLIC, newClass(buildee), NO_PARAMS, NO_EXCEPTIONS, body); }
private static void create(FieldNode fieldNode, final Expression initExpr) { final BlockStatement body = new BlockStatement(); if (fieldNode.isStatic()) { addHolderClassIdiomBody(body, fieldNode, initExpr); } else if (fieldNode.isVolatile()) { addDoubleCheckedLockingBody(body, fieldNode, initExpr); } else { addNonThreadSafeBody(body, fieldNode, initExpr); } addMethod(fieldNode, body, fieldNode.getType()); }
private static void createBuilderConstructors(ClassNode builder, ClassNode buildee, List<FieldNode> fields) { builder.addConstructor(ACC_PRIVATE, NO_PARAMS, NO_EXCEPTIONS, block(ctorSuperS())); final BlockStatement body = new BlockStatement(); body.addStatement(ctorSuperS()); initializeFields(fields, body, false); builder.addConstructor(ACC_PRIVATE, getParams(fields, buildee), NO_EXCEPTIONS, body); }
private CatchStatement createThrowableAssignmentAndRethrowCatchStatement(VariableExpression assignmentVar) { Parameter catchParameter = new Parameter(nodeCache.Throwable, "$spock_tmp_throwable"); BinaryExpression assignThrowableExpr = new BinaryExpression( new VariableExpression(assignmentVar), Token.newSymbol(Types.ASSIGN, -1, -1), new VariableExpression(catchParameter)); return new CatchStatement(catchParameter, new BlockStatement( Arrays.asList( new ExpressionStatement(assignThrowableExpr), new ThrowStatement(new VariableExpression(catchParameter))), new VariableScope())); }
private static void createWriteExternal(ClassNode cNode, List<String> excludes, List<FieldNode> list) { final BlockStatement body = new BlockStatement(); Parameter out = param(OBJECTOUTPUT_TYPE, "out"); for (FieldNode fNode : list) { if (excludes != null && excludes.contains(fNode.getName())) continue; if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue; MethodCallExpression writeObject = callX(varX(out), "write" + suffixForField(fNode), varX(fNode)); writeObject.setImplicitThis(false); body.addStatement(stmt(writeObject)); } ClassNode[] exceptions = {make(IOException.class)}; addGeneratedMethod(cNode, "writeExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(out), exceptions, body); }
private static void addGetter(FieldNode fNode, ClassNode componentType) { ClassNode cNode = fNode.getDeclaringClass(); BlockStatement body = new BlockStatement(); Parameter[] params = new Parameter[1]; params[0] = new Parameter(ClassHelper.int_TYPE, "index"); body.addStatement(stmt(indexX(varX(fNode), varX(params[0])))); addGeneratedMethod(cNode, makeName(fNode, "get"), getModifiers(fNode), componentType, params, null, body); }
private static MethodNode createBuildMethodForMethod(AnnotationNode anno, ClassNode buildee, MethodNode mNode, Parameter[] params) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); ClassNode returnType; if (mNode instanceof ConstructorNode) { returnType = newClass(buildee); body.addStatement(returnS(ctorX(newClass(mNode.getDeclaringClass()), args(params)))); } else { body.addStatement(returnS(callX(newClass(mNode.getDeclaringClass()), mNode.getName(), args(params)))); returnType = newClass(mNode.getReturnType()); } return new MethodNode(buildMethodName, ACC_PUBLIC, returnType, NO_PARAMS, NO_EXCEPTIONS, body); }