当前位置: 首页>>代码示例>>Java>>正文


Java BlockStatement.addStatement方法代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.stmt.BlockStatement.addStatement方法的典型用法代码示例。如果您正苦于以下问题:Java BlockStatement.addStatement方法的具体用法?Java BlockStatement.addStatement怎么用?Java BlockStatement.addStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.groovy.ast.stmt.BlockStatement的用法示例。


在下文中一共展示了BlockStatement.addStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createClone

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void createClone(ClassNode cNode, List<FieldNode> fieldNodes, List<String> excludes) {
    final BlockStatement body = new BlockStatement();
    final Expression result = varX("_result", cNode);
    body.addStatement(declS(result, castX(cNode, callSuperX("clone"))));
    for (FieldNode fieldNode : fieldNodes) {
        if (excludes != null && excludes.contains(fieldNode.getName())) continue;
        ClassNode fieldType = fieldNode.getType();
        Expression fieldExpr = varX(fieldNode);
        Expression to = propX(result, fieldNode.getName());
        Statement doClone = assignS(to, castX(fieldType, callCloneDirectX(fieldExpr)));
        Statement doCloneDynamic = assignS(to, castX(fieldType, callCloneDynamicX(fieldExpr)));
        if (isCloneableType(fieldType)) {
            body.addStatement(doClone);
        } else if (possiblyCloneable(fieldType)) {
            body.addStatement(ifS(isInstanceOfX(fieldExpr, CLONEABLE_TYPE), doCloneDynamic));
        }
    }
    body.addStatement(returnS(result));
    ClassNode[] exceptions = {make(CloneNotSupportedException.class)};
    cNode.addMethod("clone", ACC_PUBLIC, GenericsUtils.nonGeneric(cNode), Parameter.EMPTY_ARRAY, exceptions, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AutoCloneASTTransformation.java

示例2: addDoubleCheckedLockingBody

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void addDoubleCheckedLockingBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
    final Expression fieldExpr = varX(fieldNode);
    final VariableExpression localVar = varX(fieldNode.getName() + "_local");
    body.addStatement(declS(localVar, fieldExpr));
    body.addStatement(ifElseS(
            notNullX(localVar),
            returnS(localVar),
            new SynchronizedStatement(
                    syncTarget(fieldNode),
                    ifElseS(
                            notNullX(fieldExpr),
                            returnS(fieldExpr),
                            returnS(assignX(fieldExpr, initExpr))
                    )
            )
    ));
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:LazyASTTransformation.java

示例3: addDoubleCheckedLockingBody

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void addDoubleCheckedLockingBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
  final Expression fieldExpr = varX(fieldNode);
  final VariableExpression localVar = varX(fieldNode.getName() + "_local");
  body.addStatement(declS(localVar, fieldExpr));
  body.addStatement(ifElseS(
    notNullX(localVar),
    returnS(localVar),
    new SynchronizedStatement(
      syncTarget(fieldNode),
      ifElseS(
        notNullX(fieldExpr),
        returnS(fieldExpr),
        returnS(assignX(fieldExpr, initExpr))
      )
    )
  ));
}
 
开发者ID:domix,项目名称:diable,代码行数:18,代码来源:DIableASTTransformation.java

示例4: initializeInstance

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static Expression initializeInstance(ClassNode sourceClass, List<PropertyInfo> props, BlockStatement body) {
    Expression instance = varX("_the" + sourceClass.getNameWithoutPackage(), sourceClass);
    body.addStatement(declS(instance, ctorX(sourceClass)));
    for (PropertyInfo prop : props) {
        body.addStatement(stmt(assignX(propX(instance, prop.getName()), varX(prop.getName().equals("class") ? "clazz" : prop.getName(), newClass(prop.getType())))));
    }
    return instance;
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:ExternalStrategy.java

示例5: createReadExternal

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void createReadExternal(ClassNode cNode, List<String> excludes, List<FieldNode> list) {
    final BlockStatement body = new BlockStatement();
    Parameter oin = param(OBJECTINPUT_TYPE, "oin");
    for (FieldNode fNode : list) {
        if (excludes != null && excludes.contains(fNode.getName())) continue;
        if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue;
        String suffix = suffixForField(fNode);
        MethodCallExpression readObject = callX(varX(oin), "read" + suffix);
        readObject.setImplicitThis(false);
        body.addStatement(assignS(varX(fNode), suffix.equals("Object") ? castX(GenericsUtils.nonGeneric(fNode.getType()), readObject) : readObject));
    }
    cNode.addMethod("readExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(oin), ClassNode.EMPTY_ARRAY, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:ExternalizeMethodsASTTransformation.java

示例6: createWriteExternal

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
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)};
    cNode.addMethod("writeExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(out), exceptions, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:ExternalizeMethodsASTTransformation.java

示例7: addSimpleCloneHelperMethod

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void addSimpleCloneHelperMethod(ClassNode cNode, List<FieldNode> fieldNodes, List<String> excludes) {
    Parameter methodParam = new Parameter(GenericsUtils.nonGeneric(cNode), "other");
    final Expression other = varX(methodParam);
    boolean hasParent = cNode.getSuperClass() != ClassHelper.OBJECT_TYPE;
    BlockStatement methodBody = new BlockStatement();
    if (hasParent) {
        methodBody.addStatement(stmt(callSuperX("cloneOrCopyMembers", args(other))));
    }
    for (FieldNode fieldNode : fieldNodes) {
        String name = fieldNode.getName();
        if (excludes != null && excludes.contains(name)) continue;
        ClassNode fieldType = fieldNode.getType();
        Expression direct = propX(varX("this"), name);
        Expression to = propX(other, name);
        Statement assignDirect = assignS(to, direct);
        Statement assignCloned = assignS(to, castX(fieldType, callCloneDirectX(direct)));
        Statement assignClonedDynamic = assignS(to, castX(fieldType, callCloneDynamicX(direct)));
        if (isCloneableType(fieldType)) {
            methodBody.addStatement(assignCloned);
        } else if (!possiblyCloneable(fieldType)) {
            methodBody.addStatement(assignDirect);
        } else {
            methodBody.addStatement(ifElseS(isInstanceOfX(direct, CLONEABLE_TYPE), assignClonedDynamic, assignDirect));
        }
    }
    ClassNode[] exceptions = {make(CloneNotSupportedException.class)};
    cNode.addMethod("cloneOrCopyMembers", ACC_PROTECTED, ClassHelper.VOID_TYPE, params(methodParam), exceptions, methodBody);
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:AutoCloneASTTransformation.java

示例8: createBuildeeConstructors

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void createBuildeeConstructors(BuilderASTTransformation transform, ClassNode buildee, ClassNode builder, List<FieldNode> fields, boolean needsConstructor, boolean useSetters) {
    ConstructorNode initializer = createInitializerConstructor(buildee, builder, fields);
    if (transform.hasAnnotation(buildee, ImmutableASTTransformation.MY_TYPE)) {
        initializer.putNodeMetaData(ImmutableASTTransformation.IMMUTABLE_SAFE_FLAG, Boolean.TRUE);
    } else if (needsConstructor) {
        final BlockStatement body = new BlockStatement();
        body.addStatement(ctorSuperS());
        initializeFields(fields, body, useSetters);
        buildee.addConstructor(ACC_PRIVATE | ACC_SYNTHETIC, getParams(fields, buildee), NO_EXCEPTIONS, body);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:InitializerStrategy.java

示例9: createConstructorOrdered

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void createConstructorOrdered(ClassNode cNode, List<PropertyNode> list) {
    final MapExpression argMap = new MapExpression();
    final Parameter[] orderedParams = new Parameter[list.size()];
    int index = 0;
    for (PropertyNode pNode : list) {
        Parameter param = new Parameter(pNode.getField().getType(), pNode.getField().getName());
        orderedParams[index++] = param;
        argMap.addMapEntryExpression(constX(pNode.getName()), varX(pNode.getName()));
    }
    final BlockStatement orderedBody = new BlockStatement();
    orderedBody.addStatement(stmt(ctorX(ClassNode.THIS, args(castX(HASHMAP_TYPE, argMap)))));
    doAddConstructor(cNode, new ConstructorNode(ACC_PUBLIC, orderedParams, ClassNode.EMPTY_ARRAY, orderedBody));
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:ImmutableASTTransformation.java

示例10: createSoftSetter

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void createSoftSetter(FieldNode fieldNode, ClassNode type) {
    final BlockStatement body = new BlockStatement();
    final Expression fieldExpr = varX(fieldNode);
    final String name = "set" + MetaClassHelper.capitalize(fieldNode.getName().substring(1));
    final Parameter parameter = param(type, "value");
    final Expression paramExpr = varX(parameter);
    body.addStatement(ifElseS(
            notNullX(paramExpr),
            assignS(fieldExpr, ctorX(SOFT_REF, paramExpr)),
            assignS(fieldExpr, NULL_EXPR)
    ));
    int visibility = ACC_PUBLIC;
    if (fieldNode.isStatic()) visibility |= ACC_STATIC;
    fieldNode.getDeclaringClass().addMethod(name, visibility, ClassHelper.VOID_TYPE, params(parameter), ClassNode.EMPTY_ARRAY, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:LazyASTTransformation.java

示例11: testManyParam

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
public void testManyParam() throws Exception {
    ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
    classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));

    Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE, "coll1"), new Parameter(ClassHelper.OBJECT_TYPE, "coll2"), new Parameter(ClassHelper.OBJECT_TYPE, "coll3")};

    BlockStatement statement = new BlockStatement();
    statement.addStatement(createPrintlnStatement(new VariableExpression("coll1")));
    statement.addStatement(createPrintlnStatement(new VariableExpression("coll2")));
    statement.addStatement(createPrintlnStatement(new VariableExpression("coll3")));

    classNode.addMethod(new MethodNode("manyParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));

    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 a method with many parameters");
    Object[] array = {new Integer(1000 * 1000), "foo-", "bar~"};

    try {
        InvokerHelper.invokeMethod(bean, "manyParamDemo", array);
    } catch (InvokerInvocationException e) {
        System.out.println("Caught: " + e.getCause());
        e.getCause().printStackTrace();
        fail("Should not have thrown an exception");
    }
    System.out.println("################ Done");
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:ForTest.java

示例12: methodBody

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private BlockStatement methodBody(ClassNode exception, String message, ClosureExpression code, ClassNode returnType) {
    BlockStatement body = new BlockStatement();
    if (code != null) {
        body.addStatement(code.getCode());
    } else if (exception != null) {
        body.addStatement(throwS(ctorX(exception, message == null ? EMPTY_ARGUMENTS : constX(message))));
    } else {
        Expression result = getDefaultValueForPrimitive(returnType);
        if (result != null) {
            body.addStatement(returnS(result));
        }
    }
    return body;
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:AutoImplementASTTransformation.java

示例13: assignField

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void assignField(boolean useSetters, Parameter map, BlockStatement body, String name) {
    ArgumentListExpression nameArg = args(constX(name));
    body.addStatement(ifS(callX(varX(map), "containsKey", nameArg), useSetters ?
            stmt(callThisX(getSetterName(name), callX(varX(map), "get", nameArg))) :
            assignS(propX(varX("this"), name), callX(varX(map), "get", nameArg))));
}
 
开发者ID:apache,项目名称:groovy,代码行数:7,代码来源:MapConstructorASTTransformation.java

示例14: updateConstructor

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
public static void updateConstructor(ConstructorNode constructorNode) {
  BlockStatement methodBody = new BlockStatement();
  methodBody.addStatement(constructorNode.getCode());
  methodBody.addStatement(assignWiredStatement());
  constructorNode.setCode(methodBody);
}
 
开发者ID:domix,项目名称:diable,代码行数:7,代码来源:DIableConstructorWiringASTTransformation.java

示例15: addNonThreadSafeBody

import org.codehaus.groovy.ast.stmt.BlockStatement; //导入方法依赖的package包/类
private static void addNonThreadSafeBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
    final Expression fieldExpr = varX(fieldNode);
    body.addStatement(ifElseS(notNullX(fieldExpr), stmt(fieldExpr), assignS(fieldExpr, initExpr)));
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:LazyASTTransformation.java


注:本文中的org.codehaus.groovy.ast.stmt.BlockStatement.addStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。