use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class AutoNewLineTransformer method createNewLine.
private Statement createNewLine(final ASTNode node) {
MethodCallExpression mce = new MethodCallExpression(new VariableExpression("this"), "newLine", ArgumentListExpression.EMPTY_ARGUMENTS);
mce.setImplicitThis(true);
mce.setSourcePosition(node);
ExpressionStatement stmt = new ExpressionStatement(mce);
stmt.setSourcePosition(node);
return stmt;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project gcontracts by andresteingress.
the class DynamicSetterInjectionVisitor method visitClass.
@Override
public void visitClass(ClassNode classNode) {
// if a class invariant is available visit all property nodes else skip this class
final MethodNode invariantMethodNode = BaseGenerator.getInvariantMethodNode(classNode);
if (invariantMethodNode == null || AnnotationUtils.hasAnnotationOfType(classNode, SPRING_STEREOTYPE_PACKAGE))
return;
invariantAssertionBlockStatement = new BlockStatement();
invariantAssertionBlockStatement.addStatement(new ExpressionStatement(new MethodCallExpression(VariableExpression.THIS_EXPRESSION, invariantMethodNode.getName(), ArgumentListExpression.EMPTY_ARGUMENTS)));
List<ConstructorNode> declaredConstructors = classNode.getDeclaredConstructors();
if (declaredConstructors == null || declaredConstructors.isEmpty()) {
// create default constructor with class invariant check
ConstructorNode constructor = new ConstructorNode(Opcodes.ACC_PUBLIC, invariantAssertionBlockStatement);
constructor.setSynthetic(true);
classNode.addConstructor(constructor);
}
super.visitClass(classNode);
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project gcontracts by andresteingress.
the class PreconditionGenerator method addPrecondition.
private void addPrecondition(MethodNode method, BlockStatement blockStatement) {
final BlockStatement modifiedMethodCode = new BlockStatement();
modifiedMethodCode.addStatements(blockStatement.getStatements());
if (method.getCode() instanceof BlockStatement) {
BlockStatement methodBlock = (BlockStatement) method.getCode();
for (Statement statement : methodBlock.getStatements()) {
if (method instanceof ConstructorNode && statement instanceof ExpressionStatement && ((ExpressionStatement) statement).getExpression() instanceof ConstructorCallExpression) {
modifiedMethodCode.getStatements().add(0, statement);
} else {
modifiedMethodCode.getStatements().add(statement);
}
}
} else {
modifiedMethodCode.addStatement(method.getCode());
}
method.setCode(modifiedMethodCode);
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project gcontracts by andresteingress.
the class ExpressionUtils method getBooleanExpressions.
/**
* Returns all {@link BooleanExpression} instances found in the given {@link BlockStatement}.
*/
private static List<BooleanExpression> getBooleanExpressions(BlockStatement closureBlockStatement) {
final List<Statement> statementList = closureBlockStatement.getStatements();
List<BooleanExpression> booleanExpressions = new ArrayList<BooleanExpression>();
for (Statement stmt : statementList) {
BooleanExpression tmp = null;
if (stmt instanceof ExpressionStatement && ((ExpressionStatement) stmt).getExpression() instanceof BooleanExpression) {
tmp = (BooleanExpression) ((ExpressionStatement) stmt).getExpression();
tmp.setNodeMetaData("statementLabel", stmt.getStatementLabel());
} else if (stmt instanceof ExpressionStatement) {
Expression expression = ((ExpressionStatement) stmt).getExpression();
tmp = new BooleanExpression(expression);
tmp.setSourcePosition(expression);
tmp.setNodeMetaData("statementLabel", stmt.getStatementLabel());
}
booleanExpressions.add(tmp);
}
return booleanExpressions;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project spock by spockframework.
the class SpecialMethodCall method isMatch.
public boolean isMatch(Statement stat) {
ExpressionStatement exprStat = ObjectUtil.asInstance(stat, ExpressionStatement.class);
if (exprStat == null)
return false;
Expression expr = exprStat.getExpression();
return expr == binaryExpr || expr == methodCallExpr;
}
Aggregations