本文整理汇总了Java中org.codehaus.groovy.ast.stmt.BlockStatement类的典型用法代码示例。如果您正苦于以下问题:Java BlockStatement类的具体用法?Java BlockStatement怎么用?Java BlockStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockStatement类属于org.codehaus.groovy.ast.stmt包,在下文中一共展示了BlockStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
@Override
public void call(SourceUnit source) throws CompilationFailedException {
BlockStatement statementBlock = source.getAST().getStatementBlock();
List<Statement> statements = statementBlock.getStatements();
for (Statement statement : statements) {
if (!AstUtils.mayHaveAnEffect(statement)) {
continue;
}
ScriptBlock scriptBlock = AstUtils.detectScriptBlock(statement);
if (scriptBlock != null && scriptBlock.getName().equals(ModelBlockTransformer.MODEL)) {
continue;
}
imperativeStatementDetected = true;
break;
}
}
示例2: visit
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
LOGGER.trace("Apply AST transformation");
ModuleNode ast = sourceUnit.getAST();
BlockStatement blockStatement = ast.getStatementBlock();
if (DEBUG) {
printAST(blockStatement);
}
List<MethodNode> methods = ast.getMethods();
for (MethodNode methodNode : methods) {
methodNode.getCode().visit(new CustomClassCodeExpressionTransformer(sourceUnit));
}
blockStatement.visit(new CustomClassCodeExpressionTransformer(sourceUnit));
if (DEBUG) {
printAST(blockStatement);
}
}
示例3: getClosure
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
/**
* Extract a top-level {@code name} closure from inside this block if there is one,
* optionally removing it from the block at the same time.
* @param block a block statement (class definition)
* @param name the name to look for
* @param remove whether or not the extracted closure should be removed
* @return a beans Closure if one can be found, null otherwise
*/
public static ClosureExpression getClosure(BlockStatement block, String name,
boolean remove) {
for (ExpressionStatement statement : getExpressionStatements(block)) {
Expression expression = statement.getExpression();
if (expression instanceof MethodCallExpression) {
ClosureExpression closure = getClosure(name,
(MethodCallExpression) expression);
if (closure != null) {
if (remove) {
block.getStatements().remove(statement);
}
return closure;
}
}
}
return null;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:AstUtils.java
示例4: visitBlockStatement
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
@Override
public void visitBlockStatement(BlockStatement block) {
if (block.isEmpty() || this.xformed) {
return;
}
ClosureExpression closure = beans(block);
if (closure != null) {
// Add a marker interface to the current script
this.classNode.addInterface(ClassHelper.make(SOURCE_INTERFACE));
// Implement the interface by adding a public read-only property with the
// same name as the method in the interface (getBeans). Make it return the
// closure.
this.classNode.addProperty(
new PropertyNode(BEANS, Modifier.PUBLIC | Modifier.FINAL,
ClassHelper.CLOSURE_TYPE.getPlainNodeReference(),
this.classNode, closure, null, null));
// Only do this once per class
this.xformed = true;
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:GroovyBeansTransformation.java
示例5: transformationOfAnnotationOnLocalVariable
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnLocalVariable() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
DeclarationExpression declarationExpression = new DeclarationExpression(
new VariableExpression("test"), null, new ConstantExpression("test"));
declarationExpression.addAnnotation(this.grabAnnotation);
BlockStatement code = new BlockStatement(
Arrays.asList((Statement) new ExpressionStatement(declarationExpression)),
new VariableScope());
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[0], new ClassNode[0], code);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ResolveDependencyCoordinatesTransformationTests.java
示例6: 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))
)
)
));
}
示例7: visitClosureExpression
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
@Override
public void visitClosureExpression(final ClosureExpression expression) {
super.visitClosureExpression(expression);
if (inBuilderMethod) {
Statement oldCode = expression.getCode();
BlockStatement block = oldCode instanceof BlockStatement?
((BlockStatement)oldCode):
new BlockStatement(Arrays.asList(oldCode), new VariableScope());
List<Statement> statements = block.getStatements();
if (!statements.isEmpty()) {
Statement first = statements.get(0);
Statement last = statements.get(statements.size()-1);
if (expression.getLineNumber()<first.getLineNumber()) {
// there's a new line between { -> ... and the first statement
statements.add(0,createNewLine(expression));
}
if (expression.getLastLineNumber()>last.getLastLineNumber()) {
// there's a new line between { -> ... and the first statement
statements.add(createNewLine(expression));
}
}
expression.setCode(block);
}
}
示例8: checkThisAndSuperConstructorCall
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
private ConstructorCallExpression checkThisAndSuperConstructorCall(Statement statement) {
if (!(statement instanceof BlockStatement)) { // method code must be a BlockStatement
return null;
}
BlockStatement blockStatement = (BlockStatement) statement;
List<Statement> statementList = blockStatement.getStatements();
for (int i = 0, n = statementList.size(); i < n; i++) {
Statement s = statementList.get(i);
if (s instanceof ExpressionStatement) {
Expression expression = ((ExpressionStatement) s).getExpression();
if ((expression instanceof ConstructorCallExpression) && 0 != i) {
return (ConstructorCallExpression) expression;
}
}
}
return null;
}
示例9: 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);
}
示例10: visitClosureExpression
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
@Override
public void visitClosureExpression(ClosureExpression expression) {
if (inputs == null) {
inputs = ImmutableListMultimap.builder();
try {
accessVariable = new VariableExpression(ACCESS_HOLDER_FIELD, ACCESS_API_TYPE);
super.visitClosureExpression(expression);
BlockStatement code = (BlockStatement) expression.getCode();
code.setNodeMetaData(AST_NODE_METADATA_INPUTS_KEY, inputs.build());
accessVariable.setClosureSharedVariable(true);
StaticMethodCallExpression getAccessCall = new StaticMethodCallExpression(CONTEXTUAL_INPUT_TYPE, GET_ACCESS, ArgumentListExpression.EMPTY_ARGUMENTS);
DeclarationExpression variableDeclaration = new DeclarationExpression(accessVariable, new Token(Types.ASSIGN, "=", -1, -1), getAccessCall);
code.getStatements().add(0, new ExpressionStatement(variableDeclaration));
code.getVariableScope().putDeclaredVariable(accessVariable);
} finally {
inputs = null;
}
} else {
expression.getVariableScope().putReferencedLocalVariable(accessVariable);
super.visitClosureExpression(expression);
}
}
示例11: addHolderClassIdiomBody
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
private static void addHolderClassIdiomBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
final ClassNode declaringClass = fieldNode.getDeclaringClass();
final ClassNode fieldType = fieldNode.getType();
final int visibility = ACC_PRIVATE | ACC_STATIC;
final String fullName = declaringClass.getName() + "$" + fieldType.getNameWithoutPackage() + "Holder_" + fieldNode.getName().substring(1);
final InnerClassNode holderClass = new InnerClassNode(declaringClass, fullName, visibility, ClassHelper.OBJECT_TYPE);
final String innerFieldName = "INSTANCE";
// we have two options:
// (1) embed initExpr within holder class but redirect field access/method calls to declaring class members
// (2) keep initExpr within a declaring class method that is only called by the holder class
// currently we have gone with (2) for simplicity with only a slight memory footprint increase in the declaring class
final String initializeMethodName = (fullName + "_initExpr").replace('.', '_');
declaringClass.addMethod(initializeMethodName, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, fieldType,
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, returnS(initExpr));
holderClass.addField(innerFieldName, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, fieldType,
callX(declaringClass, initializeMethodName));
final Expression innerField = propX(classX(holderClass), innerFieldName);
declaringClass.getModule().addClass(holderClass);
body.addStatement(returnS(innerField));
}
示例12: 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))
)
)
));
}
示例13: createToString
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
public static void createToString(ClassNode cNode, boolean includeSuper, boolean includeFields, List<String> excludes, List<String> includes, boolean includeNames, boolean ignoreNulls, boolean includePackage, boolean cache, boolean includeSuperProperties, boolean allProperties, boolean allNames) {
// make a public method if none exists otherwise try a private method with leading underscore
boolean hasExistingToString = hasDeclaredMethod(cNode, "toString", 0);
if (hasExistingToString && hasDeclaredMethod(cNode, "_toString", 0)) return;
final BlockStatement body = new BlockStatement();
Expression tempToString;
if (cache) {
final FieldNode cacheField = cNode.addField("$to$string", ACC_PRIVATE | ACC_SYNTHETIC, ClassHelper.STRING_TYPE, null);
final Expression savedToString = varX(cacheField);
body.addStatement(ifS(
equalsNullX(savedToString),
assignS(savedToString, calculateToStringStatements(cNode, includeSuper, includeFields, excludes, includes, includeNames, ignoreNulls, includePackage, includeSuperProperties, allProperties, body, allNames))
));
tempToString = savedToString;
} else {
tempToString = calculateToStringStatements(cNode, includeSuper, includeFields, excludes, includes, includeNames, ignoreNulls, includePackage, includeSuperProperties, allProperties, body, allNames);
}
body.addStatement(returnS(tempToString));
cNode.addMethod(new MethodNode(hasExistingToString ? "_toString" : "toString", hasExistingToString ? ACC_PRIVATE : ACC_PUBLIC,
ClassHelper.STRING_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body));
}
示例14: createInitMethod
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
private static MethodNode createInitMethod(final boolean isStatic, final ClassNode cNode, final ClassNode helper) {
MethodNode initializer = new MethodNode(
isStatic?Traits.STATIC_INIT_METHOD:Traits.INIT_METHOD,
ACC_STATIC | ACC_PUBLIC | ACC_SYNTHETIC,
ClassHelper.VOID_TYPE,
new Parameter[]{createSelfParameter(cNode, isStatic)},
ClassNode.EMPTY_ARRAY,
new BlockStatement()
);
helper.addMethod(initializer);
// Cannot add static compilation of init method because of GROOVY-7217, see example 2 of test case
//AnnotationNode an = new AnnotationNode(TraitComposer.COMPILESTATIC_CLASSNODE);
//initializer.addAnnotation(an);
//cNode.addTransform(StaticCompileTransformation.class, an);
return initializer;
}
示例15: createCanEqual
import org.codehaus.groovy.ast.stmt.BlockStatement; //导入依赖的package包/类
private static void createCanEqual(ClassNode cNode) {
boolean hasExistingCanEqual = hasDeclaredMethod(cNode, "canEqual", 1);
if (hasExistingCanEqual && hasDeclaredMethod(cNode, "_canEqual", 1)) return;
final BlockStatement body = new BlockStatement();
VariableExpression other = varX("other");
body.addStatement(returnS(isInstanceOfX(other, GenericsUtils.nonGeneric(cNode))));
cNode.addMethod(new MethodNode(
hasExistingCanEqual ? "_canEqual" : "canEqual",
hasExistingCanEqual ? ACC_PRIVATE : ACC_PUBLIC,
ClassHelper.boolean_TYPE,
params(param(OBJECT_TYPE, other.getName())),
ClassNode.EMPTY_ARRAY,
body));
}